xmldocumentscannerimpl.java
来自「JAVA 所有包」· Java 代码 · 共 1,499 行 · 第 1/4 页
JAVA
1,499 行
/* * 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.5 2006/05/09 10:56:45 sunithareddy Exp $ * @(#)XMLDocumentScannerImpl.java 1.16 06/06/21 * * 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 * @version $Id: XMLDocumentScannerImpl.java,v 1.5 2006/05/09 10:56:45 sunithareddy 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; /** Disallow doctype declaration. */ protected boolean fDisallowDoctype = false; // 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(); public static final char [] DOCTYPE = {'D','O','C','T','Y','P','E'}; public 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 fLoadExternalDTD = true ; setScannerState(XMLEvent.START_DOCUMENT); setDriver(fXMLDeclDriver); fSeenInternalSubset = false; if(fDTDScanner != null){ ((XMLDTDScannerImpl)fDTDScanner).reset(propertyManager); } fEndPos = 0; fStartPos = 0; if(fDTDDecl != null){ fDTDDecl.clear(); } } /** * Resets the component. The component can query the component manager * about any features and properties that affect the operation of the * component. * * @param componentManager The component manager. * * @throws SAXException Thrown by component on initialization error. * For example, if a feature or property is * required for the operation of the component, the * component manager may throw a * SAXNotRecognizedException or a * SAXNotSupportedException. */ public void reset(XMLComponentManager componentManager) throws XMLConfigurationException { super.reset(componentManager); // other settings fDoctypeName = null; fDoctypePublicId = null; fDoctypeSystemId = null; fSeenDoctypeDecl = false; fExternalSubsetSource = null; // xerces features try { fLoadExternalDTD = componentManager.getFeature(LOAD_EXTERNAL_DTD); } catch (XMLConfigurationException e) { fLoadExternalDTD = true; } try { fDisallowDoctype = componentManager.getFeature(DISALLOW_DOCTYPE_DECL_FEATURE); } catch (XMLConfigurationException e) { fDisallowDoctype = false; } try { fNamespaces = componentManager.getFeature(NAMESPACES); } catch (XMLConfigurationException e) { fNamespaces = true; } fSeenInternalSubset = false; // xerces properties fDTDScanner = (XMLDTDScanner)componentManager.getProperty(DTD_SCANNER); try { fValidationManager = (ValidationManager)componentManager.getProperty(VALIDATION_MANAGER); } catch (XMLConfigurationException e) { fValidationManager = null; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?