List of usage examples for org.jdom2 Attribute detach
public Attribute detach()
From source file:com.c4om.autoconf.ulysses.extra.svrlinterpreter.SVRLInterpreterProcessor.java
License:Apache License
/** * This method:/* w w w. ja va 2 s. co m*/ * <ol> * <li>Takes an attribute from a source element</li> * <li>Detaches it</li> * <li>Removes its namespace</li> * <li>Attaches it to a destination element</li> * </ol> * @param sourceElement source element * @param destinationElement destination element * @param attrName the name of the attribute * @param attrNamespace the namespace of the source attribute (it will be removed at destination) */ private static void moveAndRemoveNSOfAttr(Element sourceElement, Element destinationElement, String attrName, Namespace attrNamespace) { Attribute mandatoryPathAttribute = sourceElement.getAttribute(attrName, attrNamespace); if (mandatoryPathAttribute != null) { mandatoryPathAttribute.detach(); mandatoryPathAttribute.setNamespace(Namespace.NO_NAMESPACE); destinationElement.setAttribute(mandatoryPathAttribute); } }
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//from w w w. jav 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:cz.muni.fi.mir.mathmlcanonicalization.modules.AbstractModule.java
License:Apache License
protected void replaceElement(final Element toReplace, final String replacementName) { assert toReplace != null && replacementName != null; assert !replacementName.isEmpty(); final Element parent = toReplace.getParentElement(); assert parent != null; final Element replacement = new Element(replacementName); replacement.addContent(toReplace.removeContent()); final List<Attribute> attributes = toReplace.getAttributes(); for (Attribute attribute : attributes) { replacement.setAttribute(attribute.detach()); }//from w w w. java2 s .c o m final int parentIndex = parent.indexOf(toReplace); parent.removeContent(parentIndex); parent.addContent(parentIndex, replacement); LOGGER.log(Level.FINE, "{0} replaced with {1}", new Object[] { toReplace, replacementName }); }
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();/*from w w w . j av 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:org.yawlfoundation.yawl.scheduling.util.XMLUtils.java
License:Open Source License
/** * 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// www . j a va 2 s . c om * * @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; }
From source file:unidue.ub.statistics.resolver.JOPResolver.java
/** * Queries the JOP brief xml service to get the total status of electronic availability, and adds that state * to the ElectronicData element. In case total access is given by combining multiple licenses with state '3' * (partially licensed), only the brief response contains the information that the combined license covers * the complete journal, if so. //from w w w.j a v a2s . c o m */ private void addElectronicDataTotalState(Element fullXML, String query) throws SAXException, IOException, JDOMException { Element briefData = getJOPDataFromRemoteServer(query, jopBriefURL); XPathExpression<Attribute> xPath = XPathFactory.instance().compile(xpathToElectronicDataState, Filters.attribute()); Attribute state = xPath.evaluateFirst(briefData); LOGGER.debug("electronic availability total state from brief xml response is " + state.getValue()); Element electronicData = XPathFactory.instance().compile(xpathToElectronicDataFull, Filters.element()) .evaluateFirst(fullXML); state.detach(); electronicData.setAttribute(state); }