basicparserconfiguration.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 628 行 · 第 1/2 页
JAVA
628 行
/* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001-2004 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.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.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.XNIException;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.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.XMLParserConfiguration;/** * A very basic parser configuration. This configuration class can * be used as a base class for custom parser configurations. The * basic parser configuration creates the symbol table (if not * specified at construction time) and manages all of the recognized * features and properties. * <p> * The basic parser configuration does <strong>not</strong> mandate * any particular pipeline configuration or the use of specific * components except for the symbol table. If even this is too much * for a basic parser configuration, the programmer can create a new * configuration class that implements the * <code>XMLParserConfiguration</code> interface. * <p> * Subclasses of the basic parser configuration can add their own * recognized features and properties by calling the * <code>addRecognizedFeature</code> and * <code>addRecognizedProperty</code> methods, respectively. * <p> * The basic parser configuration assumes that the configuration * will be made up of various parser components that implement the * <code>XMLComponent</code> interface. If subclasses of this * configuration create their own components for use in the * parser configuration, then each component should be added to * the list of components by calling the <code>addComponent</code> * method. The basic parser configuration will make sure to call * the <code>reset</code> method of each registered component * before parsing an instance document. * <p> * This class recognizes the following features and properties: * <ul> * <li>Features * <ul> * <li>http://xml.org/sax/features/validation</li> * <li>http://xml.org/sax/features/namespaces</li> * <li>http://xml.org/sax/features/external-general-entities</li> * <li>http://xml.org/sax/features/external-parameter-entities</li> * </ul> * <li>Properties * <ul> * <li>http://xml.org/sax/properties/xml-string</li> * <li>http://apache.org/xml/properties/internal/symbol-table</li> * <li>http://apache.org/xml/properties/internal/error-handler</li> * <li>http://apache.org/xml/properties/internal/entity-resolver</li> * </ul> * </ul> * * @author Arnaud Le Hors, IBM * @author Andy Clark, IBM * * @version $Id: BasicParserConfiguration.java,v 1.24 2004/04/12 21:56:02 mrglavas Exp $ */public abstract class BasicParserConfiguration extends ParserConfigurationSettings implements XMLParserConfiguration { // // Constants // // 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; // 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; // // Data // // components (non-configurable) /** Symbol table. */ protected SymbolTable fSymbolTable; // data /** Locale. */ protected Locale fLocale; /** Components. */ protected ArrayList fComponents; // handlers /** 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; // // Constructors // /** Default Constructor. */ protected BasicParserConfiguration() { this(null, null); } // <init>() /** * Constructs a parser configuration using the specified symbol table. * * @param symbolTable The symbol table to use. */ protected BasicParserConfiguration(SymbolTable symbolTable) { this(symbolTable, null); } // <init>(SymbolTable) /** * Constructs a parser configuration using the specified symbol table * and parent settings. * * @param symbolTable The symbol table to use. * @param parentSettings The parent settings. */ protected BasicParserConfiguration(SymbolTable symbolTable, XMLComponentManager parentSettings) { super(parentSettings); // create a vector to hold all the components in use fComponents = 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 = { PARSER_SETTINGS, VALIDATION, NAMESPACES, EXTERNAL_GENERAL_ENTITIES, EXTERNAL_PARAMETER_ENTITIES, }; addRecognizedFeatures(recognizedFeatures); fFeatures.put(PARSER_SETTINGS, Boolean.TRUE); // 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); // add default recognized properties final String[] recognizedProperties = { XML_STRING, SYMBOL_TABLE, ERROR_HANDLER, ENTITY_RESOLVER, }; addRecognizedProperties(recognizedProperties); if (symbolTable == null) { symbolTable = new SymbolTable(); } fSymbolTable = symbolTable; fProperties.put(SYMBOL_TABLE, fSymbolTable); } // <init>(SymbolTable) /** * Adds a component to the parser configuration. This method will * also add all of the component's recognized features and properties * to the list of default recognized features and properties. * * @param component The component to add. */ protected void addComponent(XMLComponent component) { // don't add a component more than once if (fComponents.contains(component)) { return; } fComponents.add(component); // register component's recognized features String[] recognizedFeatures = component.getRecognizedFeatures(); addRecognizedFeatures(recognizedFeatures); // register component's recognized properties String[] recognizedProperties = component.getRecognizedProperties(); addRecognizedProperties(recognizedProperties); // set default values if (recognizedFeatures != null) { for (int i = 0; i < recognizedFeatures.length; i++) { String featureId = recognizedFeatures[i]; Boolean state = component.getFeatureDefault(featureId); if (state != null) { super.setFeature(featureId, state.booleanValue()); } } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?