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

The following examples show how to use org.dom4j.Element#attributeIterator() . 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: JCache.java    From boubei-tss with Apache License 2.0 6 votes vote down vote up
/**
 * 根据缓存策略文件里的配置初始化各个缓存池。
 * 如果某一个cache初始化失败,在它之后的cache将不会被初始化。
 */
private void initPools(String cacheConfigFile) {
	Document doc = XMLDocUtil.createDoc(cacheConfigFile);
	List<Element> nodes = XMLDocUtil.selectNodes(doc, STRATEGY_NODE_NAME);
	for (Element strategyNode : nodes) {
		Map<String, String> attrsMap = new HashMap<String, String>();
		CacheStrategy strategy = new CacheStrategy();
		for (Iterator<?> it = strategyNode.attributeIterator(); it.hasNext();) {
			Attribute attr = (Attribute) it.next();
			attrsMap.put(attr.getName(), attr.getValue());
		}
		for (Iterator<?> it = strategyNode.elementIterator(); it.hasNext();) {
			Element attrNode = (Element) it.next();
			attrsMap.put(attrNode.getName(), attrNode.getText());
		}

		BeanUtil.setDataToBean(strategy, attrsMap);
		
		String poolCode = strategy.code;
		configedPoolCodes.add(poolCode);
		pools.put(poolCode, strategy.getPoolInstance());
	}
}
 
Example 2
Source File: BizInfo.java    From bulbasaur with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public StateLike parse(Element elem) {
    List<Element> infoElemList = elem.selectNodes(INFO_TAG);
    for (Element infoElem : infoElemList) {
        BizInfoElement bizInfoElement = new BizInfoElement();
        for (Iterator<Attribute> it = infoElem.attributeIterator(); it.hasNext(); ) {
            Attribute attribute = it.next();
            bizInfoElement.attribute.put(attribute.getName(), attribute.getValue());
        }
        String key = bizInfoElement.attribute.get(KEY_TAG);
        require(StringUtils.hasText(key), "attribute '" + KEY_TAG + "' in node bizInfo/info is required");
        if (bizInfoList.get(key) == null) {
            bizInfoList.put(key, new ArrayList<BizInfoElement>());
        }
        bizInfoList.get(key).add(bizInfoElement);
    }
    return this;
}
 
Example 3
Source File: OutcomesProcessingParser.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
*/
  @Override
  public Object parse(final Element element) {
      // assert element.getName().equalsIgnoreCase("outcomes_processing");

      final OutcomesProcessing outcomesProcessing = new OutcomesProcessing();

      final List decvars = element.selectNodes("*/decvar");
      if (decvars.size() == 0) {
          return outcomesProcessing;
      }

      final Element decvar = (Element) decvars.get(0);
      for (final Iterator iter = decvar.attributeIterator(); iter.hasNext();) {
          final Attribute attr = (Attribute) iter.next();
          outcomesProcessing.setField(attr.getName(), attr.getValue());
      }
      return outcomesProcessing;
  }
 
Example 4
Source File: OutcomesProcessingParser.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
*/
  @Override
  public Object parse(final Element element) {
      // assert element.getName().equalsIgnoreCase("outcomes_processing");

      final OutcomesProcessing outcomesProcessing = new OutcomesProcessing();

      final List decvars = element.selectNodes("*/decvar");
      if (decvars.size() == 0) {
          return outcomesProcessing;
      }

      final Element decvar = (Element) decvars.get(0);
      for (final Iterator iter = decvar.attributeIterator(); iter.hasNext();) {
          final Attribute attr = (Attribute) iter.next();
          outcomesProcessing.setField(attr.getName(), attr.getValue());
      }
      return outcomesProcessing;
  }
 
Example 5
Source File: FileUtilitiesTest.java    From CogniCrypt with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Test method for {@link de.cognicrypt.codegenerator.taskintegrator.controllers.FileUtilities#updateThePluginXMLFileWithHelpData(java.lang.String)}.
 *
 * @throws DocumentException
 * @throws MalformedURLException
 */
@Test
public void testUpdateThePluginXMLFileWithHelpData() throws DocumentException, MalformedURLException {
	final FileUtilities fileUtilities = new FileUtilities(this.tempTaskName);
	fileUtilities.updateThePluginXMLFileWithHelpData(this.tempTaskName);

	final File pluginXMLFile = CodeGenUtils.getResourceFromWithin("src" + Constants.innerFileSeparator + ".." + Constants.innerFileSeparator + Constants.PLUGIN_XML_FILE);
	final SAXReader reader = new SAXReader();
	Document pluginXMLDocument = null;
	reader.setValidation(false);
	pluginXMLDocument = reader.read(pluginXMLFile);
	boolean isSuccessfulWrite = false;
	if (pluginXMLDocument != null) {
		final Element root = pluginXMLDocument.getRootElement();
		for (final Iterator<Element> extensionElement = root.elementIterator("extension"); extensionElement.hasNext();) {
			final Element currentExtensionElement = extensionElement.next();
			final Attribute point = currentExtensionElement.attribute("point");
			if (point != null && point.getValue().equals("org.eclipse.help.contexts")) {
				for (final Iterator<Element> helpFileContext = currentExtensionElement.elementIterator("contexts"); helpFileContext.hasNext();) {
					final Element currentHelpFileContext = helpFileContext.next();
					for (final Iterator<Attribute> it = currentHelpFileContext.attributeIterator(); it.hasNext();) {
						final Attribute file = it.next();
						if (file.getName().equals("file") && file.getValue().equals("src" + Constants.innerFileSeparator + "main" + Constants.innerFileSeparator + "resources"
								+ Constants.innerFileSeparator + "Help" + Constants.innerFileSeparator + this.tempTaskName + ".xml")) {
							isSuccessfulWrite = true;
						}
					}
				}
			}
		}

	}

	assertTrue(isSuccessfulWrite);
}
 
Example 6
Source File: XMLUtil.java    From OpenAs2App with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static Map<String, String> mapAttributes(Element element) {
    Map<String, String> attributeMap = new HashMap<String, String>();
    for (Iterator<Attribute> it = element.attributeIterator(); it.hasNext(); ) {
        Attribute attribute = it.next();
        attributeMap.put(attribute.getName(), attribute.getStringValue());
    }
    return attributeMap;
}
 
Example 7
Source File: DataRow.java    From anyline with Apache License 2.0 4 votes vote down vote up
/**
 * 解析xml
    * @param keyCase KEY_CASE
    * @param element element
 * @return return
 */
public static DataRow parseXml(KEY_CASE keyCase, Element element){
	DataRow row = new DataRow(keyCase);
	if(null == element){
		return row;
	}
	Iterator<Element> childs=element.elementIterator();
	String key = element.getName();
	String namespace = element.getNamespacePrefix();
	if(BasicUtil.isNotEmpty(namespace)){
		key = namespace + ":" + key;
	}
	if(element.isTextOnly() || !childs.hasNext()){
		row.put(key, element.getTextTrim());
	}else{
		while(childs.hasNext()){
			Element child = childs.next();
			String childKey = child.getName();
			String childNamespace = child.getNamespacePrefix();
			if(BasicUtil.isNotEmpty(childNamespace)){
				childKey = childNamespace + ":" + childKey;
			}
			if(child.isTextOnly() || !child.elementIterator().hasNext()){
				row.put(childKey, child.getTextTrim());
				continue;
			}
			DataRow childRow = parseXml(keyCase,child);
			Object childStore = row.get(childKey);
			if(null == childStore){
				row.put(childKey, childRow);
			}else{
				if(childStore instanceof DataRow){
					DataSet childSet = new DataSet();
					childSet.add((DataRow)childStore);
					childSet.add(childRow);
					row.put(childKey, childSet);
				}else if(childStore instanceof DataSet){
					((DataSet)childStore).add(childRow);
				}
			}
		}	
	}
	Iterator<Attribute> attrs = element.attributeIterator();
	while(attrs.hasNext()){
		Attribute attr = attrs.next();
		row.attr(attr.getName(), attr.getValue());
	}
	return row;
}
 
Example 8
Source File: XmlCodecListener.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void enterXmlElement(Element element, XmlNodeType nodeType,
                            Element rootElement) {
    if (element.equals(rootElement)) {
        return;
    }

    YdtContextOperationType opType = null;

    for (Iterator iter = element.attributeIterator(); iter.hasNext();) {
        Attribute attr = (Attribute) iter.next();
        if (attr.getName().equals(OPERATION)) {
            opType =
                    YdtContextOperationType.valueOf(attr.getValue()
                                                            .toUpperCase());
        }
    }

    String nameSpace = null;
    if (element.getNamespace() != null) {
        nameSpace = element.getNamespace().getURI();
    }

    /*
     * When new module has to be added, and if curnode has reference of
     * previous module, then we need to traverse back to parent(logical
     * root node).
     */
    if (ydtExtBuilder.getRootNode() == ydtExtBuilder.getCurNode()
            .getParent() && prevNodeNamespace != null &&
            !prevNodeNamespace.equals(nameSpace)) {
        ydtExtBuilder.traverseToParent();
    }

    if (nodeType == OBJECT_NODE &&
            (element.content() == null || element.content().isEmpty())) {
        if (ydtExtBuilder != null) {
            if (ydtExtBuilder.getCurNode() == ydtExtBuilder.getRootNode()) {
                ydtExtBuilder.addChild(null, nameSpace, opType);
            }
            ydtExtBuilder.addNode(element.getName(), nameSpace);
        }
    } else if (nodeType == OBJECT_NODE) {
        if (ydtExtBuilder != null) {
            if (ydtExtBuilder.getCurNode() == ydtExtBuilder.getRootNode()) {
                ydtExtBuilder.addChild(null, nameSpace, opType);
            }
            ydtExtBuilder.addChild(element.getName(), nameSpace, opType);
        }
    } else if (nodeType == TEXT_NODE) {
        if (ydtExtBuilder != null) {
            if (ydtExtBuilder.getCurNode() == ydtExtBuilder.getRootNode()) {
                ydtExtBuilder.addChild(null, nameSpace, opType);
            }
            ydtExtBuilder.addLeaf(element.getName(), nameSpace,
                                  element.getText());
        }
    }

    if (nameSpace != null) {
        prevNodeNamespace = nameSpace;
    }
}
 
Example 9
Source File: XmlText.java    From ats-framework with Apache License 2.0 3 votes vote down vote up
/**
 * @param xpath XPath , pointing to a XML element
 * @return a HashMap , containing the attributes and their values
 * @throws XMLException
 */
@PublicAtsApi
public Map<String, String> getAttributes(
                                          String xpath ) throws XMLException {

    if (StringUtils.isNullOrEmpty(xpath)) {

        throw new XMLException("Null/empty xpath is not allowed.");

    }

    Element element = findElement(xpath);

    if (element == null) {

        throw new XMLException("'" + xpath + "' is not a valid path");

    }

    HashMap<String, String> attributes = new HashMap<>(1);

    Iterator<Attribute> it = element.attributeIterator();

    while (it.hasNext()) {
        Attribute attr = it.next();
        attributes.put(attr.getName(), attr.getValue());
    }

    return attributes;

}