xml11nonvalidatingconfiguration.java
来自「JAVA 所有包」· Java 代码 · 共 1,233 行 · 第 1/3 页
JAVA
1,233 行
/* * Copyright 2004 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.parsers;import java.io.IOException;import java.util.ArrayList;import java.util.HashMap;import java.util.Locale;import com.sun.org.apache.xerces.internal.impl.Constants;import com.sun.org.apache.xerces.internal.impl.XML11DTDScannerImpl;import com.sun.org.apache.xerces.internal.impl.XML11DocumentScannerImpl;import com.sun.org.apache.xerces.internal.impl.XML11NSDocumentScannerImpl;import com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl;import com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl;import com.sun.org.apache.xerces.internal.impl.XMLEntityHandler;import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;import com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl;import com.sun.org.apache.xerces.internal.impl.XMLVersionDetector;import com.sun.org.apache.xerces.internal.impl.dv.DTDDVFactory;import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;import com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings;import com.sun.org.apache.xerces.internal.util.SymbolTable;import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler;import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler;import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler;import com.sun.org.apache.xerces.internal.xni.XMLLocator;import com.sun.org.apache.xerces.internal.xni.XNIException;import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;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.parser.XMLDocumentScanner;import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource;import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver;import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler;import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration;/** * This class is the non vlaidating parser configuration * used to parse XML 1.0 and XML 1.1 documents. * * Xerces parser that uses this configuration is <strong>not</strong> <a href="http://www.w3.org/TR/REC-xml#sec-conformance">conformant</a> * non-validating XML processor, since conformant non-validating processor is required * to process "all the declarations they read in the internal DTD subset ... must use the information in those declarations to normalize attribute values, * include the replacement text of internal entities, and supply default attribute values". * @author Elena Litani, IBM * @author John Kim, IBM * @author Michael Glavassevich, IBM * * @version $Id: XML11NonValidatingConfiguration.java,v 1.1.2.1 2005/08/01 03:37:43 jeffsuttor Exp $ */public class XML11NonValidatingConfiguration extends ParserConfigurationSettings implements XMLPullParserConfiguration, XML11Configurable { // // Constants // protected final static String XML11_DATATYPE_VALIDATOR_FACTORY = "com.sun.org.apache.xerces.internal.impl.dv.dtd.XML11DTDDVFactoryImpl"; // feature identifiers /** Feature identifier: validation. */ protected static final String VALIDATION = Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE; /** Feature identifier: namespaces. */ protected static final String NAMESPACES = Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE; /** Feature identifier: external general entities. */ protected static final String EXTERNAL_GENERAL_ENTITIES = Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE; /** Feature identifier: external parameter entities. */ protected static final String EXTERNAL_PARAMETER_ENTITIES = Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE; /** Feature identifier: continue after fatal error. */ protected static final String CONTINUE_AFTER_FATAL_ERROR = Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE; // property identifiers /** Property identifier: xml string. */ protected static final String XML_STRING = Constants.SAX_PROPERTY_PREFIX + Constants.XML_STRING_PROPERTY; /** Property identifier: symbol table. */ protected static final String SYMBOL_TABLE = Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; /** Property identifier: error handler. */ protected static final String ERROR_HANDLER = Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY; /** Property identifier: entity resolver. */ protected static final String ENTITY_RESOLVER = Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY; /** Property identifier: error reporter. */ protected static final String ERROR_REPORTER = Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; /** Property identifier: entity manager. */ protected static final String ENTITY_MANAGER = Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY; /** Property identifier document scanner: */ protected static final String DOCUMENT_SCANNER = Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_SCANNER_PROPERTY; /** Property identifier: DTD scanner. */ protected static final String DTD_SCANNER = Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY; /** Property identifier: grammar pool. */ protected static final String XMLGRAMMAR_POOL = Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY; /** Property identifier: DTD validator. */ protected static final String DTD_VALIDATOR = Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_VALIDATOR_PROPERTY; /** Property identifier: namespace binder. */ protected static final String NAMESPACE_BINDER = Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_BINDER_PROPERTY; /** Property identifier: datatype validator factory. */ protected static final String DATATYPE_VALIDATOR_FACTORY = Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY; protected static final String VALIDATION_MANAGER = Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY; // debugging /** Set to true and recompile to print exception stack trace. */ protected static final boolean PRINT_EXCEPTION_STACK_TRACE = false; // // Data // protected SymbolTable fSymbolTable; protected XMLInputSource fInputSource; protected ValidationManager fValidationManager; protected XMLVersionDetector fVersionDetector; protected XMLLocator fLocator; protected Locale fLocale; /** XML 1.0 Components. */ protected ArrayList fComponents; /** XML 1.1. Components. */ protected ArrayList fXML11Components = null; /** Common components: XMLEntityManager, XMLErrorReporter */ protected ArrayList fCommonComponents = null; /** The document handler. */ protected XMLDocumentHandler fDocumentHandler; /** The DTD handler. */ protected XMLDTDHandler fDTDHandler; /** The DTD content model handler. */ protected XMLDTDContentModelHandler fDTDContentModelHandler; /** Last component in the document pipeline */ protected XMLDocumentSource fLastComponent; /** * True if a parse is in progress. This state is needed because * some features/properties cannot be set while parsing (e.g. * namespaces). */ protected boolean fParseInProgress = false; /** fConfigUpdated is set to true if there has been any change to the configuration settings, * i.e a feature or a property was changed. */ protected boolean fConfigUpdated = false; // // XML 1.0 components // /** The XML 1.0 Datatype validator factory. */ protected DTDDVFactory fDatatypeValidatorFactory; /** The XML 1.0 Document scanner that does namespace binding. */ protected XMLNSDocumentScannerImpl fNamespaceScanner; /** The XML 1.0 Non-namespace implementation of scanner */ protected XMLDocumentScannerImpl fNonNSScanner; /** The XML 1.0 DTD scanner. */ protected XMLDTDScanner fDTDScanner; // // XML 1.1 components // /** The XML 1.1 datatype factory. **/ protected DTDDVFactory fXML11DatatypeFactory = null; /** The XML 1.1 document scanner that does namespace binding. **/ protected XML11NSDocumentScannerImpl fXML11NSDocScanner = null; /** The XML 1.1 document scanner that does not do namespace binding. **/ protected XML11DocumentScannerImpl fXML11DocScanner = null; /** The XML 1.1 DTD scanner. **/ protected XML11DTDScannerImpl fXML11DTDScanner = null; // // Common components // /** Grammar pool. */ protected XMLGrammarPool fGrammarPool; /** Error reporter. */ protected XMLErrorReporter fErrorReporter; /** Entity manager. */ protected XMLEntityManager fEntityManager; /** Current scanner */ protected XMLDocumentScanner fCurrentScanner; /** Current Datatype validator factory. */ protected DTDDVFactory fCurrentDVFactory; /** Current DTD scanner. */ protected XMLDTDScanner fCurrentDTDScanner; /** Flag indiciating whether XML11 components have been initialized. */ private boolean f11Initialized = false; // // Constructors // /** Default constructor. */ public XML11NonValidatingConfiguration() { this(null, null, null); } // <init>() /** * Constructs a parser configuration using the specified symbol table. * * @param symbolTable The symbol table to use. */ public XML11NonValidatingConfiguration(SymbolTable symbolTable) { this(symbolTable, null, null); } // <init>(SymbolTable) /** * Constructs a parser configuration using the specified symbol table and * grammar pool. * <p> * <strong>REVISIT:</strong> * Grammar pool will be updated when the new validation engine is * implemented. * * @param symbolTable The symbol table to use. * @param grammarPool The grammar pool to use. */ public XML11NonValidatingConfiguration(SymbolTable symbolTable, XMLGrammarPool grammarPool) { this(symbolTable, grammarPool, null); } // <init>(SymbolTable,XMLGrammarPool) /** * Constructs a parser configuration using the specified symbol table, * grammar pool, and parent settings. * <p> * <strong>REVISIT:</strong> * Grammar pool will be updated when the new validation engine is * implemented. * * @param symbolTable The symbol table to use. * @param grammarPool The grammar pool to use. * @param parentSettings The parent settings. */ public XML11NonValidatingConfiguration( SymbolTable symbolTable, XMLGrammarPool grammarPool, XMLComponentManager parentSettings) { super(parentSettings); // create a vector to hold all the components in use // XML 1.0 specialized components fComponents = new ArrayList(); // XML 1.1 specialized components fXML11Components = new ArrayList(); // Common components for XML 1.1. and XML 1.0 fCommonComponents = new ArrayList(); // create storage for recognized features and properties fRecognizedFeatures = new ArrayList(); fRecognizedProperties = new ArrayList(); // create table for features and properties fFeatures = new HashMap(); fProperties = new HashMap(); // add default recognized features final String[] recognizedFeatures = { CONTINUE_AFTER_FATAL_ERROR, // from XMLDTDScannerImpl VALIDATION, NAMESPACES, EXTERNAL_GENERAL_ENTITIES, EXTERNAL_PARAMETER_ENTITIES, PARSER_SETTINGS }; addRecognizedFeatures(recognizedFeatures); // set state for default features fFeatures.put(VALIDATION, Boolean.FALSE); fFeatures.put(NAMESPACES, Boolean.TRUE); fFeatures.put(EXTERNAL_GENERAL_ENTITIES, Boolean.TRUE); fFeatures.put(EXTERNAL_PARAMETER_ENTITIES, Boolean.TRUE); fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE); fFeatures.put(PARSER_SETTINGS, Boolean.TRUE); // add default recognized properties final String[] recognizedProperties = { XML_STRING, SYMBOL_TABLE, ERROR_HANDLER, ENTITY_RESOLVER, ERROR_REPORTER, ENTITY_MANAGER, DOCUMENT_SCANNER, DTD_SCANNER, DTD_VALIDATOR, DATATYPE_VALIDATOR_FACTORY, VALIDATION_MANAGER, XML_STRING, XMLGRAMMAR_POOL, }; addRecognizedProperties(recognizedProperties); if (symbolTable == null) { symbolTable = new SymbolTable(); } fSymbolTable = symbolTable; fProperties.put(SYMBOL_TABLE, fSymbolTable); fGrammarPool = grammarPool; if (fGrammarPool != null) { fProperties.put(XMLGRAMMAR_POOL, fGrammarPool); } fEntityManager = new XMLEntityManager(); fProperties.put(ENTITY_MANAGER, fEntityManager); addCommonComponent(fEntityManager); fErrorReporter = new XMLErrorReporter(); fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner()); fProperties.put(ERROR_REPORTER, fErrorReporter); addCommonComponent(fErrorReporter); fNamespaceScanner = new XMLNSDocumentScannerImpl(); fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner); addComponent((XMLComponent) fNamespaceScanner); fDTDScanner = new XMLDTDScannerImpl(); fProperties.put(DTD_SCANNER, fDTDScanner); addComponent((XMLComponent) fDTDScanner); fDatatypeValidatorFactory = DTDDVFactory.getInstance(); fProperties.put(DATATYPE_VALIDATOR_FACTORY, fDatatypeValidatorFactory); fValidationManager = new ValidationManager(); fProperties.put(VALIDATION_MANAGER, fValidationManager); fVersionDetector = new XMLVersionDetector(); // add message formatters if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) { XMLMessageFormatter xmft = new XMLMessageFormatter(); fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft); fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?