⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 domnode.java

📁 linux下建立JAVA虚拟机的源码KAFFE
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                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++)              {                DomNode attr = (DomNode) attrs.item(i);                boolean saved3 = attr.readonly;                attr.readonly = false;                attr.normalize();                attr.readonly = saved3;              }            // Fall through          case DOCUMENT_NODE:          case DOCUMENT_FRAGMENT_NODE:          case ATTRIBUTE_NODE:          case ENTITY_REFERENCE_NODE:            ctx.normalize();            break;          }        ctx.readonly = saved2;      }    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())      return false;    switch (nodeType)      {      case ELEMENT_NODE:      case ATTRIBUTE_NODE:        if (!equal(getLocalName(), arg.getLocalName()) ||            !equal(getNamespaceURI(), arg.getNamespaceURI()))          return false;        break;      case PROCESSING_INSTRUCTION_NODE:        if (!equal(getNodeName(), arg.getNodeName()) ||            !equal(getNodeValue(), arg.getNodeValue()))          return false;        break;      case COMMENT_NODE:      case TEXT_NODE:      case CDATA_SECTION_NODE:        if (!equal(getNodeValue(), arg.getNodeValue()))          return false;        break;      }    // Children    Node argCtx = arg.getFirstChild();    getFirstChild(); // because of DomAttr lazy children    DomNode ctx = first;    for (; ctx != null && argCtx != null; ctx = ctx.next)      {        if (nodeType == DOCUMENT_NODE)          {            // Ignore whitespace outside document element            while (ctx != null && ctx.nodeType == TEXT_NODE)              ctx = ctx.next;            while (argCtx != null && ctx.getNodeType() == TEXT_NODE)              argCtx = argCtx.getNextSibling();            if (ctx == null && argCtx != null)              return false;            else if (argCtx == null && ctx != null)              return false;          }        if (!ctx.isEqualNode(argCtx))          return false;        argCtx = argCtx.getNextSibling();      }    if (ctx != null || argCtx != null)      return false;        // 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";      }  }  public void list(java.io.PrintStream out, int indent)  {    for (int i = 0; i < indent; i++)      out.print(" ");    out.println(toString());    for (DomNode ctx = first; ctx != null; ctx = ctx.next)      ctx.list(out, indent + 1);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -