List of usage examples for org.jdom2 Attribute getQualifiedName
public String getQualifiedName()
Attribute
. From source file:com.c4om.utils.xmlutils.XPathUtils.java
License:Apache License
/** * Given a {@link List} of {@link Attribute}, this generates a XPath condition that describes it. * That condition is of the form: <code>./@attr1QName='value1' and /@attr2QName='value2' and ... and /@attrNQName='valueN' and count(./@*)=N</code> * @param attributes the list of attributes (as a {@link List} of {@link Attribute} objects) * @return the XPath condition//from w ww . ja v a 2s . co m */ public static String generateAttributesFilter(List<Attribute> attributes) { StringBuilder builder = new StringBuilder(); for (Attribute attribute : attributes) { builder.append("./@" + attribute.getQualifiedName() + "='" + attribute.getValue() + "' and "); } builder.append("count(./@*)=" + attributes.size()); String result = builder.toString(); return result; }
From source file:com.izforge.izpack.util.xmlmerge.action.FullMergeAction.java
License:Open Source License
/** * Adds attributes from in element to out element. * * @param out out element/*w ww .ja v a 2 s.c o m*/ * @param in in element */ private void addAttributes(Element out, Element in) { LinkedHashMap<String, Attribute> allAttributes = new LinkedHashMap<String, Attribute>(); List<Attribute> outAttributes = new ArrayList<Attribute>(out.getAttributes()); List<Attribute> inAttributes = new ArrayList<Attribute>(in.getAttributes()); for (Attribute attr : outAttributes) { attr.detach(); allAttributes.put(attr.getQualifiedName(), attr); logger.fine("adding attr from out:" + attr); } for (Attribute attr : inAttributes) { attr.detach(); allAttributes.put(attr.getQualifiedName(), attr); logger.fine("adding attr from in:" + attr); } out.setAttributes(new ArrayList<Attribute>(allAttributes.values())); }
From source file:com.izforge.izpack.util.xmlmerge.matcher.AbstractAttributeMatcher.java
License:Open Source License
@Override public boolean matches(Element originalElement, Element patchElement) { if (super.matches(originalElement, patchElement)) { List<Attribute> origAttList = originalElement.getAttributes(); List<Attribute> patchAttList = patchElement.getAttributes(); if (origAttList.size() == 0 && patchAttList.size() == 0) { return true; }/*from ww w. j a v a 2 s.c o m*/ if (origAttList.size() != patchAttList.size()) { return false; } for (Attribute origAttribute : origAttList) { if (getAttributeName() == null || (getAttributeName() != null && equalsString(origAttribute.getQualifiedName(), getAttributeName(), ignoreCaseAttributeName()))) { for (Attribute patchAttribute : patchAttList) { if (ignoreCaseAttributeName()) { if (origAttribute.getQualifiedName() .equalsIgnoreCase(patchAttribute.getQualifiedName())) { return equalsString(origAttribute.getValue(), patchAttribute.getValue(), ignoreCaseAttributeValue()); } } else { if (origAttribute.getQualifiedName().equals(patchAttribute.getQualifiedName())) { return equalsString(origAttribute.getValue(), patchAttribute.getValue(), ignoreCaseAttributeValue()); } } } } } } return false; }
From source file:io.wcm.maven.plugins.contentpackage.unpacker.ContentUnpacker.java
License:Apache License
private void applyXmlExcludes(Element element, String parentPath) { String path = parentPath + "/" + element.getName(); if (exclude(path, this.excludeNodes)) { element.detach();//w ww . j a v a 2 s .c om return; } List<Attribute> attributes = new ArrayList<>(element.getAttributes()); for (Attribute attribute : attributes) { if (exclude(attribute.getQualifiedName(), this.excludeProperties)) { attribute.detach(); } } List<Element> children = new ArrayList<>(element.getChildren()); for (Element child : children) { applyXmlExcludes(child, path); } }
From source file:io.wcm.maven.plugins.contentpackage.unpacker.OneAttributePerLineXmlProcessor.java
License:Apache License
@Override protected void printAttribute(Writer out, FormatStack fstack, Attribute attribute) throws IOException { if (!attribute.isSpecified() && fstack.isSpecifiedAttributesOnly()) { return;/* w w w .j a v a 2 s . c o m*/ } write(out, StringUtils.defaultString(fstack.getLineSeparator())); write(out, StringUtils.defaultString(fstack.getLevelIndent())); write(out, StringUtils.defaultString(fstack.getIndent())); write(out, StringUtils.defaultString(fstack.getIndent())); write(out, attribute.getQualifiedName()); write(out, "="); write(out, "\""); attributeEscapedEntitiesFilter(out, fstack, attribute.getValue()); write(out, "\""); }
From source file:org.mycore.common.xml.MCRXPathBuilder.java
License:Open Source License
/** * Builds an absolute XPath expression for the given attribute within a JDOM XML structure. * In case any ancestor element in context is not the first one, the XPath will also contain position predicates. * For all namespaces commonly used in MyCoRe, their namespace prefixes will be used. * * @param attribute a JDOM attribute//from w ww.ja va 2 s.c o m * @return absolute XPath of that attribute. In case there is a root Document, it will begin with a "/". */ public static String buildXPath(Attribute attribute) { String parentXPath = buildXPath(attribute.getParent()); if (!parentXPath.isEmpty()) parentXPath += "/"; return parentXPath + "@" + attribute.getQualifiedName(); }