documentimpl.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,275 行 · 第 1/4 页
JAVA
1,275 行
/* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001, 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Xerces" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation and was * originally based on software copyright (c) 1999, International * Business Machines, Inc., http://www.apache.org. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */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. * * @author Arnaud Le Hors, IBM * @author Joe Kesselman, IBM * @author Andy Clark, IBM * @author Ralf Pfeiffer, IBM * @version $Id: DocumentImpl.java,v 1.78 2003/07/29 18:24:05 elena 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(). */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?