📄 xmldocumentscannerimpl.java
字号:
/* * The contents of this file are subject to the terms * of the Common Development and Distribution License * (the "License"). You may not use this file except * in compliance with the License. * * You can obtain a copy of the license at * https://jaxp.dev.java.net/CDDLv1.0.html. * See the License for the specific language governing * permissions and limitations under the License. * * When distributing Covered Code, include this CDDL * HEADER in each file and include the License file at * https://jaxp.dev.java.net/CDDLv1.0.html * If applicable add the following below this CDDL HEADER * with the fields enclosed by brackets "[]" replaced with * your own identifying information: Portions Copyright * [year] [name of copyright owner] *//* * $Id: XMLDocumentScannerImpl.java,v 1.9 2007/05/09 15:23:31 ndw Exp $ * @(#)XMLDocumentScannerImpl.java 1.18 08/03/28 * * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. *//* * Copyright 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.impl;import com.sun.xml.internal.stream.Entity;import com.sun.xml.internal.stream.StaxXMLInputSource;import com.sun.xml.internal.stream.dtd.DTDGrammarUtil;import java.io.EOFException;import java.io.IOException;import javax.xml.stream.XMLInputFactory;import javax.xml.stream.events.XMLEvent;import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;import com.sun.org.apache.xerces.internal.util.NamespaceSupport;import com.sun.org.apache.xerces.internal.util.XMLChar;import com.sun.org.apache.xerces.internal.util.XMLResourceIdentifierImpl;import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;import com.sun.org.apache.xerces.internal.xni.NamespaceContext;import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;import com.sun.org.apache.xerces.internal.xni.XMLString;import com.sun.org.apache.xerces.internal.xni.XNIException;import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner;import com.sun.org.apache.xerces.internal.xni.Augmentations;import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDDescription;import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner;/** * This class is responsible for scanning XML document structure * and content. * * This class has been modified as per the new design which is more suited to * efficiently build pull parser. Lot of improvements have been done and * the code has been added to support stax functionality/features. * * @author Neeraj Bajaj, Sun Microsystems * @author K.Venugopal, Sun Microsystems * @author Glenn Marcy, IBM * @author Andy Clark, IBM * @author Arnaud Le Hors, IBM * @author Eric Ye, IBM * @author Sunitha Reddy, Sun Microsystems * * Refer to the table in unit-test javax.xml.stream.XMLStreamReaderTest.SupportDTD for changes * related to property SupportDTD. * @author Joe Wang, Sun Microsystems * @version $Id: XMLDocumentScannerImpl.java,v 1.9 2007/05/09 15:23:31 ndw Exp $ */public class XMLDocumentScannerImpl extends XMLDocumentFragmentScannerImpl{ // // Constants // // scanner states /** Scanner state: XML declaration. */ protected static final int SCANNER_STATE_XML_DECL = 42; /** Scanner state: prolog. */ protected static final int SCANNER_STATE_PROLOG = 43; /** Scanner state: trailing misc. */ protected static final int SCANNER_STATE_TRAILING_MISC = 44; /** Scanner state: DTD internal declarations. */ protected static final int SCANNER_STATE_DTD_INTERNAL_DECLS = 45; /** Scanner state: open DTD external subset. */ protected static final int SCANNER_STATE_DTD_EXTERNAL = 46; /** Scanner state: DTD external declarations. */ protected static final int SCANNER_STATE_DTD_EXTERNAL_DECLS = 47; /** Scanner state: NO MORE ELEMENTS. */ protected static final int SCANNER_STATE_NO_SUCH_ELEMENT_EXCEPTION = 48; // feature identifiers /** Property identifier document scanner: */ protected static final String DOCUMENT_SCANNER = Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_SCANNER_PROPERTY; /** Feature identifier: load external DTD. */ protected static final String LOAD_EXTERNAL_DTD = Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE; /** Feature identifier: load external DTD. */ protected static final String DISALLOW_DOCTYPE_DECL_FEATURE = Constants.XERCES_FEATURE_PREFIX + Constants.DISALLOW_DOCTYPE_DECL_FEATURE; // property identifiers /** Property identifier: DTD scanner. */ protected static final String DTD_SCANNER = Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY; // property identifier: ValidationManager protected static final String VALIDATION_MANAGER = Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY; /** property identifier: NamespaceContext */ protected static final String NAMESPACE_CONTEXT = Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_CONTEXT_PROPERTY; // recognized features and properties /** Recognized features. */ private static final String[] RECOGNIZED_FEATURES = { LOAD_EXTERNAL_DTD, DISALLOW_DOCTYPE_DECL_FEATURE, }; /** Feature defaults. */ private static final Boolean[] FEATURE_DEFAULTS = { Boolean.TRUE, Boolean.FALSE, }; /** Recognized properties. */ private static final String[] RECOGNIZED_PROPERTIES = { DTD_SCANNER, VALIDATION_MANAGER }; /** Property defaults. */ private static final Object[] PROPERTY_DEFAULTS = { null, null }; // // Data((Boolean)propertyManager.getProperty(XMLInputFactory.IS_NAMESPACE_AWARE)).booleanValue(); // // properties /** DTD scanner. */ protected XMLDTDScanner fDTDScanner = null; /** Validation manager . */ //xxx: fValidationManager code needs to be added yet! protected ValidationManager fValidationManager; protected XMLStringBuffer fDTDDecl = null; protected boolean fReadingDTD = false; protected boolean fAddedListener = false; // protected data // other info /** Doctype name. */ protected String fDoctypeName; /** Doctype declaration public identifier. */ protected String fDoctypePublicId; /** Doctype declaration system identifier. */ protected String fDoctypeSystemId; /** Namespace support. */ protected NamespaceContext fNamespaceContext = new NamespaceSupport(); // features /** Load external DTD. */ protected boolean fLoadExternalDTD = true; // state /** Seen doctype declaration. */ protected boolean fSeenDoctypeDecl; protected boolean fScanEndElement; //protected int fScannerLastState ; // drivers /** XML declaration driver. */ protected Driver fXMLDeclDriver = new XMLDeclDriver(); /** Prolog driver. */ protected Driver fPrologDriver = new PrologDriver(); /** DTD driver. */ protected Driver fDTDDriver = null ; /** Trailing miscellaneous section driver. */ protected Driver fTrailingMiscDriver = new TrailingMiscDriver(); protected int fStartPos = 0; protected int fEndPos = 0; protected boolean fSeenInternalSubset= false; // temporary variables /** Array of 3 strings. */ private String[] fStrings = new String[3]; /** External subset source. */ private XMLInputSource fExternalSubsetSource = null; /** A DTD Description. */ private final XMLDTDDescription fDTDDescription = new XMLDTDDescription(null, null, null, null, null); /** String. */ private XMLString fString = new XMLString(); private static final char [] DOCTYPE = {'D','O','C','T','Y','P','E'}; private static final char [] COMMENTSTRING = {'-','-'}; // // Constructors // /** Default constructor. */ public XMLDocumentScannerImpl() {} // <init>() // // XMLDocumentScanner methods // /** * Sets the input source. * * @param inputSource The input source. * * @throws IOException Thrown on i/o error. */ public void setInputSource(XMLInputSource inputSource) throws IOException { fEntityManager.setEntityHandler(this); //this starts a new entity and sets the current entity to the document entity. fEntityManager.startDocumentEntity(inputSource); // fDocumentSystemId = fEntityManager.expandSystemId(inputSource.getSystemId()); setScannerState(XMLEvent.START_DOCUMENT); } // setInputSource(XMLInputSource) /**return the state of the scanner */ public int getScannetState(){ return fScannerState ; } public void reset(PropertyManager propertyManager) { super.reset(propertyManager); // other settings fDoctypeName = null; fDoctypePublicId = null; fDoctypeSystemId = null; fSeenDoctypeDecl = false; fNamespaceContext.reset(); fDisallowDoctype = !((Boolean)propertyManager.getProperty(XMLInputFactory.SUPPORT_DTD)).booleanValue(); // xerces features
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -