List of usage examples for org.jdom2 Element clone
@Override
public Element clone()
This returns a deep clone of this element.
From source file:com.izforge.izpack.util.xmlmerge.action.InsertAction.java
License:Open Source License
@Override public void perform(Element originalElement, Element patchElement, Element outputParentElement) { if (patchElement == null && originalElement != null) { outputParentElement.addContent((Element) originalElement.clone()); } else {/*from ww w . j av a 2s . c o m*/ List<Content> outputContent = outputParentElement.getContent(); Iterator<Content> it = outputContent.iterator(); int lastIndex = outputContent.size(); while (it.hasNext()) { Content content = it.next(); if (content instanceof Element) { Element element = (Element) content; if (element.getQualifiedName().equals(patchElement.getQualifiedName())) { lastIndex = outputParentElement.indexOf(element); } } } List<Content> toAdd = new ArrayList<Content>(); toAdd.add(patchElement); outputContent.addAll(Math.min(lastIndex + 1, outputContent.size()), toAdd); } }
From source file:com.izforge.izpack.util.xmlmerge.action.KeepAction.java
License:Open Source License
@Override public void perform(Element originalElement, Element patchElement, Element outputParentElement) { if (originalElement != null && patchElement != null) { outputParentElement.addContent((Element) patchElement.clone()); }/*from w w w . j a v a 2s . c o m*/ }
From source file:com.izforge.izpack.util.xmlmerge.action.OrderedMergeAction.java
License:Open Source License
@Override public void perform(Element originalElement, Element patchElement, Element outputParentElement) throws AbstractXmlMergeException { logger.fine("Merging: " + originalElement + " (original) and " + patchElement + "(patch)"); Mapper mapper = (Mapper) m_mapperFactory.getOperation(originalElement, patchElement); if (originalElement == null) { outputParentElement.addContent(mapper.map(patchElement)); } else if (patchElement == null) { outputParentElement.addContent((Content) originalElement.clone()); } else {//ww w. j a v a 2 s . com Element workingElement = new Element(originalElement.getName(), originalElement.getNamespacePrefix(), originalElement.getNamespaceURI()); addAttributes(workingElement, originalElement); logger.fine("Adding " + workingElement); outputParentElement.addContent(workingElement); doIt(workingElement, originalElement, patchElement); } }
From source file:com.izforge.izpack.util.xmlmerge.action.OverrideAction.java
License:Open Source License
@Override public void perform(Element originalElement, Element patchElement, Element outputParentElement) { if (originalElement != null && patchElement != null) { outputParentElement.addContent((Element) patchElement.clone()); } else if (originalElement != null) { outputParentElement.addContent((Element) originalElement.clone()); }//w ww .j a v a 2 s. c o m }
From source file:com.izforge.izpack.util.xmlmerge.action.PreserveAction.java
License:Open Source License
@Override public void perform(Element originalElement, Element patchElement, Element outputParentElement) { if (originalElement != null) { outputParentElement.addContent((Element) originalElement.clone()); }//www .ja v a 2s.c o m }
From source file:com.izforge.izpack.util.xmlmerge.action.ReplaceAction.java
License:Open Source License
@Override public void perform(Element originalElement, Element patchElement, Element outputParentElement) { if (patchElement != null) { outputParentElement.addContent((Element) patchElement.clone()); } else {/*from w w w. ja v a 2s. c om*/ outputParentElement.addContent((Element) originalElement.clone()); } }
From source file:com.izforge.izpack.util.xmlmerge.mapper.IdentityMapper.java
License:Open Source License
@Override public Element map(Element patchElement) { if (patchElement == null) { return null; }/*from w w w . j av a 2s.c o m*/ return (Element) patchElement.clone(); }
From source file:com.izforge.izpack.util.xmlmerge.mapper.NamespaceFilterMapper.java
License:Open Source License
/** * Filters an element's attributes./*ww w. j ava2 s . co m*/ * * @param element An element whose attributes will be filtered * @return The input element whose attributes have been filtered */ private Element filterAttributes(Element element) { Element result = (Element) element.clone(); List<Attribute> attributes = result.getAttributes(); Iterator<Attribute> it = attributes.iterator(); while (it.hasNext()) { Attribute attr = it.next(); if (attr.getNamespace().equals(m_namespace)) { it.remove(); } } return result; }
From source file:com.rometools.modules.content.io.ContentModuleParser.java
License:Open Source License
@Override public com.rometools.rome.feed.module.Module parse(final Element element, final Locale locale) { boolean foundSomething = false; final ContentModule cm = new ContentModuleImpl(); final List<Element> encodeds = element.getChildren("encoded", CONTENT_NS); final ArrayList<String> contentStrings = new ArrayList<String>(); final ArrayList<String> encodedStrings = new ArrayList<String>(); if (!encodeds.isEmpty()) { foundSomething = true;/* ww w.j a v a 2 s. c o m*/ for (int i = 0; i < encodeds.size(); i++) { final Element encodedElement = encodeds.get(i); encodedStrings.add(encodedElement.getText()); contentStrings.add(encodedElement.getText()); } } final ArrayList<ContentItem> contentItems = new ArrayList<ContentItem>(); final List<Element> items = element.getChildren("items", CONTENT_NS); for (int i = 0; i < items.size(); i++) { foundSomething = true; final List<Element> lis = items.get(i).getChild("Bag", RDF_NS).getChildren("li", RDF_NS); for (int j = 0; j < lis.size(); j++) { final ContentItem ci = new ContentItem(); final Element li = lis.get(j); final Element item = li.getChild("item", CONTENT_NS); final Element format = item.getChild("format", CONTENT_NS); final Element encoding = item.getChild("encoding", CONTENT_NS); final Element value = item.getChild("value", RDF_NS); if (value != null) { if (value.getAttributeValue("parseType", RDF_NS) != null) { ci.setContentValueParseType(value.getAttributeValue("parseType", RDF_NS)); } if (ci.getContentValueParseType() != null && ci.getContentValueParseType().equals("Literal")) { ci.setContentValue(getXmlInnerText(value)); contentStrings.add(getXmlInnerText(value)); ci.setContentValueNamespaces(value.getAdditionalNamespaces()); } else { ci.setContentValue(value.getText()); contentStrings.add(value.getText()); } ci.setContentValueDOM(value.clone().getContent()); } if (format != null) { ci.setContentFormat(format.getAttribute("resource", RDF_NS).getValue()); } if (encoding != null) { ci.setContentEncoding(encoding.getAttribute("resource", RDF_NS).getValue()); } if (item != null) { final Attribute about = item.getAttribute("about", RDF_NS); if (about != null) { ci.setContentAbout(about.getValue()); } } contentItems.add(ci); } } cm.setEncodeds(encodedStrings); cm.setContentItems(contentItems); cm.setContents(contentStrings); return foundSomething ? cm : null; }
From source file:de.hbrs.oryx.yawl.converter.layout.YAWLLayoutConverter.java
License:Open Source License
/** * If the viewport inside YAWL Editor is adjusted, then YAWL stores negative values in "bounds" element. For Oryx this has to be adjusted, simply * by setting each negative value to zero! * //from w w w . ja va 2 s . c o m * @param boundsElement * original "bounds" element of YAWL Net * @return Element containing only positive dimensions */ private Element fixNetBoundsElement(final Element boundsElement) { Element clonedElement = boundsElement.clone(); clonedElement.setAttribute("x", fixBoundsAttribute(boundsElement.getAttributeValue("x"))); clonedElement.setAttribute("y", fixBoundsAttribute(boundsElement.getAttributeValue("y"))); clonedElement.setAttribute("h", fixBoundsAttribute(boundsElement.getAttributeValue("h"))); clonedElement.setAttribute("w", fixBoundsAttribute(boundsElement.getAttributeValue("w"))); return clonedElement; }