elemtemplateelement.java
来自「java jdk 1.4的源码」· Java 代码 · 共 1,705 行 · 第 1/4 页
JAVA
1,705 行
* Return the nodelist (same reference). * * @return The nodelist containing the child nodes (this) */ public NodeList getChildNodes() { return this; } /** * 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; } /** * 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; } /** * Unimplemented. See org.w3c.dom.Node * * @param newChild New child node to insert * @param refChild Insert in front of this child * * @return null * * @throws DOMException */ public Node insertBefore(Node newChild, Node refChild) throws DOMException { if(null == refChild) { appendChild(newChild); return newChild; } if(newChild == refChild) { // hmm... return newChild; } Node node = m_firstChild; Node prev = null; boolean foundit = false; while (null != node) { // If the newChild is already in the tree, it is first removed. if(newChild == node) { if(null != prev) ((ElemTemplateElement)prev).m_nextSibling = (ElemTemplateElement)node.getNextSibling(); else m_firstChild = (ElemTemplateElement)node.getNextSibling(); node = node.getNextSibling(); continue; // prev remains the same. } if(refChild == node) { if(null != prev) { ((ElemTemplateElement)prev).m_nextSibling = (ElemTemplateElement)newChild; } else { m_firstChild = (ElemTemplateElement)newChild; } ((ElemTemplateElement)newChild).m_nextSibling = (ElemTemplateElement)refChild; ((ElemTemplateElement)newChild).setParentElem(this); prev = newChild; node = node.getNextSibling(); foundit = true; continue; } prev = node; node = node.getNextSibling(); } if(!foundit) throw new DOMException(DOMException.NOT_FOUND_ERR, "refChild was not found in insertBefore method!"); else return newChild; } /** * 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 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; } /** * NodeList method: Count the immediate children of this node * * @return The count of children of this node */ public int getLength() { // It is assumed that the getChildNodes call synchronized // the children. Therefore, we can access the first child // reference directly. int count = 0; for (ElemTemplateElement node = m_firstChild; node != null; node = node.m_nextSibling) { count++; } return count; } // getLength():int /** * NodeList method: Return the Nth immediate child of this node, or * null if the index is out of bounds. * * @param index Index of child to find * @return org.w3c.dom.Node: the child node at given index */ public Node item(int index) { // It is assumed that the getChildNodes call synchronized // the children. Therefore, we can access the first child // reference directly. ElemTemplateElement node = m_firstChild; for (int i = 0; i < index && node != null; i++) { node = node.m_nextSibling; } return node; } // item(int):Node /** * Get the stylesheet owner. * * @return The stylesheet owner */ public Document getOwnerDocument() { return getStylesheet(); } /** * Get the owning xsl:template element. * * @return The owning xsl:template element, this element if it is a xsl:template, or null if not found. */ public ElemTemplate getOwnerXSLTemplate() { ElemTemplateElement el = this; int type = el.getXSLToken(); while((null != el) && (type != Constants.ELEMNAME_TEMPLATE)) { el = el.getParentElem(); if(null != el) type = el.getXSLToken(); } return (ElemTemplate)el; } /** * Return the element name. * * @return The element name */ public String getTagName() { return getNodeName(); } /** * Tell if this element only has one text child, for optimization purposes. * @return true of this element only has one text literal child. */ public boolean hasTextLitOnly() { return m_hasTextLitOnly; } /** * Return the base identifier. * * @return The base identifier */ public String getBaseIdentifier() { // Should this always be absolute? return this.getSystemId(); } /** line number where the current document event ends. * @serial */ private int m_lineNumber; /** * Return the line number where the current document event ends. * Note that this is the line position of the first character * after the text associated with the document event. * @return The line number, or -1 if none is available. * @see #getColumnNumber */ public int getLineNumber() { return m_lineNumber; } /** the column number where the current document event ends. * @serial */ private int m_columnNumber; /** * Return the column number where the current document event ends. * Note that this is the column number of the first * character after the text associated with the document * event. The first column in a line is position 1. * @return The column number, or -1 if none is available. * @see #getLineNumber */ public int getColumnNumber() { return m_columnNumber; } /** * Return the public identifier for the current document event. * <p>This will be the public identifier * @return A string containing the public identifier, or * null if none is available. * @see #getSystemId */ public String getPublicId() { return (null != m_parentNode) ? m_parentNode.getPublicId() : null; } /** * Return the system identifier for the current document event. * * <p>If the system identifier is a URL, the parser must resolve it * fully before passing it to the application.</p> * * @return A string containing the system identifier, or null * if none is available. * @see #getPublicId */ public String getSystemId() { Stylesheet sheet=getStylesheet(); return (sheet==null) ? null : sheet.getHref(); } /** * Set the location information for this element. * * @param locator Source Locator with location information for this element */ public void setLocaterInfo(SourceLocator locator) { m_lineNumber = locator.getLineNumber(); m_columnNumber = locator.getColumnNumber(); } /** * Tell if this element has the default space handling * turned off or on according to the xml:space attribute. * @serial */ private boolean m_defaultSpace = true; /** * Tell if this element only has one text child, for optimization purposes. * @serial */ private boolean m_hasTextLitOnly = false; /** * Tell if this element only has one text child, for optimization purposes. * @serial */ protected boolean m_hasVariableDecl = false; public boolean hasVariableDecl() { return m_hasVariableDecl; } /** * Set the "xml:space" attribute. * A text node is preserved if an ancestor element of the text node * has an xml:space attribute with a value of preserve, and * no closer ancestor element has xml:space with a value of default. * @see <a href="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a> * @see <a href="http://www.w3.org/TR/xslt#section-Creating-Text">section-Creating-Text in XSLT Specification</a> * * @param v Enumerated value, either Constants.ATTRVAL_PRESERVE * or Constants.ATTRVAL_STRIP. */ public void setXmlSpace(int v) { m_defaultSpace = ((Constants.ATTRVAL_STRIP == v) ? true : false); } /** * Get the "xml:space" attribute. * A text node is preserved if an ancestor element of the text node * has an xml:space attribute with a value of preserve, and * no closer ancestor element has xml:space with a value of default. * @see <a href="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a> * @see <a href="http://www.w3.org/TR/xslt#section-Creating-Text">section-Creating-Text in XSLT Specification</a> * * @return The value of the xml:space attribute */ public boolean getXmlSpace() { return m_defaultSpace; } /**
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?