Java Code Examples for org.dom4j.Element#elementTextTrim()

The following examples show how to use org.dom4j.Element#elementTextTrim() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebXmlUtils.java    From Openfire with Apache License 2.0 6 votes vote down vote up
private static String getClassName( String type, Document webXml, String typeName )
{
    String className = null;
    final List<Element> elements = webXml.getRootElement().elements( type ); // all elements of 'type' (filter or servlet).
    for ( final Element element : elements )
    {
        final String name = element.elementTextTrim( type + "-name" );
        if ( typeName.equals( name ) )
        {
            className = element.elementTextTrim( type + "-class" );
            break;
        }
    }

    if (className == null || className.isEmpty() )
    {
        return null;
    }

    return className;
}
 
Example 2
Source File: DataMigrator.java    From onedev with MIT License 5 votes vote down vote up
private void migrate30(File dataDir, Stack<Integer> versions) {
	for (File file: dataDir.listFiles()) {
		if (file.getName().startsWith("Settings.xml")) {
			VersionedXmlDoc dom = VersionedXmlDoc.fromFile(file);
			for (Element element: dom.getRootElement().elements()) {
				String key = element.elementTextTrim("key"); 
				if (key.equals("JOB_EXECUTORS")) 
					element.detach();
			}
			dom.writeToFile(file, false);
		}
	}
}
 
Example 3
Source File: DataMigrator.java    From onedev with MIT License 5 votes vote down vote up
private void migrate32(File dataDir, Stack<Integer> versions) {
	for (File file: dataDir.listFiles()) {
		if (file.getName().startsWith("Settings.xml")) {
			VersionedXmlDoc dom = VersionedXmlDoc.fromFile(file);
			for (Element element: dom.getRootElement().elements()) {
				String key = element.elementTextTrim("key"); 
				if (key.equals("ISSUE"))
					element.detach();
			}
			dom.writeToFile(file, false);
		} else if (file.getName().startsWith("IssueChanges.xml")) { 
			FileUtils.deleteFile(file);
		}
	}
}
 
Example 4
Source File: MetadataFactory.java    From eclipse-cs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void parseMetadata(InputStream metadataStream, ResourceBundle metadataBundle)
        throws DocumentException, CheckstylePluginException {

  SAXReader reader = new SAXReader();
  reader.setEntityResolver(new XMLUtil.InternalDtdEntityResolver(PUBLIC2INTERNAL_DTD_MAP));
  Document document = reader.read(metadataStream);

  List<Element> groupElements = document.getRootElement()
          .elements(XMLTags.RULE_GROUP_METADATA_TAG);

  for (Element groupEl : groupElements) {

    String groupName = groupEl.attributeValue(XMLTags.NAME_TAG).trim();
    groupName = localize(groupName, metadataBundle);

    // process description
    String groupDesc = groupEl.elementTextTrim(XMLTags.DESCRIPTION_TAG);
    groupDesc = localize(groupDesc, metadataBundle);

    RuleGroupMetadata group = getRuleGroupMetadata(groupName);

    if (group == null) {

      boolean hidden = Boolean.valueOf(groupEl.attributeValue(XMLTags.HIDDEN_TAG)).booleanValue();
      int priority = 0;
      try {
        priority = Integer.parseInt(groupEl.attributeValue(XMLTags.PRIORITY_TAG));
      } catch (Exception e) {
        CheckstyleLog.log(e);
        priority = Integer.MAX_VALUE;
      }

      group = new RuleGroupMetadata(groupName, groupDesc, hidden, priority);
      sRuleGroupMetadata.put(groupName, group);
    }

    // process the modules
    processModules(groupEl, group, metadataBundle);
  }
}
 
Example 5
Source File: AppMsgXmlHandler.java    From SmartIM with Apache License 2.0 5 votes vote down vote up
/**
 * 解析appmsg,这里只解析部分关键字段,如果解析失败,返回null
 * 
 * @return {@link AppMsgInfo}
 */
public AppMsgInfo decode() {
    AppMsgInfo info = new AppMsgInfo();
    try {
        Element node = root.element("appmsg");
        info.appId = node.attributeValue("appid");
        info.title = node.elementTextTrim("title");
        info.desc = node.elementTextTrim("des");
        String showType = node.elementTextTrim("showtype");
        String type = node.elementTextTrim("type");
        info.msgType = StringUtils.getInt(type, 0);
        info.showType = StringUtils.getInt(showType, 0);
        info.url = node.elementTextTrim("url");
        if (info.url != null) {
            info.url = EncodeUtils.decodeXml(info.url);
        }
        
        node = root.element("appinfo");
        info.appName = node.elementTextTrim("appname");
        if (message != null) {
            message.AppMsgInfo = info;
        }
    } catch (Exception e) {
        return null;
    }
    return info;
}
 
Example 6
Source File: HbmBinder.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void bindAuxiliaryDatabaseObject(Element auxDbObjectNode, Mappings mappings) {
	AuxiliaryDatabaseObject auxDbObject = null;
	Element definitionNode = auxDbObjectNode.element( "definition" );
	if ( definitionNode != null ) {
		try {
			auxDbObject = ( AuxiliaryDatabaseObject ) ReflectHelper
					.classForName( definitionNode.attributeValue( "class" ) )
					.newInstance();
		}
		catch( ClassNotFoundException e ) {
			throw new MappingException(
					"could not locate custom database object class [" +
					definitionNode.attributeValue( "class" ) + "]"
				);
		}
		catch( Throwable t ) {
			throw new MappingException(
					"could not instantiate custom database object class [" +
					definitionNode.attributeValue( "class" ) + "]"
				);
		}
	}
	else {
		auxDbObject = new SimpleAuxiliaryDatabaseObject(
				auxDbObjectNode.elementTextTrim( "create" ),
				auxDbObjectNode.elementTextTrim( "drop" )
			);
	}

	Iterator dialectScopings = auxDbObjectNode.elementIterator( "dialect-scope" );
	while ( dialectScopings.hasNext() ) {
		Element dialectScoping = ( Element ) dialectScopings.next();
		auxDbObject.addDialectScope( dialectScoping.attributeValue( "name" ) );
	}

	mappings.addAuxiliaryDatabaseObject( auxDbObject );
}
 
Example 7
Source File: WebXmlUtils.java    From Openfire with Apache License 2.0 5 votes vote down vote up
private static List<String> getNames( String type, Document webXml )
{
    final List<String> result = new ArrayList<>();
    final List<Element> elements = webXml.getRootElement().elements( type ); // all elements of 'type' (filter or servlet).
    for ( final Element element : elements )
    {
        final String name = element.elementTextTrim( type + "-name" );
        if ( name != null && !name.isEmpty() )
        {
            result.add( name );
        }
    }

    return result;
}
 
Example 8
Source File: WebXmlUtils.java    From Openfire with Apache License 2.0 5 votes vote down vote up
private static Map<String, String> getInitParams( String type, Document webXml, String typeName )
{
    final Map<String, String> result = new HashMap<>();
    final List<Element> elements = webXml.getRootElement().elements( type ); // all elements of 'type' (filter or servlet).
    for ( final Element element : elements )
    {
        final String name = element.elementTextTrim( type + "-name" );
        if ( typeName.equals( name ) )
        {
            final List<Element> initParamElements = element.elements( "init-param" );
            for ( final Element initParamElement : initParamElements )
            {
                final String pName  = initParamElement.elementTextTrim( "param-name" );
                final String pValue = initParamElement.elementTextTrim( "param-value" );
                if ( pName == null || pName.isEmpty() ) {
                    Log.warn( "Unable to add init-param that has no name" );
                }
                else
                {
                    result.put( pName, pValue );
                }
            }
        }
    }

    return result;
}
 
Example 9
Source File: WebXmlUtils.java    From Openfire with Apache License 2.0 5 votes vote down vote up
private static Set<String> getUrlPatterns( String type, Document webXml, String typeName )
{
    final Set<String> result = new HashSet<>();
    final List<Element> elements = webXml.getRootElement().elements( type + "-mapping" ); // all elements of 'type'-mapping (filter-mapping or servlet-mapping).
    for ( final Element element : elements )
    {
        final String name = element.elementTextTrim( type + "-name" );
        if ( typeName.equals( name ) )
        {
            final List<Element> urlPatternElements = element.elements( "url-pattern" );
            for ( final Element urlPatternElement : urlPatternElements )
            {
                final String urlPattern = urlPatternElement.getTextTrim();
                if ( urlPattern != null )
                {
                    result.add( urlPattern );
                }
            }

            // A filter can also be mapped to a servlet (by name). In that case, all url-patterns of the corresponding servlet-mapping should be used.
            if ( "filter".equals( type ) )
            {
                final List<Element> servletNameElements = element.elements( "servlet-name" );
                for ( final Element servletNameElement : servletNameElements )
                {
                    final String servletName = servletNameElement.getTextTrim();
                    if ( servletName != null )
                    {
                        result.addAll( getUrlPatterns( "servlet", webXml, servletName ) );
                    }
                }
            }
            break;
        }
    }

    return result;
}
 
Example 10
Source File: WechatGatewayController.java    From MicroCommunity with Apache License 2.0 4 votes vote down vote up
/**
 * 微信登录接口
 *
 * @param request
 */
@RequestMapping(path = "/gateway", method = RequestMethod.POST)
public ResponseEntity<String> gateway(@RequestBody String param, HttpServletRequest request) {

    String token = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, WechatConstant.TOKEN);
    String signature = request.getParameter("signature");
    String timestamp = request.getParameter("timestamp");
    String nonce = request.getParameter("nonce");
    String openId = request.getParameter("openid");
    String java110AppId = request.getParameter("java110AppId");
    String responseStr = "";
    String wId = request.getParameter(WechatConstant.PAGE_WECHAT_APP_ID);
    logger.debug("请求参数" + request.getParameterMap().toString());
    if (!StringUtil.isEmpty(wId)) {
        wId = wId.replace(" ", "+");
        token = getToken(java110AppId, wId);
    }
    ResponseEntity<String> responseEntity = null;
    logger.debug("token = " + token + "||||" + "signature = " + signature + "|||" + "timestamp = "
            + timestamp + "|||" + "nonce = " + nonce + "|||| param = " + param + "|||| openId= " + openId);
    String sourceString = "";
    String[] ss = new String[]{token, timestamp, nonce};
    Arrays.sort(ss);
    for (String s : ss) {
        sourceString += s;
    }
    String signature1 = AuthenticationFactory.SHA1Encode(sourceString).toLowerCase();
    logger.debug("sourceString = " + sourceString + "||||" + "signature1 = " + signature1);
    try {
        if (!signature1.equals(signature)) {
            responseStr = "亲,非法访问,签名失败";
            return new ResponseEntity<String>(responseStr, HttpStatus.OK);
        }
        String postStr = param;
        if (StringUtil.isEmpty(postStr)) {
            responseStr = "未输入任何内容";
            return new ResponseEntity<String>(responseStr, HttpStatus.OK);
        }
        Document document = DocumentHelper.parseText(postStr);
        Element root = document.getRootElement();
        String fromUserName = root.elementText("FromUserName");
        String toUserName = root.elementText("ToUserName");
        String keyword = root.elementTextTrim("Content");
        String msgType = root.elementTextTrim("MsgType");
        String event = root.elementText("Event");
        String eventKey = root.elementText("EventKey");
        JSONObject paramIn = new JSONObject();
        paramIn.put("fromUserName", fromUserName);
        paramIn.put("toUserName", toUserName);
        paramIn.put("keyword", keyword);
        paramIn.put("msgType", msgType);
        paramIn.put("event", event);
        paramIn.put("eventKey", eventKey);
        IPageData pd = PageData.newInstance().builder("-1", "", "", paramIn.toJSONString(),
                "", "", "", "",
                java110AppId);
        responseEntity = wechatGatewaySMOImpl.gateway(pd);

    } catch (Exception e) {
        // TODO Auto-generated catch block
        logger.error("处理失败", e);
        responseStr = "亲,网络超时,请稍后重试";
        responseEntity = new ResponseEntity<String>(responseStr, HttpStatus.OK);
    }

    return responseEntity;
}