List of usage examples for org.w3c.dom Document equals
public boolean equals(Object obj)
From source file:com.adaptris.util.XmlUtils.java
/** * Convenience method which appends a new Node to the children of a parent * * @param newNode the Node to be added//from w w w . j a v a 2 s . c o m * @param parent the parent Node * @throws Exception on error. */ public void appendNode(Node newNode, Node parent) throws Exception { Document parentDoc = parent.getOwnerDocument(); Document newDoc = newNode.getOwnerDocument(); if (!parentDoc.equals(newDoc)) { newNode = parentDoc.importNode(newNode, true); } parent.appendChild(newNode); }
From source file:com.adaptris.util.XmlUtils.java
/** * Convenience method which enables a new Node to be added to a parent at a specified position, by specifying the Node to insert * before. Here is a sample of how to use: * /*from w w w .j a va 2s .c o m*/ * <pre> * {@code * * // Example of how to insert a Node as the 3rd child of a parent * Node p = xmlUtils.getSingleNode("/mydoc/parent"); * Node c = xmlUtils.getSingleNode("/mydoc/parent/child[4]"); * Node n = // Node creation code here; * xmlUtils.insertNodeBefore(newNode, child, parent); * * } * </pre> * * @param newNode the Node to be added * @param existingNode the Node to insert before * @param parent the parent Node * @throws Exception on error. */ public void insertNodeBefore(Node newNode, Node existingNode, Node parent) throws Exception { Document parentDoc = parent.getOwnerDocument(); Document newDoc = newNode.getOwnerDocument(); Node nodeToAdd = newNode; if (!parentDoc.equals(newDoc)) { nodeToAdd = parentDoc.importNode(newNode, true); } parent.insertBefore(nodeToAdd, existingNode); }
From source file:org.structr.web.entity.dom.DOMNode.java
protected void checkSameDocument(Node otherNode) throws DOMException { Document doc = getOwnerDocument(); if (doc != null) { Document otherDoc = otherNode.getOwnerDocument(); // Shadow doc is neutral if (otherDoc != null && !doc.equals(otherDoc) && !(doc instanceof ShadowDocument)) { throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, WRONG_DOCUMENT_ERR_MESSAGE); }/*from w w w. j a va 2s . c o m*/ if (otherDoc == null) { ((DOMNode) otherNode).doAdopt((Page) doc); } } }
From source file:org.kalypsodeegree.xml.XMLTools.java
/** * inserts a node into a dom element (of a different dom document) *//*from w ww. jav a 2 s. c o m*/ public static Node insertNodeInto(final Node source, final Node dest) { Document dDoc = null; final Document sDoc = source.getOwnerDocument(); if (dest instanceof Document) { dDoc = (Document) dest; } else { dDoc = dest.getOwnerDocument(); } if (dDoc.equals(sDoc)) { dest.appendChild(source); } else { final Element element = dDoc.createElementNS(source.getNamespaceURI(), source.getNodeName()); dest.appendChild(element); copyNode(source, element); } return dest; }
From source file:org.structr.web.entity.dom.DOMNode.java
public Template getClosestTemplate(final Page page) { DOMNode node = this; while (node != null) { if (node instanceof Template) { final Template template = (Template) node; Document doc = template.getOwnerDocument(); if (doc == null) { doc = node.getClosestPage(); }//from ww w . j ava 2 s.c o m if (doc != null && (page == null || doc.equals(page))) { return template; } final List<DOMNode> _syncedNodes = template.getProperty(DOMNode.syncedNodes); for (final DOMNode syncedNode : _syncedNodes) { doc = syncedNode.getOwnerDocument(); if (doc != null && (page == null || doc.equals(page))) { return (Template) syncedNode; } } } node = (DOMNode) node.getParentNode(); } return null; }