coredocumentimpl.java

来自「JAVA 所有包」· Java 代码 · 共 1,776 行 · 第 1/5 页

JAVA
1,776
字号
    /**     * Retrieve information describing the abilities of this particular     * DOM implementation. Intended to support applications that may be     * using DOMs retrieved from several different sources, potentially     * with different underlying representations.     */    public DOMImplementation getImplementation() {        // Currently implemented as a singleton, since it's hardcoded        // information anyway.        return CoreDOMImplementationImpl.getDOMImplementation();    }    //    // Public methods    //    // properties    /**     * Sets whether the DOM implementation performs error checking     * upon operations. Turning off error checking only affects     * the following DOM checks:     * <ul>     * <li>Checking strings to make sure that all characters are     *     legal XML characters     * <li>Hierarchy checking such as allowed children, checks for     *     cycles, etc.     * </ul>     * <p>     * Turning off error checking does <em>not</em> turn off the     * following checks:     * <ul>     * <li>Read only checks     * <li>Checks related to DOM events     * </ul>     */    public void setErrorChecking(boolean check) {        errorChecking = check;    }    /*     * DOM Level 3 WD - Experimental.     */    public void setStrictErrorChecking(boolean check) {        errorChecking = check;    }    /**     * Returns true if the DOM implementation performs error checking.     */    public boolean getErrorChecking() {        return errorChecking;    }    /*     * DOM Level 3 WD - Experimental.     */    public boolean getStrictErrorChecking() {        return errorChecking;    }    /**     * DOM Level 3 CR - Experimental. (Was getActualEncoding)     *     * An attribute specifying the encoding used for this document     * at the time of the parsing. This is <code>null</code> when     * it is not known, such as when the <code>Document</code> was     * created in memory.     * @since DOM Level 3     */    public String getInputEncoding() {        return actualEncoding;    }    /**     * DOM Internal     * (Was a DOM L3 Core WD public interface method setActualEncoding )     *     * An attribute specifying the actual encoding of this document. This is     * <code>null</code> otherwise.     * <br> This attribute represents the property [character encoding scheme]     * defined in .     */    public void setInputEncoding(String value) {        actualEncoding = value;    }    /**     * DOM Internal     * (Was a DOM L3 Core WD public interface method setXMLEncoding )     *     * An attribute specifying, as part of the XML declaration,     * the encoding of this document. This is null when unspecified.     */    public void setXmlEncoding(String value) {        encoding = value;    }        /**     * @deprecated This method is internal and only exists for     * compatibility with older applications. New applications     * should never call this method.     */    public void setEncoding(String value) {        setXmlEncoding(value);    }    /**     * DOM Level 3 WD - Experimental.     * The encoding of this document (part of XML Declaration)     */    public String getXmlEncoding() {        return encoding;    }        /**     * @deprecated This method is internal and only exists for     * compatibility with older applications. New applications     * should never call this method.     */    public String getEncoding() {        return getXmlEncoding();    }    /**     * DOM Level 3 CR - Experimental.     * version - An attribute specifying, as part of the XML declaration,     * the version number of this document.     */    public void setXmlVersion(String value) {        if(value.equals("1.0") || value.equals("1.1")){            //we need to change the flag value only --            // when the version set is different than already set.            if(!getXmlVersion().equals(value)){                xmlVersionChanged = true ;                //change the normalization value back to false                isNormalized(false);                version = value;            }        }        else{            //NOT_SUPPORTED_ERR: Raised if the vesion is set to a value that is not supported by            //this document            //we dont support any other XML version            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_SUPPORTED_ERR", null);            throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);        }        if((getXmlVersion()).equals("1.1")){            xml11Version = true;        }        else{            xml11Version = false;        }    }        /**     * @deprecated This method is internal and only exists for     * compatibility with older applications. New applications     * should never call this method.     */    public void setVersion(String value) {        setXmlVersion(value);    }    /**     * DOM Level 3 WD - Experimental.     * The version of this document (part of XML Declaration)     */    public String getXmlVersion() {        return (version == null)?"1.0":version;    }        /**     * @deprecated This method is internal and only exists for     * compatibility with older applications. New applications     * should never call this method.     */    public String getVersion() {        return getXmlVersion();    }    /**     * DOM Level 3 CR - Experimental.     *     * Xmlstandalone - An attribute specifying, as part of the XML declaration,     * whether this document is standalone     * @exception DOMException     *    NOT_SUPPORTED_ERR: Raised if this document does not support the     *   "XML" feature.     * @since DOM Level 3     */    public void setXmlStandalone(boolean value)                                  throws DOMException {            standalone = value;    }        /**     * @deprecated This method is internal and only exists for     * compatibility with older applications. New applications     * should never call this method.     */    public void setStandalone(boolean value) {        setXmlStandalone(value);    }    /**     * DOM Level 3 WD - Experimental.     * standalone that specifies whether this document is standalone     * (part of XML Declaration)     */    public boolean getXmlStandalone() {        return standalone;    }        /**     * @deprecated This method is internal and only exists for     * compatibility with older applications. New applications     * should never call this method.     */    public boolean getStandalone() {        return getXmlStandalone();    }    /**     * DOM Level 3 WD - Experimental.     * The location of the document or <code>null</code> if undefined.     * <br>Beware that when the <code>Document</code> supports the feature     * "HTML" , the href attribute of the HTML BASE element takes precedence     * over this attribute.     * @since DOM Level 3     */    public String getDocumentURI(){        return fDocumentURI;    }    /**     * DOM Level 3 WD - Experimental.     * Renaming node     */    public Node renameNode(Node n,String namespaceURI,String name)    throws DOMException{                if (errorChecking && n.getOwnerDocument() != this && n != this) {            String msg = DOMMessageFormatter.formatMessage(                    DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);            throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);        }        switch (n.getNodeType()) {            case ELEMENT_NODE: {                ElementImpl el = (ElementImpl) n;                if (el instanceof ElementNSImpl) {                    ((ElementNSImpl) el).rename(namespaceURI, name);                                        // fire user data NODE_RENAMED event                    callUserDataHandlers(el, null, UserDataHandler.NODE_RENAMED);                }                else {                    if (namespaceURI == null) {                        if (errorChecking) {                            int colon1 = name.indexOf(':');                            if(colon1 != -1){                                String msg =                                    DOMMessageFormatter.formatMessage(                                            DOMMessageFormatter.DOM_DOMAIN,                                            "NAMESPACE_ERR",                                            null);                                throw new DOMException(DOMException.NAMESPACE_ERR, msg);                            }                            if (!isXMLName(name,xml11Version)) {                                String msg = DOMMessageFormatter.formatMessage(                                        DOMMessageFormatter.DOM_DOMAIN,                                        "INVALID_CHARACTER_ERR", null);                                throw new DOMException(DOMException.INVALID_CHARACTER_ERR,                                        msg);                            }                        }                        el.rename(name);                                                // fire user data NODE_RENAMED event                        callUserDataHandlers(el, null,                                UserDataHandler.NODE_RENAMED);                    }                    else {                        // we need to create a new object                        ElementNSImpl nel =                            new ElementNSImpl(this, namespaceURI, name);                                                // register event listeners on new node                        copyEventListeners(el, nel);                                                // remove user data from old node                        Hashtable data = removeUserDataTable(el);                                                // remove old node from parent if any                        Node parent = el.getParentNode();                        Node nextSib = el.getNextSibling();                        if (parent != null) {                            parent.removeChild(el);                        }                        // move children to new node                        Node child = el.getFirstChild();                        while (child != null) {                            el.removeChild(child);                            nel.appendChild(child);                            child = el.getFirstChild();                        }                        // move specified attributes to new node                        nel.moveSpecifiedAttributes(el);                                                // attach user data to new node                        setUserDataTable(nel, data);                                                // and fire user data NODE_RENAMED event                        callUserDataHandlers(el, nel,                                UserDataHandler.NODE_RENAMED);                                                // insert new node where old one was                        if (parent != null) {                            parent.insertBefore(nel, nextSib);                        }                        el = nel;                    }                }                // fire ElementNameChanged event                renamedElement((Element) n, el);                return el;            }            case ATTRIBUTE_NODE: {                AttrImpl at = (AttrImpl) n;                                // dettach attr from element                Element el = at.getOwnerElement();                if (el != null) {                    el.removeAttributeNode(at);                }                if (n instanceof AttrNSImpl) {                    ((AttrNSImpl) at).rename(namespaceURI, name);                    // reattach attr to element                    if (el != null) {                        el.setAttributeNodeNS(at);                    }                                        // fire user data NODE_RENAMED event                    callUserDataHandlers(at, null, UserDataHandler.NODE_RENAMED);                }                else {                    if (namespaceURI == null) {                        at.rename(name);                        // reattach attr to element                        if (el != null) {                            el.setAttributeNode(at);

⌨️ 快捷键说明

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