List of usage examples for org.w3c.dom DocumentFragment removeChild
public Node removeChild(Node oldChild) throws DOMException;
oldChild
from the list of children, and returns it. From source file:org.structr.web.entity.dom.DOMNode.java
@Override public Node insertBefore(final Node newChild, final Node refChild) throws DOMException { // according to DOM spec, insertBefore with null refChild equals appendChild if (refChild == null) { return appendChild(newChild); }//from www. j a va2 s. c o m checkWriteAccess(); checkSameDocument(newChild); checkSameDocument(refChild); checkHierarchy(newChild); checkHierarchy(refChild); if (newChild instanceof DocumentFragment) { // When inserting document fragments, we must take // care of the special case that the nodes already // have a NEXT_LIST_ENTRY relationship coming from // the document fragment, so we must first remove // the node from the document fragment and then // add it to the new parent. final DocumentFragment fragment = (DocumentFragment) newChild; Node currentChild = fragment.getFirstChild(); while (currentChild != null) { // save next child in fragment list for later use Node savedNextChild = currentChild.getNextSibling(); // remove child from document fragment fragment.removeChild(currentChild); // insert child into new parent insertBefore(currentChild, refChild); // next currentChild = savedNextChild; } } else { final Node _parent = newChild.getParentNode(); if (_parent != null) { _parent.removeChild(newChild); } try { // do actual tree insertion here treeInsertBefore((DOMNode) newChild, (DOMNode) refChild); } catch (FrameworkException frex) { if (frex.getStatus() == 404) { throw new DOMException(DOMException.NOT_FOUND_ERR, frex.getMessage()); } else { throw new DOMException(DOMException.INVALID_STATE_ERR, frex.getMessage()); } } // allow parent to set properties in new child handleNewChild(newChild); } return refChild; }
From source file:org.structr.web.entity.dom.DOMNode.java
@Override public Node replaceChild(final Node newChild, final Node oldChild) throws DOMException { checkWriteAccess();//from ww w .ja va 2 s . c o m checkSameDocument(newChild); checkSameDocument(oldChild); checkHierarchy(newChild); checkHierarchy(oldChild); if (newChild instanceof DocumentFragment) { // When inserting document fragments, we must take // care of the special case that the nodes already // have a NEXT_LIST_ENTRY relationship coming from // the document fragment, so we must first remove // the node from the document fragment and then // add it to the new parent. // replace indirectly using insertBefore and remove final DocumentFragment fragment = (DocumentFragment) newChild; Node currentChild = fragment.getFirstChild(); while (currentChild != null) { // save next child in fragment list for later use final Node savedNextChild = currentChild.getNextSibling(); // remove child from document fragment fragment.removeChild(currentChild); // add child to new parent insertBefore(currentChild, oldChild); // next currentChild = savedNextChild; } // finally, remove reference element removeChild(oldChild); } else { Node _parent = newChild.getParentNode(); if (_parent != null && _parent instanceof DOMNode) { _parent.removeChild(newChild); } try { // replace directly treeReplaceChild((DOMNode) newChild, (DOMNode) oldChild); } catch (FrameworkException frex) { if (frex.getStatus() == 404) { throw new DOMException(DOMException.NOT_FOUND_ERR, frex.getMessage()); } else { throw new DOMException(DOMException.INVALID_STATE_ERR, frex.getMessage()); } } // allow parent to set properties in new child handleNewChild(newChild); } return oldChild; }
From source file:org.structr.web.entity.dom.DOMNode.java
@Override public Node appendChild(final Node newChild) throws DOMException { checkWriteAccess();/* ww w .jav a 2s . c om*/ checkSameDocument(newChild); checkHierarchy(newChild); try { if (newChild instanceof DocumentFragment) { // When inserting document fragments, we must take // care of the special case that the nodes already // have a NEXT_LIST_ENTRY relationship coming from // the document fragment, so we must first remove // the node from the document fragment and then // add it to the new parent. // replace indirectly using insertBefore and remove final DocumentFragment fragment = (DocumentFragment) newChild; Node currentChild = fragment.getFirstChild(); while (currentChild != null) { // save next child in fragment list for later use final Node savedNextChild = currentChild.getNextSibling(); // remove child from document fragment fragment.removeChild(currentChild); // append child to new parent appendChild(currentChild); // next currentChild = savedNextChild; } } else { final Node _parent = newChild.getParentNode(); if (_parent != null && _parent instanceof DOMNode) { _parent.removeChild(newChild); } treeAppendChild((DOMNode) newChild); // allow parent to set properties in new child handleNewChild(newChild); } } catch (FrameworkException fex) { throw new DOMException(DOMException.INVALID_STATE_ERR, fex.toString()); } return newChild; }