/** * Replace the old child with a new child. * * @param newChildElem New child to replace with * @param oldChildElem Old child to be replaced * @return The new child * @throws DOMException */ public ElemTemplateElement replaceChild( ElemTemplateElement newChildElem, ElemTemplateElement oldChildElem) { if (oldChildElem == null || oldChildElem.getParentElem() != this) return null; // Fix up previous sibling. ElemTemplateElement prev = oldChildElem.getPreviousSiblingElem(); if (null != prev) prev.m_nextSibling = newChildElem; // Fix up parent (this) if (m_firstChild == oldChildElem) m_firstChild = newChildElem; newChildElem.m_parentNode = this; oldChildElem.m_parentNode = null; newChildElem.m_nextSibling = oldChildElem.m_nextSibling; oldChildElem.m_nextSibling = null; // newChildElem.m_stylesheet = oldChildElem.m_stylesheet; // oldChildElem.m_stylesheet = null; return newChildElem; }
/** * Replace the old child with a new child. * * @param newChild New child to replace with * @param oldChild Old child to be replaced * @return The new child * @throws DOMException */ public Node replaceChild(Node newChild, Node oldChild) throws DOMException { if (oldChild == null || oldChild.getParentNode() != this) return null; ElemTemplateElement newChildElem = ((ElemTemplateElement) newChild); ElemTemplateElement oldChildElem = ((ElemTemplateElement) oldChild); // Fix up previous sibling. ElemTemplateElement prev = (ElemTemplateElement) oldChildElem.getPreviousSibling(); if (null != prev) prev.m_nextSibling = newChildElem; // Fix up parent (this) if (m_firstChild == oldChildElem) m_firstChild = newChildElem; newChildElem.m_parentNode = this; oldChildElem.m_parentNode = null; newChildElem.m_nextSibling = oldChildElem.m_nextSibling; oldChildElem.m_nextSibling = null; // newChildElem.m_stylesheet = oldChildElem.m_stylesheet; // oldChildElem.m_stylesheet = null; return newChildElem; }
/** * Remove a child. ADDED 9/8/200 to support compilation. TODO: ***** Alternative is "removeMe() * from my parent if any" ... which is less well checked, but more convenient in some cases. Given * that we assume only experts are calling this class, it might be preferable. It's less DOMish, * though. * * @param childETE The child to remove. This operation is a no-op if oldChild is not a child of * this node. * @return the removed child, or null if the specified node was not a child of this element. */ public ElemTemplateElement removeChild(ElemTemplateElement childETE) { if (childETE == null || childETE.m_parentNode != this) return null; // Pointers to the child if (childETE == m_firstChild) m_firstChild = childETE.m_nextSibling; else { ElemTemplateElement prev = childETE.getPreviousSiblingElem(); prev.m_nextSibling = childETE.m_nextSibling; } // Pointers from the child childETE.m_parentNode = null; childETE.m_nextSibling = null; return childETE; }
/** * Add a child to the child list. NOTE: This presumes the child did not previously have a parent. * Making that assumption makes this a less expensive operation -- but requires that if you *do* * want to reparent a node, you use removeChild() first to remove it from its previous context. * Failing to do so will damage the tree. * * @param newChild Child to be added to child list * @return Child just added to the child list * @throws DOMException */ public Node appendChild(Node newChild) throws DOMException { if (null == newChild) { error(XSLTErrorResources.ER_NULL_CHILD, null); // "Trying to add a null child!"); } ElemTemplateElement elem = (ElemTemplateElement) newChild; if (null == m_firstChild) { m_firstChild = elem; } else { ElemTemplateElement last = (ElemTemplateElement) getLastChild(); last.m_nextSibling = elem; } elem.m_parentNode = this; return newChild; }