Java Code Examples for org.jdom2.Document#clone()
The following examples show how to use
org.jdom2.Document#clone() .
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: MCRChangeTrackerTest.java From mycore with GNU General Public License v3.0 | 6 votes |
@Test public void testCompleteUndo() throws JaxenException, JDOMException { String template = "document[titles[title][title[2]]][authors/author[first='John'][last='Doe']]"; Document doc = new Document(new MCRNodeBuilder().buildElement(template, null, null)); Document before = doc.clone(); MCRChangeTracker tracker = new MCRChangeTracker(); Element titles = (Element) (new MCRBinding("document/titles", true, new MCRBinding(doc)).getBoundNode()); Element title = new Element("title").setAttribute("type", "alternative"); titles.addContent(2, title); tracker.track(MCRAddedElement.added(title)); Attribute lang = new Attribute("lang", "de"); doc.getRootElement().setAttribute(lang); tracker.track(MCRAddedAttribute.added(lang)); Element author = (Element) (new MCRBinding("document/authors/author", true, new MCRBinding(doc)) .getBoundNode()); tracker.track(MCRRemoveElement.remove(author)); tracker.undoChanges(doc); assertTrue(MCRXMLHelper.deepEqual(before, doc)); }
Example 2
Source File: MCRXMLCleaner.java From mycore with GNU General Public License v3.0 | 5 votes |
public Document clean(Document xml) { Document clone = xml.clone(); do { mapNodesToRules(clone); } while (clean(clone.getRootElement())); return clone; }
Example 3
Source File: MCRPostProcessorXSL.java From mycore with GNU General Public License v3.0 | 5 votes |
public Document process(Document xml) throws IOException, JDOMException, SAXException { if (stylesheet == null) { return xml.clone(); } MCRContent source = new MCRJDOMContent(xml); MCRContent transformed = MCRXSL2XMLTransformer.getInstance("xsl/" + stylesheet).transform(source); MCRContent normalized = new MCRNormalizeUnicodeTransformer().transform(transformed); return normalized.asXML(); }
Example 4
Source File: MCRBatchEditorCommands.java From mycore with GNU General Public License v3.0 | 5 votes |
public static void edit(String oid, String level, Action a, String field1, String value1, String field2, String value2) throws JaxenException, MCRPersistenceException, MCRAccessException, IOException { Document xmlOld = getObjectXML(oid); Document xmlNew = xmlOld.clone(); for (Element base : getlevelElements(xmlNew, level)) { if (a == Action.ADD) { add(base, field1, value1); } else if (a == Action.REMOVE) { find(base, field1, value1).forEach(e -> e.detach()); } else if (a == Action.REPLACE) { List<Element> found = find(base, field1, value1); found.forEach(e -> e.detach()); if (!found.isEmpty()) { add(base, field2, value2); } } else if (a == Action.ADD_IF) { if (!find(base, field1, value1).isEmpty()) { add(base, field2, value2); } } else if (a == Action.REMOVE_IF) { if (!find(base, field1, value1).isEmpty()) { find(base, field2, value2).forEach(e -> e.detach()); } } } saveIfModified(xmlOld, xmlNew); }
Example 5
Source File: MCRChangeTracker.java From mycore with GNU General Public License v3.0 | 4 votes |
public static Document removeChangeTracking(Document doc) { Document clone = doc.clone(); removeChangeTracking(clone.getRootElement()); return clone; }