private Node importNode( final Node node, final boolean deep, final boolean removeParentFromSourceNode) throws DOMException { if (node instanceof DOMNode) { final DOMNode domNode = (DOMNode) node; // step 1: use type-specific import impl. Node importedNode = domNode.doImport(Page.this); // step 2: do recursive import? if (deep && domNode.hasChildNodes()) { // FIXME: is it really a good idea to do the // recursion inside of a transaction? Node child = domNode.getFirstChild(); while (child != null) { // do not remove parent for child nodes importNode(child, deep, false); child = child.getNextSibling(); logger.log(Level.INFO, "sibling is {0}", child); } } // step 3: remove node from its current parent // (Note that this step needs to be done last in // (order for the child to be able to find its // siblings.) if (removeParentFromSourceNode) { // only do this for the actual source node, do not remove // child nodes from its parents Node _parent = domNode.getParentNode(); if (_parent != null) { _parent.removeChild(domNode); } } return importedNode; } return null; }
private Node adoptNode(final Node node, final boolean removeParentFromSourceNode) throws DOMException { if (node instanceof DOMNode) { final DOMNode domNode = (DOMNode) node; // step 2: do recursive import? if (domNode.hasChildNodes()) { Node child = domNode.getFirstChild(); while (child != null) { // do not remove parent for child nodes adoptNode(child, false); child = child.getNextSibling(); } } // step 3: remove node from its current parent // (Note that this step needs to be done last in // (order for the child to be able to find its // siblings.) if (removeParentFromSourceNode) { // only do this for the actual source node, do not remove // child nodes from its parents Node _parent = domNode.getParentNode(); if (_parent != null) { _parent.removeChild(domNode); } } // step 1: use type-specific adopt impl. Node adoptedNode = domNode.doAdopt(Page.this); return adoptedNode; } return null; }