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

📄 domdocument.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    Node root = getDocumentElement();    return (root == null) ? false : root.isDefaultNamespace(namespaceURI);  }  public String lookupNamespaceURI(String prefix)  {    Node root = getDocumentElement();    return (root == null) ? null : root.lookupNamespaceURI(prefix);  }  public String getBaseURI()  {    return getDocumentURI();    /*    Node root = getDocumentElement();    if (root != null)      {        NamedNodeMap attrs = root.getAttributes();        Node xmlBase = attrs.getNamedItemNS(XMLConstants.XML_NS_URI, "base");        if (xmlBase != null)          {            return xmlBase.getNodeValue();          }      }    return systemId;    */  }    public String getDocumentURI()  {    return systemId;  }  public void setDocumentURI(String documentURI)  {    systemId = documentURI;  }  public Node adoptNode(Node source)  {    int sourceNodeType = source.getNodeType();    switch (sourceNodeType)      {      case DOCUMENT_NODE:      case DOCUMENT_TYPE_NODE:        throw new DomDOMException(DOMException.NOT_SUPPORTED_ERR);      case ENTITY_NODE:      case NOTATION_NODE:        throw new DomDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR);      }    if (source instanceof DomNode)      {        // GNU native        DomNode src = (DomNode) source;        DomNode dst = src;        if (dst.parent != null)          {            dst = (DomNode) dst.cloneNode(true);          }        dst.setOwner(this);        src.notifyUserDataHandlers(UserDataHandler.NODE_ADOPTED, src, dst);        return dst;      }    else      {        // Some other implementation        Node dst = null;        switch (sourceNodeType)          {          case Node.ATTRIBUTE_NODE:              {                Attr src = (Attr) source;                String nodeName = src.getNodeName();                String localName = src.getLocalName();                String namespaceUri = src.getNamespaceURI();                dst = (localName == null) ?                  createAttribute(nodeName) :                  createAttributeNS(namespaceUri, nodeName);                adoptChildren(src, dst);                break;              }          case Node.CDATA_SECTION_NODE:              {                CDATASection src = (CDATASection) source;                dst = createCDATASection(src.getData());                break;              }          case Node.COMMENT_NODE:              {                Comment src = (Comment) source;                dst = createComment(src.getData());                break;              }          case Node.DOCUMENT_FRAGMENT_NODE:              {                DocumentFragment src = (DocumentFragment) source;                dst = createDocumentFragment();                adoptChildren(src, dst);                break;              }          case Node.ELEMENT_NODE:              {                Element src = (Element) source;                String nodeName = src.getNodeName();                String localName = src.getLocalName();                String namespaceUri = src.getNamespaceURI();                dst = (localName == null) ?                  createElement(nodeName) :                  createElementNS(namespaceUri, nodeName);                adoptAttributes(src, dst);                adoptChildren(src, dst);                break;              }          case Node.ENTITY_REFERENCE_NODE:              {                EntityReference src = (EntityReference) source;                dst = createEntityReference(src.getNodeName());                adoptChildren(src, dst);                break;              }          case Node.PROCESSING_INSTRUCTION_NODE:              {                ProcessingInstruction src = (ProcessingInstruction) source;                dst = createProcessingInstruction(src.getTarget(),                                                  src.getData());                break;              }          case Node.TEXT_NODE:              {                Text src = (Text) source;                dst = createTextNode(src.getData());                break;              }          }        return dst;      }  }  void adoptChildren(Node src, Node dst)  {    Node node = src.getFirstChild();    while (node != null)      {        Node next = node.getNextSibling();        dst.appendChild(adoptNode(node));        node = next;      }  }  void adoptAttributes(Node src, Node dst)  {    NamedNodeMap srcAttrs = src.getAttributes();    NamedNodeMap dstAttrs = dst.getAttributes();    int len = srcAttrs.getLength();    for (int i = 0; i < len; i++)      {        Node node = srcAttrs.item(i);        String localName = node.getLocalName();        if (localName == null)          {            dstAttrs.setNamedItem(adoptNode(node));          }        else          {            dstAttrs.setNamedItemNS(adoptNode(node));          }      }  }  public DOMConfiguration getDomConfig()  {    if (config == null)      {        config = new DomDocumentConfiguration();      }    return config;  }  public void normalizeDocument()  {    boolean save = building;    building = true;    normalizeNode(this);    building = save;  }  void normalizeNode(DomNode node)  {    node.normalize();    if (config != null)      {        switch (node.nodeType)          {          case CDATA_SECTION_NODE:            if (!config.cdataSections)              {                // replace CDATA section with text node                Text text = createTextNode(node.getNodeValue());                node.parent.insertBefore(text, node);                node.parent.removeChild(node);                // merge adjacent text nodes                String data = text.getWholeText();                node = (DomNode) text.replaceWholeText(data);              }            else if (config.splitCdataSections)              {                String value = node.getNodeValue();                int i = value.indexOf("]]>");                while (i != -1)                  {                    Node node2 = createCDATASection(value.substring(0, i));                    node.parent.insertBefore(node2, node);                    value = value.substring(i + 3);                    node.setNodeValue(value);                    i = value.indexOf("]]>");                  }              }            break;          case COMMENT_NODE:            if (!config.comments)              {                node.parent.removeChild(node);              }            break;          case TEXT_NODE:            if (!config.elementContentWhitespace &&                ((Text) node).isElementContentWhitespace())              {                node.parent.removeChild(node);              }            break;          case ENTITY_REFERENCE_NODE:            if (!config.entities)              {                for (DomNode ctx = node.first; ctx != null; )                  {                    DomNode ctxNext = ctx.next;                    node.parent.insertBefore(ctx, node);                    ctx = ctxNext;                  }                node.parent.removeChild(node);              }            break;          case ELEMENT_NODE:            if (!config.namespaceDeclarations)              {                DomNamedNodeMap attrs =                  (DomNamedNodeMap) node.getAttributes();                boolean aro = attrs.readonly;                attrs.readonly = false; // Ensure we can delete if necessary                int len = attrs.getLength();                for (int i = 0; i < len; i++)                  {                    Node attr = attrs.item(i);                    String namespace = attr.getNamespaceURI();                    if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespace))                      {                        attrs.removeNamedItemNS(namespace,                                                attr.getLocalName());                        i--;                        len--;                      }                  }                attrs.readonly = aro;              }            break;          }      }    for (DomNode ctx = node.first; ctx != null; )      {        DomNode ctxNext = ctx.next;        normalizeNode(ctx);        ctx = ctxNext;      }  }    public Node renameNode(Node n, String namespaceURI, String qualifiedName)    throws DOMException  {    if (n instanceof DomNsNode)      {        DomNsNode src = (DomNsNode) n;        if (src == null)          {            throw new DomDOMException(DOMException.NOT_FOUND_ERR);          }        if (src.owner != this)          {            throw new DomDOMException(DOMException.WRONG_DOCUMENT_ERR,                                      null, src, 0);          }        boolean xml11 = "1.1".equals(version);        checkName(qualifiedName, xml11);        int ci = qualifiedName.indexOf(':');        if ("".equals(namespaceURI))          {            namespaceURI = null;          }        if (namespaceURI != null)          {            checkNCName(qualifiedName, xml11);            String prefix = (ci == -1) ? "" :              qualifiedName.substring(0, ci);            if (XMLConstants.XML_NS_PREFIX.equals(prefix) &&                !XMLConstants.XML_NS_URI.equals(namespaceURI))              {                throw new DomDOMException(DOMException.NAMESPACE_ERR,                                "xml namespace must be " +                                XMLConstants.XML_NS_URI, src, 0);              }            else if (src.nodeType == ATTRIBUTE_NODE &&                     (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) ||                      XMLConstants.XMLNS_ATTRIBUTE.equals(qualifiedName)) &&                     !XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceURI))              {                throw new DomDOMException(DOMException.NAMESPACE_ERR,                                "xmlns namespace must be " +                                XMLConstants.XMLNS_ATTRIBUTE_NS_URI, src, 0);              }            if (XMLConstants.XML_NS_URI.equals(namespaceURI) &&                !XMLConstants.XML_NS_PREFIX.equals(prefix))              {                throw new DomDOMException(DOMException.NAMESPACE_ERR,                                "xml namespace must be " +                                XMLConstants.XML_NS_URI, src, 0);              }            else if (src.nodeType == ATTRIBUTE_NODE &&                     XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceURI) &&                     !(XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) ||                       XMLConstants.XMLNS_ATTRIBUTE.equals(qualifiedName)))              {                throw new DomDOMException(DOMException.NAMESPACE_ERR,                                "xmlns namespace must be " +                                XMLConstants.XMLNS_ATTRIBUTE_NS_URI, src, 0);              }                          }        src.setNodeName(qualifiedName);        src.setNamespaceURI(namespaceURI);        src.notifyUserDataHandlers(UserDataHandler.NODE_RENAMED, src, src);        // TODO MutationNameEvents        // DOMElementNameChanged or DOMAttributeNameChanged        return src;      }    throw new DomDOMException(DOMException.NOT_SUPPORTED_ERR, null, n, 0);  }  // -- XPathEvaluator --    public XPathExpression createExpression(String expression,                                          XPathNSResolver resolver)    throws XPathException, DOMException  {    return new DomXPathExpression(this, expression, resolver);  }    public XPathNSResolver createNSResolver(Node nodeResolver)  {    return new DomXPathNSResolver(nodeResolver);  }      public Object evaluate(String expression,                         Node contextNode,                         XPathNSResolver resolver,                         short type,                         Object result)    throws XPathException, DOMException  {    XPathExpression xpe =      new DomXPathExpression(this, expression, resolver);    return xpe.evaluate(contextNode, type, result);  }}

⌨️ 快捷键说明

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