domconfigurationimpl.java

来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,118 行 · 第 1/3 页

JAVA
1,118
字号
/* * 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.dom;import java.io.IOException;import java.util.ArrayList;import java.util.HashMap;import java.util.Locale;import java.util.Vector;import org.w3c.dom.DOMConfiguration;import org.w3c.dom.DOMErrorHandler;import org.w3c.dom.DOMStringList;import com.sun.org.apache.xerces.internal.impl.Constants;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.msg.XMLMessageFormatter;import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;import com.sun.org.apache.xerces.internal.util.DOMEntityResolverWrapper;import com.sun.org.apache.xerces.internal.util.DOMErrorHandlerWrapper;import com.sun.org.apache.xerces.internal.util.MessageFormatter;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.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.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;import org.w3c.dom.DOMException;import org.w3c.dom.ls.LSResourceResolver;import com.sun.org.apache.xerces.internal.impl.dv.DTDDVFactory;/** * Xerces implementation of DOMConfiguration that maintains a table of recognized parameters. * * @author Elena Litani, IBM * @author Neeraj Bajaj, Sun Microsystems. * @version $Id: DOMConfigurationImpl.java,v 1.28 2004/04/14 15:54:06 mrglavas Exp $ */public class DOMConfigurationImpl extends ParserConfigurationSettings    implements XMLParserConfiguration, DOMConfiguration {    //    // Constants    //    // feature identifiers    /** Feature identifier: validation. */    protected static final String XERCES_VALIDATION =        Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;    /** Feature identifier: namespaces. */    protected static final String XERCES_NAMESPACES =        Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;    protected static final String SCHEMA =        Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE;    protected static final String DYNAMIC_VALIDATION =        Constants.XERCES_FEATURE_PREFIX + Constants.DYNAMIC_VALIDATION_FEATURE;    protected static final String NORMALIZE_DATA =        Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE;    protected static final String DATATYPE_VALIDATOR_FACTORY =         Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY;    /** sending psvi in the pipeline */    protected static final String SEND_PSVI =        Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI;    // property identifiers    /** Property identifier: entity manager. */    protected static final String ENTITY_MANAGER =        Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;    /** Property identifier: error reporter. */    protected static final String ERROR_REPORTER =        Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;    /** 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 id: Grammar pool*/    protected static final String GRAMMAR_POOL =    Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_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: JAXP schema language / DOM schema-type. */    protected static final String JAXP_SCHEMA_LANGUAGE =    Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE;    /** Property identifier: JAXP schema source/ DOM schema-location. */    protected static final String JAXP_SCHEMA_SOURCE =    Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE;    protected static final String VALIDATION_MANAGER =        Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;    //    // Data    //    XMLDocumentHandler fDocumentHandler;    /** Normalization features*/    protected short features = 0;    protected final static short NAMESPACES          = 0x1<<0;    protected final static short DTNORMALIZATION     = 0x1<<1;    protected final static short ENTITIES            = 0x1<<2;    protected final static short CDATA               = 0x1<<3;    protected final static short SPLITCDATA          = 0x1<<4;    protected final static short COMMENTS            = 0x1<<5;    protected final static short VALIDATE            = 0x1<<6;    protected final static short PSVI                = 0x1<<7;    protected final static short WELLFORMED          = 0x1<<8;    protected final static short INFOSET_TRUE_PARAMS = NAMESPACES | COMMENTS | WELLFORMED;    protected final static short INFOSET_FALSE_PARAMS = ENTITIES | DTNORMALIZATION | CDATA;    protected final static short INFOSET_MASK = INFOSET_TRUE_PARAMS | INFOSET_FALSE_PARAMS;    // components    /** Symbol table. */    protected SymbolTable fSymbolTable;    protected DTDDVFactory fDatatypeValidatorFactory;    /** Components. */    protected ArrayList fComponents;    protected ValidationManager fValidationManager;    /** Locale. */    protected Locale fLocale;    /** Error reporter */    protected XMLErrorReporter fErrorReporter;    protected final DOMErrorHandlerWrapper fErrorHandlerWrapper =                new DOMErrorHandlerWrapper();    // private data    private DOMStringList fRecognizedParameters;    //    // Constructors    //    /** Default Constructor. */    protected DOMConfigurationImpl() {        this(null, null);    } // <init>()    /**     * Constructs a parser configuration using the specified symbol table.     *     * @param symbolTable The symbol table to use.     */    protected DOMConfigurationImpl(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 DOMConfigurationImpl(SymbolTable symbolTable,                                    XMLComponentManager parentSettings) {        super(parentSettings);        // 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 = {            XERCES_VALIDATION,            XERCES_NAMESPACES,            SCHEMA,            DYNAMIC_VALIDATION,            NORMALIZE_DATA,            SEND_PSVI,        };        addRecognizedFeatures(recognizedFeatures);        // set state for default features        setFeature(XERCES_VALIDATION, false);        setFeature(SCHEMA, false);        setFeature(DYNAMIC_VALIDATION, false);        setFeature(NORMALIZE_DATA, false);        setFeature(XERCES_NAMESPACES, true);        setFeature(SEND_PSVI, true);        // add default recognized properties        final String[] recognizedProperties = {            XML_STRING,            SYMBOL_TABLE,            ERROR_HANDLER,            ENTITY_RESOLVER,            ERROR_REPORTER,            ENTITY_MANAGER,            VALIDATION_MANAGER,            DATATYPE_VALIDATOR_FACTORY,            GRAMMAR_POOL,            JAXP_SCHEMA_SOURCE,            JAXP_SCHEMA_LANGUAGE        };        addRecognizedProperties(recognizedProperties);        // set default values for normalization features        features |= NAMESPACES;        features |= ENTITIES;        features |= COMMENTS;        features |= CDATA;        features |= SPLITCDATA;        features |=  WELLFORMED;        if (symbolTable == null) {            symbolTable = new SymbolTable();        }        fSymbolTable = symbolTable;        fComponents = new ArrayList();        setProperty(SYMBOL_TABLE, fSymbolTable);        fErrorReporter = new XMLErrorReporter();        setProperty(ERROR_REPORTER, fErrorReporter);        addComponent(fErrorReporter);        XMLEntityManager manager =  new XMLEntityManager();        setProperty(ENTITY_MANAGER, manager);        addComponent(manager);        fValidationManager = createValidationManager();        setProperty(VALIDATION_MANAGER, fValidationManager);        fDatatypeValidatorFactory = createDatatypeValidatorFactory();        if (fDatatypeValidatorFactory != null) {            setProperty(DATATYPE_VALIDATOR_FACTORY,                        fDatatypeValidatorFactory);        }        // 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);        }        // REVISIT: try to include XML Schema formatter.        //          This is a hack to allow DTD configuration to be build.        //        if (fErrorReporter.getMessageFormatter("http://www.w3.org/TR/xml-schema-1") == null) {            MessageFormatter xmft = null;            try {               xmft = (MessageFormatter)(                    ObjectFactory.newInstance("com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter",                    ObjectFactory.findClassLoader(), true));            } catch (Exception exception){            }             if (xmft !=  null) {                 fErrorReporter.putMessageFormatter("http://www.w3.org/TR/xml-schema-1", xmft);             }        }        // set locale        try {            setLocale(Locale.getDefault());        }        catch (XNIException e) {            // do nothing            // REVISIT: What is the right thing to do? -Ac        }    } // <init>(SymbolTable)    //    // XMLParserConfiguration methods    //    /**     * Parse an XML document.     * <p>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?