Java Code Examples for org.jdom2.Element#getAttributes()

The following examples show how to use org.jdom2.Element#getAttributes() . 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: IOProcessorImpl.java    From n2o-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Считать атрибуты другой схемы
 *
 * @param element   элемент
 * @param namespace схема, атрибуты которой нужно считать
 * @param map       мапа, в которую считать атрибуты схемы
 */
@Override
public void otherAttributes(Element element, Namespace namespace, Map<String, String> map) {
    if (r) {
        for (Object o : element.getAttributes()) {
            Attribute attribute = (Attribute) o;
            if (attribute.getNamespace().equals(namespace)) {
                map.put(attribute.getName(), attribute.getValue());
            }
        }
    } else {
        for (Map.Entry<String, String> entry : map.entrySet()) {
            element.setAttribute(new Attribute(entry.getKey(), entry.getValue(), namespace));
        }
    }
}
 
Example 2
Source File: ClonedElement.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
public ClonedElement(Element el) {
    super(el.getName(), el.getNamespace());
    setParent(el.getParent());

    final BoundedElement bounded = (BoundedElement) el;
    setLine(bounded.getLine());
    setColumn(bounded.getColumn());
    setStartLine(bounded.getStartLine());
    setEndLine(bounded.getEndLine());
    this.indexInParent = bounded.indexInParent();

    setContent(el.cloneContent());

    for(Attribute attribute : el.getAttributes()) {
        setAttribute(attribute.clone());
    }
}
 
Example 3
Source File: XMLConfigProvider.java    From java-trader with Apache License 2.0 5 votes vote down vote up
/**
 * 返回List<Map>
 */
private List<Object> getItems(String[] configParts)
{
    LinkedList<String> parts = new LinkedList<String>( Arrays.asList(configParts));
    Element parentElem = doc.getRootElement();
    while( parentElem!=null && parts.size()>1 ){
        String part = parts.poll();
        if ( part.length()==0 ){
            continue;
        }
        parentElem = getChildElem(parentElem, part);
        if ( parentElem==null ){
            break;
        }
        continue;
    }
    if ( parentElem==null || parts.size()==0 ){
        return Collections.emptyList();
    }
    List<Object> result = new LinkedList<>();
    for(Element elem:parentElem.getChildren(parts.poll())){
        Map<String, String> map = new HashMap<>();
        map.put("text", elem.getTextTrim());
        for( Attribute attr:elem.getAttributes()){
            map.put(attr.getName(), attr.getValue());
        }
        result.add(map);
    }
    return result;
}
 
Example 4
Source File: DataSchemaBuilder.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Clones a set of attributes. Needs to be done this way to (i) break the
 * parental attachment to the attribute; and (ii) to fix any errant namespace
 * prefixes
 * @param element the element with the attributes to clone
 * @param defNS the default namespace
 * @return the List of clone attributes
 */
private List<Attribute> cloneAttributes(Element element, Namespace defNS) {
    String prefix = element.getNamespacePrefix();
    List<Attribute> cloned = new ArrayList<Attribute>();
    for (Attribute attribute : element.getAttributes()) {
        String value = getAttributeValue(attribute, prefix, defNS);
        Attribute copy = new Attribute(attribute.getName(), value);
        cloned.add(copy);
    }
    return cloned;
}
 
Example 5
Source File: JnlpLauncher.java    From weasis-pacs-connector with Eclipse Public License 2.0 5 votes vote down vote up
static void filterMarkerInAttribute(List<Element> eltList, Map<String, Object> parameterMap,
    boolean allowEmptyMarker) {

    final Pattern patternMarker = Pattern.compile("\\$\\{([^}]+)\\}"); // matching pattern is "${..}"

    for (Element elt : eltList) {
        for (Attribute attribute : elt.getAttributes()) {
            String attributeValue = attribute.getValue();

            if (attributeValue == null) {
                continue;
            }

            Matcher matcher = patternMarker.matcher(attributeValue);
            while (matcher.find()) {
                String marker = matcher.group(0); // full pattern matched "${..}"
                String markerName = matcher.group(1); // get only text between curly braces
                String parameterValue = ServletUtil.getFirstParameter(parameterMap.get(markerName));

                if (parameterValue == null && allowEmptyMarker)
                    parameterValue = "";

                if (parameterValue != null) {
                    attributeValue = attributeValue.replace(marker, parameterValue);
                    attribute.setValue(attributeValue);
                } else {
                    LOGGER.warn("Found marker \"{}\" with NO matching parameter in Element <{}> {}", marker,
                        elt.getName(), attribute);
                }
            }
        }
    }
}
 
Example 6
Source File: XMLUtils.java    From yawl with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * merges content of two elements recursively into element minor following
 * content will be copied: Text, Element, Attribute if conflicts, minor will
 * be overwrite with content of major
 * 
 * @param minor
 * @param major
 */
public static boolean mergeElements(Element minor, Element major) throws Exception
{
	// logger.debug("minor: " + Utils.element2String(minor, false));
	// logger.debug("major: " + Utils.element2String(major, false));
	boolean changed = false;
	if (minor == null)
	{
		minor = major;
		// logger.debug("set minor = " + Utils.element2String(major, false));
		changed = true;
	}
	else if (major != null)
	{
		if (!minor.getText().equals(major.getText()))
		{
			minor.setText(major.getText());
			// logger.debug("minor.setText("+major.getText()+")");
			changed = true;
		}

		for (Attribute a : (List<Attribute>) major.getAttributes())
		{
			Attribute aCopy = (Attribute) Utils.deepCopy(a);
			if (minor.getAttribute(a.getName()) == null || !minor.getAttributeValue(a.getName()).equals(a.getValue()))
			{
				minor.setAttribute(aCopy.detach());
				// logger.debug("minor.setAttribute("+Utils.toString(a)+")");
				changed = true;
			}
		}

		for (Element e : (List<Element>) major.getChildren())
		{
			Element eCopy = (Element) Utils.deepCopy(e);
			List<Element> minorChildren = minor.getChildren(e.getName());
			// logger.debug("minorChildren: " + Utils.toString(minorChildren));
			// logger.debug("e: " + Utils.toString(e));
			Element firstInList = existInList(minorChildren, e);
			if (firstInList == null)
			{
				// logger.debug("minor.addContent: " +
				// Utils.toString(eCopy.detach()));
				minor = minor.addContent(eCopy.detach());
				// logger.debug("minor.addContent("+Utils.element2String(e,
				// false)+")");
				changed = true;
			}
			else
			{
				changed = mergeElements(firstInList, eCopy) || changed;
			}
		}
	}

	return changed;
}
 
Example 7
Source File: YDecompositionParser.java    From yawl with GNU Lesser General Public License v3.0 4 votes vote down vote up
private YDecomposition createDecomposition(Element decompElem) {
    Namespace schemaInstanceNS = decompElem.getNamespace("xsi");
    String xsiType = _decompElem.getAttributeValue("type", schemaInstanceNS);
    String id = _decompElem.getAttributeValue("id");

    String elementName = _decompElem.getName();
    if ("NetFactsType".equals(xsiType) || "rootNet".equals(elementName)) {
        _decomposition = new YNet(id, _specificationParser.getSpecification());
        parseNet((YNet) _decomposition, decompElem);
    }
    else if ("WebServiceGatewayFactsType".equals(xsiType)) {
        _decomposition = new YAWLServiceGateway(id, _specificationParser.getSpecification());
        parseWebServiceGateway((YAWLServiceGateway) _decomposition, decompElem);
    }
    /**
     * AJH: Added to support XML attribute pass-thru from specification into task output data doclet.
     * Load element attributes
     */
    for (Attribute attr : decompElem.getAttributes()) {
        String attname = attr.getName();
        boolean isXsiNS = attr.getNamespace() == schemaInstanceNS;

        //don't add the standard YAWL schema attributes to the pass through list.
        if(!("id".equals(attname) || ("type".equals(attname) && isXsiNS))) {
            String value = attr.getValue();
            if (value.startsWith("dynamic{")) {
                _decomposition.setAttribute(attr.getName(),
                        new DynamicValue(value, _decomposition));
            }
            else _decomposition.setAttribute(attr.getName(), value);
        }
    }
    
    parseDecompositionRoles(_decomposition, decompElem);
    _decomposition.setLogPredicate(parseLogPredicate(decompElem, _yawlNS));

    // added for resourcing
    parseExternalInteraction(_decomposition, decompElem);
    parseCodelet(_decomposition, decompElem);

    return _decomposition;
}
 
Example 8
Source File: SSEParserTest.java    From rome with Apache License 2.0 4 votes vote down vote up
private boolean equalAttributes(final Element one, final Element two, final boolean doAssert) {
    final List<Attribute> attrs1 = one.getAttributes();
    final List<Attribute> attrs2 = two.getAttributes();

    boolean equal = nullEqual(attrs1, attrs2);
    if (doAssert) {
        assertTrue("not null equal", equal);
    }

    if (bothNull(attrs1, attrs2)) {
        return true;
    }

    if (equal) {
        for (final Object element : attrs1) {
            // compare the attributes in an order insensitive way
            final Attribute a1 = (Attribute) element;
            final Attribute a2 = findAttribute(a1.getName(), attrs2);

            equal = a2 != null;
            if (!equal) {
                if (doAssert) {
                    assertNotNull("no matching attribute for: " + one.getName() + "." + a1.getName() + "=" + a1.getValue(), a2);
                }
                break;
            }

            Object av1 = a1.getValue();
            Object av2 = a2.getValue();

            equal = nullEqual(av1, av2);
            if (!equal && doAssert) {
                assertNullEqual("attribute values not null equal: " + av1 + " != " + av2, av1, av2);
            }

            if (!bothNull(av1, av2)) {
                final String a1Name = a1.getName();

                // this test is brittle, but its comprehensive
                if ("until".equals(a1Name) || "since".equals(a1Name) || "when".equals(a1Name)) {
                    av1 = DateParser.parseRFC822((String) av1, Locale.US);
                    av2 = DateParser.parseRFC822((String) av2, Locale.US);
                }

                assertTrue("unequal attributes:" + one.getName() + "." + a1.getName() + ": " + av1 + " != " + av2, av1.equals(av2));
            }
        }
    }
    return equal;
}