domconfigurationimpl.java
来自「JAVA 所有包」· Java 代码 · 共 1,073 行 · 第 1/3 页
JAVA
1,073 行
/* * Copyright 2001-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.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.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.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;/** * Xerces implementation of DOMConfiguration that maintains a table of recognized parameters. * * @xerces.internal * * @author Elena Litani, IBM * @author Neeraj Bajaj, Sun Microsystems. * @version $Id: DOMConfigurationImpl.java,v 1.2.6.1 2005/08/30 13:08:25 sunithareddy 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 SCHEMA_FULL_CHECKING = Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_FULL_CHECKING; 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; /** sending psvi in the pipeline */ protected static final String SEND_PSVI = Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI; protected final static String DTD_VALIDATOR_FACTORY_PROPERTY = Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY; // 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 NSDECL = 0x1<<9; protected final static short INFOSET_TRUE_PARAMS = NAMESPACES | COMMENTS | WELLFORMED | NSDECL; 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; /** 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, SCHEMA_FULL_CHECKING, DYNAMIC_VALIDATION, NORMALIZE_DATA, SEND_PSVI, }; addRecognizedFeatures(recognizedFeatures); // set state for default features setFeature(XERCES_VALIDATION, false); setFeature(SCHEMA, false); setFeature(SCHEMA_FULL_CHECKING, 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, GRAMMAR_POOL, JAXP_SCHEMA_SOURCE, JAXP_SCHEMA_LANGUAGE, DTD_VALIDATOR_FACTORY_PROPERTY }; addRecognizedProperties(recognizedProperties); // set default values for normalization features features |= NAMESPACES; features |= ENTITIES; features |= COMMENTS; features |= CDATA; features |= SPLITCDATA; features |= WELLFORMED; features |= NSDECL; if (symbolTable == null) { symbolTable = new SymbolTable(); } fSymbolTable = symbolTable; fComponents = new ArrayList(); setProperty(SYMBOL_TABLE, fSymbolTable); fErrorReporter = new XMLErrorReporter(); setProperty(ERROR_REPORTER, fErrorReporter); addComponent(fErrorReporter); setProperty(DTD_VALIDATOR_FACTORY_PROPERTY, DTDDVFactory.getInstance()); XMLEntityManager manager = new XMLEntityManager(); setProperty(ENTITY_MANAGER, manager); addComponent(manager); fValidationManager = createValidationManager(); setProperty(VALIDATION_MANAGER, fValidationManager); // 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> * The parser can use this method to instruct this configuration * to begin parsing an XML document from any valid input source * (a character stream, a byte stream, or a URI). * <p> * Parsers may not invoke this method while a parse is in progress. * Once a parse is complete, the parser may then parse another XML * document. * <p> * This method is synchronous: it will not return until parsing * has ended. If a client application wants to terminate * parsing early, it should throw an exception. * * @param source The input source for the top-level of the * XML document. * * @exception XNIException Any XNI exception, possibly wrapping * another exception. * @exception IOException An IO exception from the parser, possibly * from a byte stream or character stream * supplied by the parser.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?