📄 domnode.java
字号:
else { for (int j = i + 1; j < nListeners; j++) { listeners[i++] = listeners[j++]; } listeners[--nListeners] = null; } break; } // no exceptions reported } /** * <b>DOM L1 (relocated in DOM L2)</b> * In this node and all contained nodes (including attributes if * relevant) merge adjacent text nodes. This is done while ignoring * text which happens to use CDATA delimiters). */ public final void normalize() { // Suspend readonly status boolean saved = readonly; readonly = false; for (DomNode ctx = first; ctx != null; ctx = ctx.next) { switch (ctx.nodeType) { case TEXT_NODE: while (ctx.next != null && ctx.next.nodeType == TEXT_NODE) { Text text = (Text) ctx; text.appendData(ctx.next.getNodeValue()); removeChild(ctx.next); } break; case ELEMENT_NODE: NamedNodeMap attrs = ctx.getAttributes(); int len = attrs.getLength(); for (int i = 0; i < len; i++) { attrs.item(i).normalize(); } // Fall through case DOCUMENT_NODE: case DOCUMENT_FRAGMENT_NODE: case ATTRIBUTE_NODE: case ENTITY_REFERENCE_NODE: ctx.normalize(); break; } } readonly = saved; } /** * Returns true iff node types match, and either (a) both nodes have no * namespace and their getNodeName() values are the same, or (b) both * nodes have the same getNamespaceURI() and same getLocalName() values. * * <p>Note that notion of a "Per-Element-Type" attribute name scope, as * found in a non-normative appendix of the XML Namespaces specification, * is not supported here. Your application must implement that notion, * typically by not bothering to check nameAndTypeEquals for attributes * without namespace URIs unless you already know their elements are * nameAndTypeEquals. */ public boolean nameAndTypeEquals(Node other) { if (other == this) { return true; } // node types must match if (nodeType != other.getNodeType()) { return false; } // if both have namespaces, do a "full" comparision // this is a "global" partition String ns1 = this.getNamespaceURI(); String ns2 = other.getNamespaceURI(); if (ns1 != null && ns2 != null) { return ns1.equals(ns2) && equal(getLocalName(), other.getLocalName()); } // if neither has a namespace, this is a "no-namespace" name. if (ns1 == null && ns2 == null) { if (!getNodeName().equals(other.getNodeName())) { return false; } // can test the non-normative "per-element-type" scope here. // if this is an attribute node and both nodes have been bound // to elements (!!), then return the nameAndTypeEquals() // comparison of those elements. return true; } // otherwise they're unequal: one scoped, one not. return false; } // DOM Level 3 methods public String getBaseURI() { return (parent != null) ? parent.getBaseURI() : null; } public short compareDocumentPosition(Node other) throws DOMException { return (short) compareTo(other); } /** * DOM nodes have a natural ordering: document order. */ public final int compareTo(Object other) { if (other instanceof DomNode) { DomNode n1 = this; DomNode n2 = (DomNode) other; if (n1.owner != n2.owner) { return 0; } int d1 = n1.depth, d2 = n2.depth; int delta = d1 - d2; while (d1 > d2) { n1 = n1.parent; d1--; } while (d2 > d1) { n2 = n2.parent; d2--; } int c = compareTo2(n1, n2); return (c != 0) ? c : delta; } return 0; } /** * Compare two nodes at the same depth. */ final int compareTo2(DomNode n1, DomNode n2) { if (n1 == n2 || n1.depth == 0 || n2.depth == 0) { return 0; } int c = compareTo2(n1.parent, n2.parent); return (c != 0) ? c : n1.index - n2.index; } public final String getTextContent() throws DOMException { return getTextContent(true); } final String getTextContent(boolean topLevel) throws DOMException { switch (nodeType) { case ELEMENT_NODE: case ENTITY_NODE: case ENTITY_REFERENCE_NODE: case DOCUMENT_FRAGMENT_NODE: StringBuffer buffer = new StringBuffer(); for (DomNode ctx = first; ctx != null; ctx = ctx.next) { String textContent = ctx.getTextContent(false); if (textContent != null) { buffer.append(textContent); } } return buffer.toString(); case TEXT_NODE: case CDATA_SECTION_NODE: if (((Text) this).isElementContentWhitespace()) { return ""; } return getNodeValue(); case ATTRIBUTE_NODE: return getNodeValue(); case COMMENT_NODE: case PROCESSING_INSTRUCTION_NODE: return topLevel ? getNodeValue() : ""; default: return null; } } public void setTextContent(String textContent) throws DOMException { switch (nodeType) { case ELEMENT_NODE: case ATTRIBUTE_NODE: case ENTITY_NODE: case ENTITY_REFERENCE_NODE: case DOCUMENT_FRAGMENT_NODE: for (DomNode ctx = first; ctx != null; ) { DomNode n = ctx.next; removeChild(ctx); ctx = n; } if (textContent != null) { Text text = owner.createTextNode(textContent); appendChild(text); } break; case TEXT_NODE: case CDATA_SECTION_NODE: case COMMENT_NODE: case PROCESSING_INSTRUCTION_NODE: setNodeValue(textContent); break; } } public boolean isSameNode(Node other) { return this == other; } public String lookupPrefix(String namespaceURI) { return (parent == null || parent == owner) ? null : parent.lookupPrefix(namespaceURI); } public boolean isDefaultNamespace(String namespaceURI) { return (parent == null || parent == owner) ? false : parent.isDefaultNamespace(namespaceURI); } public String lookupNamespaceURI(String prefix) { return (parent == null || parent == owner) ? null : parent.lookupNamespaceURI(prefix); } public boolean isEqualNode(Node arg) { if (this == arg) { return true; } if (arg == null) { return false; } if (nodeType != arg.getNodeType() || !equal(getNodeName(), arg.getNodeName()) || !equal(getLocalName(), arg.getLocalName()) || !equal(getNamespaceURI(), arg.getNamespaceURI()) || !equal(getPrefix(), arg.getPrefix()) || !equal(getNodeValue(), arg.getNodeValue())) { return false; } // Children Node argCtx = arg.getFirstChild(); getFirstChild(); // because of DomAttr lazy children for (DomNode ctx = first; ctx != null; ctx = ctx.next) { if (!ctx.isEqualNode(argCtx)) { return false; } argCtx = argCtx.getNextSibling(); } if (argCtx != null) { return false; } // TODO Attr NamedNodeMap // TODO DocumentType return true; } boolean equal(String arg1, String arg2) { return ((arg1 == null && arg2 == null) || (arg1 != null && arg1.equals(arg2))); } public Object getFeature(String feature, String version) { DOMImplementation impl = (nodeType == DOCUMENT_NODE) ? ((Document) this).getImplementation() : owner.getImplementation(); if (impl.hasFeature(feature, version)) { return this; } return null; } public Object setUserData(String key, Object data, UserDataHandler handler) { if (userData == null) { userData = new HashMap(); } if (handler != null) { if (userDataHandlers == null) { userDataHandlers = new HashMap(); } userDataHandlers.put(key, handler); } return userData.put(key, data); } public Object getUserData(String key) { if (userData == null) { return null; } return userData.get(key); } public String toString() { String nodeName = getNodeName(); String nodeValue = getNodeValue(); StringBuffer buf = new StringBuffer(getClass().getName()); buf.append('['); if (nodeName != null) { buf.append(nodeName); } if (nodeValue != null) { if (nodeName != null) { buf.append('='); } buf.append('\''); buf.append(encode(nodeValue)); buf.append('\''); } buf.append(']'); return buf.toString(); } String encode(String value) { StringBuffer buf = null; int len = value.length(); for (int i = 0; i < len; i++) { char c = value.charAt(i); if (c == '\n') { if (buf == null) { buf = new StringBuffer(value.substring(0, i)); } buf.append("\\n"); } else if (c == '\r') { if (buf == null) { buf = new StringBuffer(value.substring(0, i)); } buf.append("\\r"); } else if (buf != null) { buf.append(c); } } return (buf != null) ? buf.toString() : value; } String nodeTypeToString(short nodeType) { switch (nodeType) { case ELEMENT_NODE: return "ELEMENT_NODE"; case ATTRIBUTE_NODE: return "ATTRIBUTE_NODE"; case TEXT_NODE: return "TEXT_NODE"; case CDATA_SECTION_NODE: return "CDATA_SECTION_NODE"; case DOCUMENT_NODE: return "DOCUMENT_NODE"; case DOCUMENT_TYPE_NODE: return "DOCUMENT_TYPE_NODE"; case COMMENT_NODE: return "COMMENT_NODE"; case PROCESSING_INSTRUCTION_NODE: return "PROCESSING_INSTRUCTION_NODE"; case DOCUMENT_FRAGMENT_NODE: return "DOCUMENT_FRAGMENT_NODE"; case ENTITY_NODE: return "ENTITY_NODE"; case ENTITY_REFERENCE_NODE: return "ENTITY_REFERENCE_NODE"; case NOTATION_NODE: return "NOTATION_NODE"; default: return "UNKNOWN"; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -