documentimpl.java

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

JAVA
1,302
字号
/* * Copyright 2001,2002,2004,2005 The Apache Software Foundation. *  * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *  *      http://www.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.sun.org.apache.xerces.internal.dom;import java.io.Serializable;import java.util.Hashtable;import java.util.Vector;import com.sun.org.apache.xerces.internal.dom.events.EventImpl;import com.sun.org.apache.xerces.internal.dom.events.MutationEventImpl;import org.w3c.dom.UserDataHandler;import org.w3c.dom.Attr;import org.w3c.dom.DOMException;import org.w3c.dom.DOMImplementation;import org.w3c.dom.DocumentType;import org.w3c.dom.Element;import org.w3c.dom.NamedNodeMap;import org.w3c.dom.Node;import org.w3c.dom.events.DocumentEvent;import org.w3c.dom.events.Event;import org.w3c.dom.events.EventException;import org.w3c.dom.events.EventListener;import org.w3c.dom.events.MutationEvent;import org.w3c.dom.ranges.DocumentRange;import org.w3c.dom.ranges.Range;import org.w3c.dom.traversal.DocumentTraversal;import org.w3c.dom.traversal.NodeFilter;import org.w3c.dom.traversal.NodeIterator;import org.w3c.dom.traversal.TreeWalker;/** * The Document interface represents the entire HTML or XML document. * Conceptually, it is the root of the document tree, and provides the * primary access to the document's data. * <P> * Since elements, text nodes, comments, processing instructions, * etc. cannot exist outside the context of a Document, the Document * interface also contains the factory methods needed to create these * objects. The Node objects created have a ownerDocument attribute * which associates them with the Document within whose context they * were created. * <p> * The DocumentImpl class also implements the DOM Level 2 DocumentTraversal * interface. This interface is comprised of factory methods needed to * create NodeIterators and TreeWalkers. The process of creating NodeIterator * objects also adds these references to this document. * After finishing with an iterator it is important to remove the object * using the remove methods in this implementation. This allows the release of * the references from the iterator objects to the DOM Nodes. * <p> * <b>Note:</b> When any node in the document is serialized, the * entire document is serialized along with it. *  * @xerces.internal * * @author Arnaud  Le Hors, IBM * @author Joe Kesselman, IBM * @author Andy Clark, IBM * @author Ralf Pfeiffer, IBM * @version $Id: DocumentImpl.java,v 1.2.6.1 2005/08/31 10:49:17 sunithareddy Exp $ * @since  PR-DOM-Level-1-19980818. */public class DocumentImpl    extends CoreDocumentImpl    implements DocumentTraversal, DocumentEvent, DocumentRange {    //    // Constants    //    /** Serialization version. */    static final long serialVersionUID = 515687835542616694L;    //    // Data    //    /** Iterators */    // REVISIT: Should this be transient? -Ac    protected Vector iterators;     /** Ranges */    // REVISIT: Should this be transient? -Ac    protected Vector ranges;    /** Table for event listeners registered to this document nodes. */    protected Hashtable eventListeners;    /** Bypass mutation events firing. */    protected boolean mutationEvents = false;    //    // Constructors    //    /**     * NON-DOM: Actually creating a Document is outside the DOM's spec,     * since it has to operate in terms of a particular implementation.     */    public DocumentImpl() {        super();    }    /** Constructor. */    public DocumentImpl(boolean grammarAccess) {        super(grammarAccess);    }    /**     * For DOM2 support.     * The createDocument factory method is in DOMImplementation.     */    public DocumentImpl(DocumentType doctype)    {        super(doctype);    }    /** For DOM2 support. */    public DocumentImpl(DocumentType doctype, boolean grammarAccess) {        super(doctype, grammarAccess);    }    //    // Node methods    //    /**     * Deep-clone a document, including fixing ownerDoc for the cloned     * children. Note that this requires bypassing the WRONG_DOCUMENT_ERR     * protection. I've chosen to implement it by calling importNode     * which is DOM Level 2.     *     * @return org.w3c.dom.Node     * @param deep boolean, iff true replicate children     */    public Node cloneNode(boolean deep) {        DocumentImpl newdoc = new DocumentImpl();        callUserDataHandlers(this, newdoc, UserDataHandler.NODE_CLONED);        cloneNode(newdoc, deep);        // experimental        newdoc.mutationEvents = mutationEvents;    	return newdoc;    } // cloneNode(boolean):Node    /**     * 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 DOMImplementationImpl.getDOMImplementation();    }    //    // DocumentTraversal methods    //    /**     * NON-DOM extension:     * Create and return a NodeIterator. The NodeIterator is     * added to a list of NodeIterators so that it can be     * removed to free up the DOM Nodes it references.     *     * @param root The root of the iterator.     * @param whatToShow The whatToShow mask.     * @param filter The NodeFilter installed. Null means no filter.     */    public NodeIterator createNodeIterator(Node root,                                           short whatToShow,                                           NodeFilter filter)    {        return createNodeIterator(root, whatToShow, filter, true);    }    /**     * Create and return a NodeIterator. The NodeIterator is     * added to a list of NodeIterators so that it can be     * removed to free up the DOM Nodes it references.     *     * @param root The root of the iterator.     * @param whatToShow The whatToShow mask.     * @param filter The NodeFilter installed. Null means no filter.     * @param entityReferenceExpansion true to expand the contents of     *                                 EntityReference nodes     * @since WD-DOM-Level-2-19990923     */    public NodeIterator createNodeIterator(Node root,                                           int whatToShow,                                           NodeFilter filter,                                           boolean entityReferenceExpansion)    {                if (root == null) {                  String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_SUPPORTED_ERR", null);                  throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);        }        NodeIterator iterator = new NodeIteratorImpl(this,                                                     root,                                                     whatToShow,                                                     filter,                                                     entityReferenceExpansion);        if (iterators == null) {            iterators = new Vector();        }        iterators.addElement(iterator);        return iterator;    }    /**     * NON-DOM extension:     * Create and return a TreeWalker.     *     * @param root The root of the iterator.     * @param whatToShow The whatToShow mask.     * @param filter The NodeFilter installed. Null means no filter.     */    public TreeWalker createTreeWalker(Node root,                                       short whatToShow,                                       NodeFilter filter)    {        return createTreeWalker(root, whatToShow, filter, true);    }    /**     * Create and return a TreeWalker.     *     * @param root The root of the iterator.     * @param whatToShow The whatToShow mask.     * @param filter The NodeFilter installed. Null means no filter.     * @param entityReferenceExpansion true to expand the contents of     *                                 EntityReference nodes     * @since WD-DOM-Level-2-19990923     */    public TreeWalker createTreeWalker(Node root,                                       int whatToShow,                                       NodeFilter filter,                                       boolean entityReferenceExpansion)    {    	if (root == null) {            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_SUPPORTED_ERR", null);            throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);        }        return new TreeWalkerImpl(root, whatToShow, filter,                                  entityReferenceExpansion);    }    //    // Not DOM Level 2. Support DocumentTraversal methods.    //    /** This is not called by the developer client. The     *  developer client uses the detach() function on the     *  NodeIterator itself. <p>     *     *  This function is called from the NodeIterator#detach().     */     void removeNodeIterator(NodeIterator nodeIterator) {        if (nodeIterator == null) return;        if (iterators == null) return;        iterators.removeElement(nodeIterator);    }    //    // DocumentRange methods    //    /**     */    public Range createRange() {        if (ranges == null) {            ranges = new Vector();        }        Range range = new RangeImpl(this);        ranges.addElement(range);        return range;    }    /** Not a client function. Called by Range.detach(),     *  so a Range can remove itself from the list of     *  Ranges.     */    void removeRange(Range range) {        if (range == null) return;        if (ranges == null) return;        ranges.removeElement(range);    }    /**     * A method to be called when some text was changed in a text node,     * so that live objects can be notified.     */    void replacedText(NodeImpl node) {        // notify ranges        if (ranges != null) {

⌨️ 快捷键说明

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