286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 2004 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A
286N/Apackage com.sun.org.apache.xerces.internal.parsers;
286N/A
286N/Aimport java.io.IOException;
286N/Aimport java.util.ArrayList;
286N/Aimport java.util.HashMap;
286N/Aimport java.util.Locale;
286N/A
286N/Aimport com.sun.org.apache.xerces.internal.impl.Constants;
286N/Aimport com.sun.org.apache.xerces.internal.impl.XML11DTDScannerImpl;
286N/Aimport com.sun.org.apache.xerces.internal.impl.XML11DocumentScannerImpl;
286N/Aimport com.sun.org.apache.xerces.internal.impl.XML11NSDocumentScannerImpl;
286N/Aimport com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl;
286N/Aimport com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl;
286N/Aimport com.sun.org.apache.xerces.internal.impl.XMLEntityHandler;
286N/Aimport com.sun.org.apache.xerces.internal.impl.XMLEntityManager;
286N/Aimport com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
286N/Aimport com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl;
286N/Aimport com.sun.org.apache.xerces.internal.impl.XMLVersionDetector;
286N/Aimport com.sun.org.apache.xerces.internal.impl.dtd.XML11DTDProcessor;
286N/Aimport com.sun.org.apache.xerces.internal.impl.dtd.XML11DTDValidator;
286N/Aimport com.sun.org.apache.xerces.internal.impl.dtd.XML11NSDTDValidator;
286N/Aimport com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDProcessor;
286N/Aimport com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator;
286N/Aimport com.sun.org.apache.xerces.internal.impl.dtd.XMLNSDTDValidator;
286N/Aimport com.sun.org.apache.xerces.internal.impl.dv.DTDDVFactory;
286N/Aimport com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
286N/Aimport com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
286N/Aimport com.sun.org.apache.xerces.internal.util.FeatureState;
286N/Aimport com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings;
286N/Aimport com.sun.org.apache.xerces.internal.util.PropertyState;
286N/Aimport com.sun.org.apache.xerces.internal.util.Status;
286N/Aimport com.sun.org.apache.xerces.internal.util.SymbolTable;
286N/Aimport com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler;
286N/Aimport com.sun.org.apache.xerces.internal.xni.XMLDTDHandler;
286N/Aimport com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler;
286N/Aimport com.sun.org.apache.xerces.internal.xni.XMLLocator;
286N/Aimport com.sun.org.apache.xerces.internal.xni.XNIException;
286N/Aimport com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;
286N/Aimport com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;
286N/Aimport com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
286N/Aimport com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
286N/Aimport com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner;
286N/Aimport com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner;
286N/Aimport com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource;
286N/Aimport com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver;
286N/Aimport com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler;
286N/Aimport com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
286N/Aimport com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration;
286N/A
286N/A/**
286N/A * This class is the DTD-only parser configuration
286N/A * used to parse XML 1.0 and XML 1.1 documents.
286N/A *
286N/A * <p>
286N/A * This class recognizes the following features and properties:
286N/A * <ul>
286N/A * <li>Features
286N/A * <ul>
286N/A * <li>http://xml.org/sax/features/validation</li>
286N/A * <li>http://xml.org/sax/features/namespaces</li>
286N/A * <li>http://xml.org/sax/features/external-general-entities</li>
286N/A * <li>http://xml.org/sax/features/external-parameter-entities</li>
286N/A * <li>http://apache.org/xml/features/continue-after-fatal-error</li>
286N/A * <li>http://apache.org/xml/features/load-external-dtd</li>
286N/A * </ul>
286N/A * <li>Properties
286N/A * <ul>
286N/A * <li>http://xml.org/sax/properties/xml-string</li>
286N/A * <li>http://apache.org/xml/properties/internal/symbol-table</li>
286N/A * <li>http://apache.org/xml/properties/internal/error-handler</li>
286N/A * <li>http://apache.org/xml/properties/internal/entity-resolver</li>
286N/A * <li>http://apache.org/xml/properties/internal/error-reporter</li>
286N/A * <li>http://apache.org/xml/properties/internal/entity-manager</li>
286N/A * <li>http://apache.org/xml/properties/internal/document-scanner</li>
286N/A * <li>http://apache.org/xml/properties/internal/dtd-scanner</li>
286N/A * <li>http://apache.org/xml/properties/internal/grammar-pool</li>
286N/A * <li>http://apache.org/xml/properties/internal/validator/dtd</li>
286N/A * <li>http://apache.org/xml/properties/internal/datatype-validator-factory</li>
286N/A * </ul>
286N/A * </ul>
286N/A * @author Elena Litani, IBM
286N/A * @author Neil Graham, IBM
286N/A * @author Michael Glavassevich, IBM
286N/A * @author John Kim, IBM
286N/A *
286N/A * @version $Id: XML11DTDConfiguration.java,v 1.5 2010-11-01 04:40:10 joehw Exp $
286N/A */
286N/Apublic class XML11DTDConfiguration extends ParserConfigurationSettings
286N/A implements XMLPullParserConfiguration, XML11Configurable {
286N/A
286N/A //
286N/A // Constants
286N/A //
286N/A protected final static String XML11_DATATYPE_VALIDATOR_FACTORY =
286N/A "com.sun.org.apache.xerces.internal.impl.dv.dtd.XML11DTDDVFactoryImpl";
286N/A
286N/A // feature identifiers
286N/A
286N/A /** Feature identifier: validation. */
286N/A protected static final String VALIDATION =
286N/A Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;
286N/A
286N/A /** Feature identifier: namespaces. */
286N/A protected static final String NAMESPACES =
286N/A Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;
286N/A
286N/A /** Feature identifier: external general entities. */
286N/A protected static final String EXTERNAL_GENERAL_ENTITIES =
286N/A Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE;
286N/A
286N/A /** Feature identifier: external parameter entities. */
286N/A protected static final String EXTERNAL_PARAMETER_ENTITIES =
286N/A Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE;
286N/A
286N/A /** Feature identifier: continue after fatal error. */
286N/A protected static final String CONTINUE_AFTER_FATAL_ERROR =
286N/A Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE;
286N/A
286N/A /** Feature identifier: load external DTD. */
286N/A protected static final String LOAD_EXTERNAL_DTD =
286N/A Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE;
286N/A
286N/A // property identifiers
286N/A
286N/A /** Property identifier: xml string. */
286N/A protected static final String XML_STRING =
286N/A Constants.SAX_PROPERTY_PREFIX + Constants.XML_STRING_PROPERTY;
286N/A
286N/A /** Property identifier: symbol table. */
286N/A protected static final String SYMBOL_TABLE =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY;
286N/A
286N/A /** Property identifier: error handler. */
286N/A protected static final String ERROR_HANDLER =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY;
286N/A
286N/A /** Property identifier: entity resolver. */
286N/A protected static final String ENTITY_RESOLVER =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
286N/A
286N/A /** Property identifier: error reporter. */
286N/A protected static final String ERROR_REPORTER =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
286N/A
286N/A /** Property identifier: entity manager. */
286N/A protected static final String ENTITY_MANAGER =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;
286N/A
286N/A /** Property identifier document scanner: */
286N/A protected static final String DOCUMENT_SCANNER =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_SCANNER_PROPERTY;
286N/A
286N/A /** Property identifier: DTD scanner. */
286N/A protected static final String DTD_SCANNER =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY;
286N/A
286N/A /** Property identifier: grammar pool. */
286N/A protected static final String XMLGRAMMAR_POOL =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY;
286N/A
286N/A /** Property identifier: DTD loader. */
286N/A protected static final String DTD_PROCESSOR =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_PROCESSOR_PROPERTY;
286N/A
286N/A /** Property identifier: DTD validator. */
286N/A protected static final String DTD_VALIDATOR =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_VALIDATOR_PROPERTY;
286N/A
286N/A /** Property identifier: namespace binder. */
286N/A protected static final String NAMESPACE_BINDER =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_BINDER_PROPERTY;
286N/A
286N/A /** Property identifier: datatype validator factory. */
286N/A protected static final String DATATYPE_VALIDATOR_FACTORY =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY;
286N/A
286N/A protected static final String VALIDATION_MANAGER =
286N/A Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
286N/A
286N/A /** Property identifier: JAXP schema language / DOM schema-type. */
286N/A protected static final String JAXP_SCHEMA_LANGUAGE =
286N/A Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE;
286N/A
286N/A /** Property identifier: JAXP schema source/ DOM schema-location. */
286N/A protected static final String JAXP_SCHEMA_SOURCE =
286N/A Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE;
286N/A
286N/A // debugging
286N/A
286N/A /** Set to true and recompile to print exception stack trace. */
286N/A protected static final boolean PRINT_EXCEPTION_STACK_TRACE = false;
286N/A
286N/A //
286N/A // Data
286N/A //
286N/A protected SymbolTable fSymbolTable;
286N/A protected XMLInputSource fInputSource;
286N/A protected ValidationManager fValidationManager;
286N/A protected XMLVersionDetector fVersionDetector;
286N/A protected XMLLocator fLocator;
286N/A protected Locale fLocale;
286N/A
286N/A /** XML 1.0 Components. */
286N/A protected ArrayList fComponents;
286N/A
286N/A /** XML 1.1. Components. */
286N/A protected ArrayList fXML11Components = null;
286N/A
286N/A /** Common components: XMLEntityManager, XMLErrorReporter */
286N/A protected ArrayList fCommonComponents = null;
286N/A
286N/A /** The document handler. */
286N/A protected XMLDocumentHandler fDocumentHandler;
286N/A
286N/A /** The DTD handler. */
286N/A protected XMLDTDHandler fDTDHandler;
286N/A
286N/A /** The DTD content model handler. */
286N/A protected XMLDTDContentModelHandler fDTDContentModelHandler;
286N/A
286N/A /** Last component in the document pipeline */
286N/A protected XMLDocumentSource fLastComponent;
286N/A
286N/A /**
286N/A * True if a parse is in progress. This state is needed because
286N/A * some features/properties cannot be set while parsing (e.g.
286N/A * validation and namespaces).
286N/A */
286N/A protected boolean fParseInProgress = false;
286N/A
286N/A /**
286N/A * fConfigUpdated is set to true if there has been any change to the configuration settings,
286N/A * i.e a feature or a property was changed.
286N/A */
286N/A protected boolean fConfigUpdated = false;
286N/A
286N/A //
286N/A // XML 1.0 components
286N/A //
286N/A
286N/A /** The XML 1.0 Datatype validator factory. */
286N/A protected DTDDVFactory fDatatypeValidatorFactory;
286N/A
286N/A /** The XML 1.0 Document scanner that does namespace binding. */
286N/A protected XMLNSDocumentScannerImpl fNamespaceScanner;
286N/A
286N/A /** The XML 1.0 Non-namespace implementation of scanner */
286N/A protected XMLDocumentScannerImpl fNonNSScanner;
286N/A
286N/A /** The XML 1.0 DTD Validator: binds namespaces */
286N/A protected XMLDTDValidator fDTDValidator;
286N/A
286N/A /** The XML 1.0 DTD Validator that does not bind namespaces */
286N/A protected XMLDTDValidator fNonNSDTDValidator;
286N/A
286N/A /** The XML 1.0 DTD scanner. */
286N/A protected XMLDTDScanner fDTDScanner;
286N/A
286N/A /** The XML 1.0 DTD Processor . */
286N/A protected XMLDTDProcessor fDTDProcessor;
286N/A
286N/A //
286N/A // XML 1.1 components
286N/A //
286N/A
286N/A /** The XML 1.1 datatype factory. **/
286N/A protected DTDDVFactory fXML11DatatypeFactory = null;
286N/A
286N/A /** The XML 1.1 document scanner that does namespace binding. **/
286N/A protected XML11NSDocumentScannerImpl fXML11NSDocScanner = null;
286N/A
286N/A /** The XML 1.1 document scanner that does not do namespace binding. **/
286N/A protected XML11DocumentScannerImpl fXML11DocScanner = null;
286N/A
286N/A /** The XML 1.1 DTD validator that does namespace binding. **/
286N/A protected XML11NSDTDValidator fXML11NSDTDValidator = null;
286N/A
286N/A /** The XML 1.1 DTD validator that does not do namespace binding. **/
286N/A protected XML11DTDValidator fXML11DTDValidator = null;
286N/A
286N/A /** The XML 1.1 DTD scanner. **/
286N/A protected XML11DTDScannerImpl fXML11DTDScanner = null;
286N/A
286N/A /** The XML 1.1 DTD processor. **/
286N/A protected XML11DTDProcessor fXML11DTDProcessor = null;
286N/A
286N/A //
286N/A // Common components
286N/A //
286N/A
286N/A /** Grammar pool. */
286N/A protected XMLGrammarPool fGrammarPool;
286N/A
286N/A /** Error reporter. */
286N/A protected XMLErrorReporter fErrorReporter;
286N/A
286N/A /** Entity manager. */
286N/A protected XMLEntityManager fEntityManager;
286N/A
286N/A /** Current scanner */
286N/A protected XMLDocumentScanner fCurrentScanner;
286N/A
286N/A /** Current Datatype validator factory. */
286N/A protected DTDDVFactory fCurrentDVFactory;
286N/A
286N/A /** Current DTD scanner. */
286N/A protected XMLDTDScanner fCurrentDTDScanner;
286N/A
286N/A /** Flag indiciating whether XML11 components have been initialized. */
286N/A private boolean f11Initialized = false;
286N/A
286N/A //
286N/A // Constructors
286N/A //
286N/A
286N/A /** Default constructor. */
286N/A public XML11DTDConfiguration() {
286N/A this(null, null, null);
286N/A } // <init>()
286N/A
286N/A /**
286N/A * Constructs a parser configuration using the specified symbol table.
286N/A *
286N/A * @param symbolTable The symbol table to use.
286N/A */
286N/A public XML11DTDConfiguration(SymbolTable symbolTable) {
286N/A this(symbolTable, null, null);
286N/A } // <init>(SymbolTable)
286N/A
286N/A /**
286N/A * Constructs a parser configuration using the specified symbol table and
286N/A * grammar pool.
286N/A * <p>
286N/A * <strong>REVISIT:</strong>
286N/A * Grammar pool will be updated when the new validation engine is
286N/A * implemented.
286N/A *
286N/A * @param symbolTable The symbol table to use.
286N/A * @param grammarPool The grammar pool to use.
286N/A */
286N/A public XML11DTDConfiguration(SymbolTable symbolTable, XMLGrammarPool grammarPool) {
286N/A this(symbolTable, grammarPool, null);
286N/A } // <init>(SymbolTable,XMLGrammarPool)
286N/A
286N/A /**
286N/A * Constructs a parser configuration using the specified symbol table,
286N/A * grammar pool, and parent settings.
286N/A * <p>
286N/A * <strong>REVISIT:</strong>
286N/A * Grammar pool will be updated when the new validation engine is
286N/A * implemented.
286N/A *
286N/A * @param symbolTable The symbol table to use.
286N/A * @param grammarPool The grammar pool to use.
286N/A * @param parentSettings The parent settings.
286N/A */
286N/A public XML11DTDConfiguration(
286N/A SymbolTable symbolTable,
286N/A XMLGrammarPool grammarPool,
286N/A XMLComponentManager parentSettings) {
286N/A
286N/A super(parentSettings);
286N/A
286N/A // create a vector to hold all the components in use
286N/A // XML 1.0 specialized components
286N/A fComponents = new ArrayList();
286N/A // XML 1.1 specialized components
286N/A fXML11Components = new ArrayList();
286N/A // Common components for XML 1.1. and XML 1.0
286N/A fCommonComponents = new ArrayList();
286N/A
286N/A // create table for features and properties
286N/A fFeatures = new HashMap();
286N/A fProperties = new HashMap();
286N/A
286N/A // add default recognized features
286N/A final String[] recognizedFeatures =
286N/A {
286N/A CONTINUE_AFTER_FATAL_ERROR, LOAD_EXTERNAL_DTD, // from XMLDTDScannerImpl
286N/A VALIDATION,
286N/A NAMESPACES,
286N/A EXTERNAL_GENERAL_ENTITIES,
286N/A EXTERNAL_PARAMETER_ENTITIES,
286N/A PARSER_SETTINGS
286N/A };
286N/A addRecognizedFeatures(recognizedFeatures);
286N/A // set state for default features
286N/A fFeatures.put(VALIDATION, Boolean.FALSE);
286N/A fFeatures.put(NAMESPACES, Boolean.TRUE);
286N/A fFeatures.put(EXTERNAL_GENERAL_ENTITIES, Boolean.TRUE);
286N/A fFeatures.put(EXTERNAL_PARAMETER_ENTITIES, Boolean.TRUE);
286N/A fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE);
286N/A fFeatures.put(LOAD_EXTERNAL_DTD, Boolean.TRUE);
286N/A fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);
286N/A
286N/A // add default recognized properties
286N/A final String[] recognizedProperties =
286N/A {
286N/A SYMBOL_TABLE,
286N/A ERROR_HANDLER,
286N/A ENTITY_RESOLVER,
286N/A ERROR_REPORTER,
286N/A ENTITY_MANAGER,
286N/A DOCUMENT_SCANNER,
286N/A DTD_SCANNER,
286N/A DTD_PROCESSOR,
286N/A DTD_VALIDATOR,
286N/A DATATYPE_VALIDATOR_FACTORY,
286N/A VALIDATION_MANAGER,
286N/A XML_STRING,
286N/A XMLGRAMMAR_POOL,
286N/A JAXP_SCHEMA_SOURCE,
286N/A JAXP_SCHEMA_LANGUAGE};
286N/A addRecognizedProperties(recognizedProperties);
286N/A
286N/A if (symbolTable == null) {
286N/A symbolTable = new SymbolTable();
286N/A }
286N/A fSymbolTable = symbolTable;
286N/A fProperties.put(SYMBOL_TABLE, fSymbolTable);
286N/A
286N/A fGrammarPool = grammarPool;
286N/A if (fGrammarPool != null) {
286N/A fProperties.put(XMLGRAMMAR_POOL, fGrammarPool);
286N/A }
286N/A
286N/A fEntityManager = new XMLEntityManager();
286N/A fProperties.put(ENTITY_MANAGER, fEntityManager);
286N/A addCommonComponent(fEntityManager);
286N/A
286N/A fErrorReporter = new XMLErrorReporter();
286N/A fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());
286N/A fProperties.put(ERROR_REPORTER, fErrorReporter);
286N/A addCommonComponent(fErrorReporter);
286N/A
286N/A fNamespaceScanner = new XMLNSDocumentScannerImpl();
286N/A fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner);
286N/A addComponent((XMLComponent) fNamespaceScanner);
286N/A
286N/A fDTDScanner = new XMLDTDScannerImpl();
286N/A fProperties.put(DTD_SCANNER, fDTDScanner);
286N/A addComponent((XMLComponent) fDTDScanner);
286N/A
286N/A fDTDProcessor = new XMLDTDProcessor();
286N/A fProperties.put(DTD_PROCESSOR, fDTDProcessor);
286N/A addComponent((XMLComponent) fDTDProcessor);
286N/A
286N/A fDTDValidator = new XMLNSDTDValidator();
286N/A fProperties.put(DTD_VALIDATOR, fDTDValidator);
286N/A addComponent(fDTDValidator);
286N/A
286N/A fDatatypeValidatorFactory = DTDDVFactory.getInstance();
286N/A fProperties.put(DATATYPE_VALIDATOR_FACTORY, fDatatypeValidatorFactory);
286N/A
286N/A fValidationManager = new ValidationManager();
286N/A fProperties.put(VALIDATION_MANAGER, fValidationManager);
286N/A
286N/A fVersionDetector = new XMLVersionDetector();
286N/A
286N/A // add message formatters
286N/A if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
286N/A XMLMessageFormatter xmft = new XMLMessageFormatter();
286N/A fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
286N/A fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
286N/A }
286N/A
286N/A // set locale
286N/A try {
286N/A setLocale(Locale.getDefault());
286N/A } catch (XNIException e) {
286N/A // do nothing
286N/A // REVISIT: What is the right thing to do? -Ac
286N/A }
286N/A
286N/A fConfigUpdated = false;
286N/A
286N/A } // <init>(SymbolTable,XMLGrammarPool)
286N/A
286N/A //
286N/A // Public methods
286N/A //
286N/A /**
286N/A * Sets the input source for the document to parse.
286N/A *
286N/A * @param inputSource The document's input source.
286N/A *
286N/A * @exception XMLConfigurationException Thrown if there is a
286N/A * configuration error when initializing the
286N/A * parser.
286N/A * @exception IOException Thrown on I/O error.
286N/A *
286N/A * @see #parse(boolean)
286N/A */
286N/A public void setInputSource(XMLInputSource inputSource)
286N/A throws XMLConfigurationException, IOException {
286N/A
286N/A // REVISIT: this method used to reset all the components and
286N/A // construct the pipeline. Now reset() is called
286N/A // in parse (boolean) just before we parse the document
286N/A // Should this method still throw exceptions..?
286N/A
286N/A fInputSource = inputSource;
286N/A
286N/A } // setInputSource(XMLInputSource)
286N/A
286N/A /**
286N/A * Set the locale to use for messages.
286N/A *
286N/A * @param locale The locale object to use for localization of messages.
286N/A *
286N/A * @exception XNIException Thrown if the parser does not support the
286N/A * specified locale.
286N/A */
286N/A public void setLocale(Locale locale) throws XNIException {
286N/A fLocale = locale;
286N/A fErrorReporter.setLocale(locale);
286N/A } // setLocale(Locale)
286N/A
286N/A /**
286N/A * Sets the document handler on the last component in the pipeline
286N/A * to receive information about the document.
286N/A *
286N/A * @param documentHandler The document handler.
286N/A */
286N/A public void setDocumentHandler(XMLDocumentHandler documentHandler) {
286N/A fDocumentHandler = documentHandler;
286N/A if (fLastComponent != null) {
286N/A fLastComponent.setDocumentHandler(fDocumentHandler);
286N/A if (fDocumentHandler !=null){
286N/A fDocumentHandler.setDocumentSource(fLastComponent);
286N/A }
286N/A }
286N/A } // setDocumentHandler(XMLDocumentHandler)
286N/A
286N/A /** Returns the registered document handler. */
286N/A public XMLDocumentHandler getDocumentHandler() {
286N/A return fDocumentHandler;
286N/A } // getDocumentHandler():XMLDocumentHandler
286N/A
286N/A /**
286N/A * Sets the DTD handler.
286N/A *
286N/A * @param dtdHandler The DTD handler.
286N/A */
286N/A public void setDTDHandler(XMLDTDHandler dtdHandler) {
286N/A fDTDHandler = dtdHandler;
286N/A } // setDTDHandler(XMLDTDHandler)
286N/A
286N/A /** Returns the registered DTD handler. */
286N/A public XMLDTDHandler getDTDHandler() {
286N/A return fDTDHandler;
286N/A } // getDTDHandler():XMLDTDHandler
286N/A
286N/A /**
286N/A * Sets the DTD content model handler.
286N/A *
286N/A * @param handler The DTD content model handler.
286N/A */
286N/A public void setDTDContentModelHandler(XMLDTDContentModelHandler handler) {
286N/A fDTDContentModelHandler = handler;
286N/A } // setDTDContentModelHandler(XMLDTDContentModelHandler)
286N/A
286N/A /** Returns the registered DTD content model handler. */
286N/A public XMLDTDContentModelHandler getDTDContentModelHandler() {
286N/A return fDTDContentModelHandler;
286N/A } // getDTDContentModelHandler():XMLDTDContentModelHandler
286N/A
286N/A /**
286N/A * Sets the resolver used to resolve external entities. The EntityResolver
286N/A * interface supports resolution of public and system identifiers.
286N/A *
286N/A * @param resolver The new entity resolver. Passing a null value will
286N/A * uninstall the currently installed resolver.
286N/A */
286N/A public void setEntityResolver(XMLEntityResolver resolver) {
286N/A fProperties.put(ENTITY_RESOLVER, resolver);
286N/A } // setEntityResolver(XMLEntityResolver)
286N/A
286N/A /**
286N/A * Return the current entity resolver.
286N/A *
286N/A * @return The current entity resolver, or null if none
286N/A * has been registered.
286N/A * @see #setEntityResolver
286N/A */
286N/A public XMLEntityResolver getEntityResolver() {
286N/A return (XMLEntityResolver)fProperties.get(ENTITY_RESOLVER);
286N/A } // getEntityResolver():XMLEntityResolver
286N/A
286N/A /**
286N/A * Allow an application to register an error event handler.
286N/A *
286N/A * <p>If the application does not register an error handler, all
286N/A * error events reported by the SAX parser will be silently
286N/A * ignored; however, normal processing may not continue. It is
286N/A * highly recommended that all SAX applications implement an
286N/A * error handler to avoid unexpected bugs.</p>
286N/A *
286N/A * <p>Applications may register a new or different handler in the
286N/A * middle of a parse, and the SAX parser must begin using the new
286N/A * handler immediately.</p>
286N/A *
286N/A * @param errorHandler The error handler.
286N/A * @exception java.lang.NullPointerException If the handler
286N/A * argument is null.
286N/A * @see #getErrorHandler
286N/A */
286N/A public void setErrorHandler(XMLErrorHandler errorHandler) {
286N/A fProperties.put(ERROR_HANDLER, errorHandler);
286N/A } // setErrorHandler(XMLErrorHandler)
286N/A
286N/A /**
286N/A * Return the current error handler.
286N/A *
286N/A * @return The current error handler, or null if none
286N/A * has been registered.
286N/A * @see #setErrorHandler
286N/A */
286N/A public XMLErrorHandler getErrorHandler() {
286N/A // REVISIT: Should this be a property?
286N/A return (XMLErrorHandler)fProperties.get(ERROR_HANDLER);
286N/A } // getErrorHandler():XMLErrorHandler
286N/A
286N/A
286N/A /**
286N/A * If the application decides to terminate parsing before the xml document
286N/A * is fully parsed, the application should call this method to free any
286N/A * resource allocated during parsing. For example, close all opened streams.
286N/A */
286N/A public void cleanup() {
286N/A fEntityManager.closeReaders();
286N/A }
286N/A
286N/A /**
286N/A * Parses the specified input source.
286N/A *
286N/A * @param source The input source.
286N/A *
286N/A * @exception XNIException Throws exception on XNI error.
286N/A * @exception java.io.IOException Throws exception on i/o error.
286N/A */
286N/A public void parse(XMLInputSource source) throws XNIException, IOException {
286N/A
286N/A if (fParseInProgress) {
286N/A // REVISIT - need to add new error message
286N/A throw new XNIException("FWK005 parse may not be called while parsing.");
286N/A }
286N/A fParseInProgress = true;
286N/A
286N/A try {
286N/A setInputSource(source);
286N/A parse(true);
286N/A } catch (XNIException ex) {
286N/A if (PRINT_EXCEPTION_STACK_TRACE)
286N/A ex.printStackTrace();
286N/A throw ex;
286N/A } catch (IOException ex) {
286N/A if (PRINT_EXCEPTION_STACK_TRACE)
286N/A ex.printStackTrace();
286N/A throw ex;
286N/A } catch (RuntimeException ex) {
286N/A if (PRINT_EXCEPTION_STACK_TRACE)
286N/A ex.printStackTrace();
286N/A throw ex;
286N/A } catch (Exception ex) {
286N/A if (PRINT_EXCEPTION_STACK_TRACE)
286N/A ex.printStackTrace();
286N/A throw new XNIException(ex);
286N/A } finally {
286N/A fParseInProgress = false;
286N/A // close all streams opened by xerces
286N/A this.cleanup();
286N/A }
286N/A
286N/A } // parse(InputSource)
286N/A
286N/A public boolean parse(boolean complete) throws XNIException, IOException {
286N/A //
286N/A // reset and configure pipeline and set InputSource.
286N/A if (fInputSource != null) {
286N/A try {
286N/A fValidationManager.reset();
286N/A fVersionDetector.reset(this);
286N/A resetCommon();
286N/A
286N/A short version = fVersionDetector.determineDocVersion(fInputSource);
286N/A if (version == Constants.XML_VERSION_1_1) {
286N/A initXML11Components();
286N/A configureXML11Pipeline();
286N/A resetXML11();
286N/A } else {
286N/A configurePipeline();
286N/A reset();
286N/A }
286N/A
286N/A // mark configuration as fixed
286N/A fConfigUpdated = false;
286N/A
286N/A // resets and sets the pipeline.
286N/A fVersionDetector.startDocumentParsing((XMLEntityHandler) fCurrentScanner, version);
286N/A fInputSource = null;
286N/A } catch (XNIException ex) {
286N/A if (PRINT_EXCEPTION_STACK_TRACE)
286N/A ex.printStackTrace();
286N/A throw ex;
286N/A } catch (IOException ex) {
286N/A if (PRINT_EXCEPTION_STACK_TRACE)
286N/A ex.printStackTrace();
286N/A throw ex;
286N/A } catch (RuntimeException ex) {
286N/A if (PRINT_EXCEPTION_STACK_TRACE)
286N/A ex.printStackTrace();
286N/A throw ex;
286N/A } catch (Exception ex) {
286N/A if (PRINT_EXCEPTION_STACK_TRACE)
286N/A ex.printStackTrace();
286N/A throw new XNIException(ex);
286N/A }
286N/A }
286N/A
286N/A try {
286N/A return fCurrentScanner.scanDocument(complete);
286N/A } catch (XNIException ex) {
286N/A if (PRINT_EXCEPTION_STACK_TRACE)
286N/A ex.printStackTrace();
286N/A throw ex;
286N/A } catch (IOException ex) {
286N/A if (PRINT_EXCEPTION_STACK_TRACE)
286N/A ex.printStackTrace();
286N/A throw ex;
286N/A } catch (RuntimeException ex) {
286N/A if (PRINT_EXCEPTION_STACK_TRACE)
286N/A ex.printStackTrace();
286N/A throw ex;
286N/A } catch (Exception ex) {
286N/A if (PRINT_EXCEPTION_STACK_TRACE)
286N/A ex.printStackTrace();
286N/A throw new XNIException(ex);
286N/A }
286N/A
286N/A } // parse(boolean):boolean
286N/A
286N/A /**
286N/A * Returns the state of a feature.
286N/A *
286N/A * @param featureId The feature identifier.
286N/A * @return true if the feature is supported
286N/A *
286N/A * @throws XMLConfigurationException Thrown for configuration error.
286N/A * In general, components should
286N/A * only throw this exception if
286N/A * it is <strong>really</strong>
286N/A * a critical error.
286N/A */
286N/A public FeatureState getFeatureState(String featureId)
286N/A throws XMLConfigurationException {
286N/A // make this feature special
286N/A if (featureId.equals(PARSER_SETTINGS)){
286N/A return FeatureState.is(fConfigUpdated);
286N/A }
286N/A return super.getFeatureState(featureId);
286N/A
286N/A } // getFeature(String):boolean
286N/A
286N/A /**
286N/A * Set the state of a feature.
286N/A *
286N/A * Set the state of any feature in a SAX2 parser. The parser
286N/A * might not recognize the feature, and if it does recognize
286N/A * it, it might not be able to fulfill the request.
286N/A *
286N/A * @param featureId The unique identifier (URI) of the feature.
286N/A * @param state The requested state of the feature (true or false).
286N/A *
286N/A * @exception com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException If the
286N/A * requested feature is not known.
286N/A */
286N/A public void setFeature(String featureId, boolean state)
286N/A throws XMLConfigurationException {
286N/A fConfigUpdated = true;
286N/A // forward to every XML 1.0 component
286N/A int count = fComponents.size();
286N/A for (int i = 0; i < count; i++) {
286N/A XMLComponent c = (XMLComponent) fComponents.get(i);
286N/A c.setFeature(featureId, state);
286N/A }
286N/A // forward it to common components
286N/A count = fCommonComponents.size();
286N/A for (int i = 0; i < count; i++) {
286N/A XMLComponent c = (XMLComponent) fCommonComponents.get(i);
286N/A c.setFeature(featureId, state);
286N/A }
286N/A
286N/A // forward to every XML 1.1 component
286N/A count = fXML11Components.size();
286N/A for (int i = 0; i < count; i++) {
286N/A XMLComponent c = (XMLComponent) fXML11Components.get(i);
286N/A try{
286N/A c.setFeature(featureId, state);
286N/A }
286N/A catch (Exception e){
286N/A // no op
286N/A }
286N/A }
286N/A // save state if noone "objects"
286N/A super.setFeature(featureId, state);
286N/A
286N/A } // setFeature(String,boolean)
286N/A
286N/A /**
286N/A * setProperty
286N/A *
286N/A * @param propertyId
286N/A * @param value
286N/A */
286N/A public void setProperty(String propertyId, Object value)
286N/A throws XMLConfigurationException {
286N/A fConfigUpdated = true;
286N/A // forward to every XML 1.0 component
286N/A int count = fComponents.size();
286N/A for (int i = 0; i < count; i++) {
286N/A XMLComponent c = (XMLComponent) fComponents.get(i);
286N/A c.setProperty(propertyId, value);
286N/A }
286N/A // forward it to every common Component
286N/A count = fCommonComponents.size();
286N/A for (int i = 0; i < count; i++) {
286N/A XMLComponent c = (XMLComponent) fCommonComponents.get(i);
286N/A c.setProperty(propertyId, value);
286N/A }
286N/A // forward it to every XML 1.1 component
286N/A count = fXML11Components.size();
286N/A for (int i = 0; i < count; i++) {
286N/A XMLComponent c = (XMLComponent) fXML11Components.get(i);
286N/A try{
286N/A c.setProperty(propertyId, value);
286N/A }
286N/A catch (Exception e){
286N/A // ignore it
286N/A }
286N/A }
286N/A
286N/A // store value if noone "objects"
286N/A super.setProperty(propertyId, value);
286N/A
286N/A } // setProperty(String,Object)
286N/A
286N/A
286N/A /** Returns the locale. */
286N/A public Locale getLocale() {
286N/A return fLocale;
286N/A } // getLocale():Locale
286N/A
286N/A /**
286N/A * reset all XML 1.0 components before parsing and namespace context
286N/A */
286N/A protected void reset() throws XNIException {
286N/A int count = fComponents.size();
286N/A for (int i = 0; i < count; i++) {
286N/A XMLComponent c = (XMLComponent) fComponents.get(i);
286N/A c.reset(this);
286N/A }
286N/A
286N/A } // reset()
286N/A
286N/A /**
286N/A * reset all common components before parsing
286N/A */
286N/A protected void resetCommon() throws XNIException {
286N/A // reset common components
286N/A int count = fCommonComponents.size();
286N/A for (int i = 0; i < count; i++) {
286N/A XMLComponent c = (XMLComponent) fCommonComponents.get(i);
286N/A c.reset(this);
286N/A }
286N/A
286N/A } // resetCommon()
286N/A
286N/A /**
286N/A * reset all components before parsing and namespace context
286N/A */
286N/A protected void resetXML11() throws XNIException {
286N/A // reset every component
286N/A int count = fXML11Components.size();
286N/A for (int i = 0; i < count; i++) {
286N/A XMLComponent c = (XMLComponent) fXML11Components.get(i);
286N/A c.reset(this);
286N/A }
286N/A
286N/A } // resetXML11()
286N/A
286N/A /**
286N/A * Configures the XML 1.1 pipeline.
286N/A * Note: this method also resets the new XML11 components.
286N/A */
286N/A protected void configureXML11Pipeline() {
286N/A if (fCurrentDVFactory != fXML11DatatypeFactory) {
286N/A fCurrentDVFactory = fXML11DatatypeFactory;
286N/A setProperty(DATATYPE_VALIDATOR_FACTORY, fCurrentDVFactory);
286N/A }
286N/A if (fCurrentDTDScanner != fXML11DTDScanner) {
286N/A fCurrentDTDScanner = fXML11DTDScanner;
286N/A setProperty(DTD_SCANNER, fCurrentDTDScanner);
286N/A setProperty(DTD_PROCESSOR, fXML11DTDProcessor);
286N/A }
286N/A
286N/A fXML11DTDScanner.setDTDHandler(fXML11DTDProcessor);
286N/A fXML11DTDProcessor.setDTDSource(fXML11DTDScanner);
286N/A fXML11DTDProcessor.setDTDHandler(fDTDHandler);
286N/A if (fDTDHandler != null) {
286N/A fDTDHandler.setDTDSource(fXML11DTDProcessor);
286N/A }
286N/A
286N/A fXML11DTDScanner.setDTDContentModelHandler(fXML11DTDProcessor);
286N/A fXML11DTDProcessor.setDTDContentModelSource(fXML11DTDScanner);
286N/A fXML11DTDProcessor.setDTDContentModelHandler(fDTDContentModelHandler);
286N/A if (fDTDContentModelHandler != null) {
286N/A fDTDContentModelHandler.setDTDContentModelSource(fXML11DTDProcessor);
286N/A }
286N/A
286N/A // setup XML 1.1 document pipeline
286N/A if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
286N/A if (fCurrentScanner != fXML11NSDocScanner) {
286N/A fCurrentScanner = fXML11NSDocScanner;
286N/A setProperty(DOCUMENT_SCANNER, fXML11NSDocScanner);
286N/A setProperty(DTD_VALIDATOR, fXML11NSDTDValidator);
286N/A }
286N/A
286N/A fXML11NSDocScanner.setDTDValidator(fXML11NSDTDValidator);
286N/A fXML11NSDocScanner.setDocumentHandler(fXML11NSDTDValidator);
286N/A fXML11NSDTDValidator.setDocumentSource(fXML11NSDocScanner);
286N/A fXML11NSDTDValidator.setDocumentHandler(fDocumentHandler);
286N/A
286N/A if (fDocumentHandler != null) {
286N/A fDocumentHandler.setDocumentSource(fXML11NSDTDValidator);
286N/A }
286N/A fLastComponent = fXML11NSDTDValidator;
286N/A
286N/A } else {
286N/A // create components
286N/A if (fXML11DocScanner == null) {
286N/A // non namespace document pipeline
286N/A fXML11DocScanner = new XML11DocumentScannerImpl();
286N/A addXML11Component(fXML11DocScanner);
286N/A fXML11DTDValidator = new XML11DTDValidator();
286N/A addXML11Component(fXML11DTDValidator);
286N/A }
286N/A if (fCurrentScanner != fXML11DocScanner) {
286N/A fCurrentScanner = fXML11DocScanner;
286N/A setProperty(DOCUMENT_SCANNER, fXML11DocScanner);
286N/A setProperty(DTD_VALIDATOR, fXML11DTDValidator);
286N/A }
286N/A fXML11DocScanner.setDocumentHandler(fXML11DTDValidator);
286N/A fXML11DTDValidator.setDocumentSource(fXML11DocScanner);
286N/A fXML11DTDValidator.setDocumentHandler(fDocumentHandler);
286N/A
286N/A if (fDocumentHandler != null) {
286N/A fDocumentHandler.setDocumentSource(fXML11DTDValidator);
286N/A }
286N/A fLastComponent = fXML11DTDValidator;
286N/A }
286N/A
286N/A } // configureXML11Pipeline()
286N/A
286N/A /** Configures the pipeline. */
286N/A protected void configurePipeline() {
286N/A if (fCurrentDVFactory != fDatatypeValidatorFactory) {
286N/A fCurrentDVFactory = fDatatypeValidatorFactory;
286N/A // use XML 1.0 datatype library
286N/A setProperty(DATATYPE_VALIDATOR_FACTORY, fCurrentDVFactory);
286N/A }
286N/A
286N/A // setup DTD pipeline
286N/A if (fCurrentDTDScanner != fDTDScanner) {
286N/A fCurrentDTDScanner = fDTDScanner;
286N/A setProperty(DTD_SCANNER, fCurrentDTDScanner);
286N/A setProperty(DTD_PROCESSOR, fDTDProcessor);
286N/A }
286N/A fDTDScanner.setDTDHandler(fDTDProcessor);
286N/A fDTDProcessor.setDTDSource(fDTDScanner);
286N/A fDTDProcessor.setDTDHandler(fDTDHandler);
286N/A if (fDTDHandler != null) {
286N/A fDTDHandler.setDTDSource(fDTDProcessor);
286N/A }
286N/A
286N/A fDTDScanner.setDTDContentModelHandler(fDTDProcessor);
286N/A fDTDProcessor.setDTDContentModelSource(fDTDScanner);
286N/A fDTDProcessor.setDTDContentModelHandler(fDTDContentModelHandler);
286N/A if (fDTDContentModelHandler != null) {
286N/A fDTDContentModelHandler.setDTDContentModelSource(fDTDProcessor);
286N/A }
286N/A
286N/A // setup document pipeline
286N/A if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
286N/A if (fCurrentScanner != fNamespaceScanner) {
286N/A fCurrentScanner = fNamespaceScanner;
286N/A setProperty(DOCUMENT_SCANNER, fNamespaceScanner);
286N/A setProperty(DTD_VALIDATOR, fDTDValidator);
286N/A }
286N/A fNamespaceScanner.setDTDValidator(fDTDValidator);
286N/A fNamespaceScanner.setDocumentHandler(fDTDValidator);
286N/A fDTDValidator.setDocumentSource(fNamespaceScanner);
286N/A fDTDValidator.setDocumentHandler(fDocumentHandler);
286N/A if (fDocumentHandler != null) {
286N/A fDocumentHandler.setDocumentSource(fDTDValidator);
286N/A }
286N/A fLastComponent = fDTDValidator;
286N/A } else {
286N/A // create components
286N/A if (fNonNSScanner == null) {
286N/A fNonNSScanner = new XMLDocumentScannerImpl();
286N/A fNonNSDTDValidator = new XMLDTDValidator();
286N/A // add components
286N/A addComponent((XMLComponent) fNonNSScanner);
286N/A addComponent((XMLComponent) fNonNSDTDValidator);
286N/A }
286N/A if (fCurrentScanner != fNonNSScanner) {
286N/A fCurrentScanner = fNonNSScanner;
286N/A setProperty(DOCUMENT_SCANNER, fNonNSScanner);
286N/A setProperty(DTD_VALIDATOR, fNonNSDTDValidator);
286N/A }
286N/A
286N/A fNonNSScanner.setDocumentHandler(fNonNSDTDValidator);
286N/A fNonNSDTDValidator.setDocumentSource(fNonNSScanner);
286N/A fNonNSDTDValidator.setDocumentHandler(fDocumentHandler);
286N/A if (fDocumentHandler != null) {
286N/A fDocumentHandler.setDocumentSource(fNonNSDTDValidator);
286N/A }
286N/A fLastComponent = fNonNSDTDValidator;
286N/A }
286N/A
286N/A } // configurePipeline()
286N/A
286N/A
286N/A // features and properties
286N/A
286N/A /**
286N/A * Check a feature. If feature is know and supported, this method simply
286N/A * returns. Otherwise, the appropriate exception is thrown.
286N/A *
286N/A * @param featureId The unique identifier (URI) of the feature.
286N/A *
286N/A * @throws XMLConfigurationException Thrown for configuration error.
286N/A * In general, components should
286N/A * only throw this exception if
286N/A * it is <strong>really</strong>
286N/A * a critical error.
286N/A */
286N/A protected FeatureState checkFeature(String featureId) throws XMLConfigurationException {
286N/A
286N/A //
286N/A // Xerces Features
286N/A //
286N/A
286N/A if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) {
286N/A final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length();
286N/A
286N/A //
286N/A // http://apache.org/xml/features/validation/dynamic
286N/A // Allows the parser to validate a document only when it
286N/A // contains a grammar. Validation is turned on/off based
286N/A // on each document instance, automatically.
286N/A //
286N/A if (suffixLength == Constants.DYNAMIC_VALIDATION_FEATURE.length() &&
286N/A featureId.endsWith(Constants.DYNAMIC_VALIDATION_FEATURE)) {
286N/A return FeatureState.RECOGNIZED;
286N/A }
286N/A
286N/A //
286N/A // http://apache.org/xml/features/validation/default-attribute-values
286N/A //
286N/A if (suffixLength == Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE.length() &&
286N/A featureId.endsWith(Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE)) {
286N/A // REVISIT
286N/A return FeatureState.NOT_SUPPORTED;
286N/A }
286N/A //
286N/A // http://apache.org/xml/features/validation/default-attribute-values
286N/A //
286N/A if (suffixLength == Constants.VALIDATE_CONTENT_MODELS_FEATURE.length() &&
286N/A featureId.endsWith(Constants.VALIDATE_CONTENT_MODELS_FEATURE)) {
286N/A // REVISIT
286N/A return FeatureState.NOT_SUPPORTED;
286N/A }
286N/A //
286N/A // http://apache.org/xml/features/validation/nonvalidating/load-dtd-grammar
286N/A //
286N/A if (suffixLength == Constants.LOAD_DTD_GRAMMAR_FEATURE.length() &&
286N/A featureId.endsWith(Constants.LOAD_DTD_GRAMMAR_FEATURE)) {
286N/A return FeatureState.RECOGNIZED;
286N/A }
286N/A //
286N/A // http://apache.org/xml/features/validation/nonvalidating/load-external-dtd
286N/A //
286N/A if (suffixLength == Constants.LOAD_EXTERNAL_DTD_FEATURE.length() &&
286N/A featureId.endsWith(Constants.LOAD_EXTERNAL_DTD_FEATURE)) {
286N/A return FeatureState.RECOGNIZED;
286N/A }
286N/A
286N/A //
286N/A // http://apache.org/xml/features/validation/default-attribute-values
286N/A //
286N/A if (suffixLength == Constants.VALIDATE_DATATYPES_FEATURE.length() &&
286N/A featureId.endsWith(Constants.VALIDATE_DATATYPES_FEATURE)) {
286N/A return FeatureState.NOT_SUPPORTED;
286N/A }
286N/A
286N/A // special performance feature: only component manager is allowed to set it.
286N/A if (suffixLength == Constants.PARSER_SETTINGS.length() &&
286N/A featureId.endsWith(Constants.PARSER_SETTINGS)) {
286N/A return FeatureState.NOT_SUPPORTED;
286N/A }
286N/A }
286N/A
286N/A //
286N/A // Not recognized
286N/A //
286N/A
286N/A return super.checkFeature(featureId);
286N/A
286N/A } // checkFeature(String)
286N/A
286N/A /**
286N/A * Check a property. If the property is know and supported, this method
286N/A * simply returns. Otherwise, the appropriate exception is thrown.
286N/A *
286N/A * @param propertyId The unique identifier (URI) of the property
286N/A * being set.
286N/A *
286N/A * @throws XMLConfigurationException Thrown for configuration error.
286N/A * In general, components should
286N/A * only throw this exception if
286N/A * it is <strong>really</strong>
286N/A * a critical error.
286N/A */
286N/A protected PropertyState checkProperty(String propertyId) throws XMLConfigurationException {
286N/A
286N/A //
286N/A // Xerces Properties
286N/A //
286N/A
286N/A if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
286N/A final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length();
286N/A
286N/A if (suffixLength == Constants.DTD_SCANNER_PROPERTY.length() &&
286N/A propertyId.endsWith(Constants.DTD_SCANNER_PROPERTY)) {
286N/A return PropertyState.RECOGNIZED;
286N/A }
286N/A }
286N/A
286N/A // special cases
286N/A if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) {
286N/A final int suffixLength = propertyId.length() - Constants.SAX_PROPERTY_PREFIX.length();
286N/A
286N/A //
286N/A // http://xml.org/sax/properties/xml-string
286N/A // Value type: String
286N/A // Access: read-only
286N/A // Get the literal string of characters associated with the
286N/A // current event. If the parser recognises and supports this
286N/A // property but is not currently parsing text, it should return
286N/A // null (this is a good way to check for availability before the
286N/A // parse begins).
286N/A //
286N/A if (suffixLength == Constants.XML_STRING_PROPERTY.length() &&
286N/A propertyId.endsWith(Constants.XML_STRING_PROPERTY)) {
286N/A // REVISIT - we should probably ask xml-dev for a precise
286N/A // definition of what this is actually supposed to return, and
286N/A // in exactly which circumstances.
286N/A return PropertyState.NOT_SUPPORTED;
286N/A }
286N/A }
286N/A
286N/A //
286N/A // Not recognized
286N/A //
286N/A
286N/A return super.checkProperty(propertyId);
286N/A
286N/A } // checkProperty(String)
286N/A
286N/A
286N/A /**
286N/A * Adds a component to the parser configuration. This method will
286N/A * also add all of the component's recognized features and properties
286N/A * to the list of default recognized features and properties.
286N/A *
286N/A * @param component The component to add.
286N/A */
286N/A protected void addComponent(XMLComponent component) {
286N/A
286N/A // don't add a component more than once
286N/A if (fComponents.contains(component)) {
286N/A return;
286N/A }
286N/A fComponents.add(component);
286N/A addRecognizedParamsAndSetDefaults(component);
286N/A
286N/A } // addComponent(XMLComponent)
286N/A
286N/A /**
286N/A * Adds common component to the parser configuration. This method will
286N/A * also add all of the component's recognized features and properties
286N/A * to the list of default recognized features and properties.
286N/A *
286N/A * @param component The component to add.
286N/A */
286N/A protected void addCommonComponent(XMLComponent component) {
286N/A
286N/A // don't add a component more than once
286N/A if (fCommonComponents.contains(component)) {
286N/A return;
286N/A }
286N/A fCommonComponents.add(component);
286N/A addRecognizedParamsAndSetDefaults(component);
286N/A
286N/A } // addCommonComponent(XMLComponent)
286N/A
286N/A /**
286N/A * Adds an XML 1.1 component to the parser configuration. This method will
286N/A * also add all of the component's recognized features and properties
286N/A * to the list of default recognized features and properties.
286N/A *
286N/A * @param component The component to add.
286N/A */
286N/A protected void addXML11Component(XMLComponent component) {
286N/A
286N/A // don't add a component more than once
286N/A if (fXML11Components.contains(component)) {
286N/A return;
286N/A }
286N/A fXML11Components.add(component);
286N/A addRecognizedParamsAndSetDefaults(component);
286N/A
286N/A } // addXML11Component(XMLComponent)
286N/A
286N/A /**
286N/A * Adds all of the component's recognized features and properties
286N/A * to the list of default recognized features and properties, and
286N/A * sets default values on the configuration for features and
286N/A * properties which were previously absent from the configuration.
286N/A *
286N/A * @param component The component whose recognized features
286N/A * and properties will be added to the configuration
286N/A */
286N/A protected void addRecognizedParamsAndSetDefaults(XMLComponent component) {
286N/A
286N/A // register component's recognized features
286N/A String[] recognizedFeatures = component.getRecognizedFeatures();
286N/A addRecognizedFeatures(recognizedFeatures);
286N/A
286N/A // register component's recognized properties
286N/A String[] recognizedProperties = component.getRecognizedProperties();
286N/A addRecognizedProperties(recognizedProperties);
286N/A
286N/A // set default values
286N/A if (recognizedFeatures != null) {
286N/A for (int i = 0; i < recognizedFeatures.length; ++i) {
286N/A String featureId = recognizedFeatures[i];
286N/A Boolean state = component.getFeatureDefault(featureId);
286N/A if (state != null) {
286N/A // Do not overwrite values already set on the configuration.
286N/A if (!fFeatures.containsKey(featureId)) {
286N/A fFeatures.put(featureId, state);
286N/A // For newly added components who recognize this feature
286N/A // but did not offer a default value, we need to make
286N/A // sure these components will get an opportunity to read
286N/A // the value before parsing begins.
286N/A fConfigUpdated = true;
286N/A }
286N/A }
286N/A }
286N/A }
286N/A if (recognizedProperties != null) {
286N/A for (int i = 0; i < recognizedProperties.length; ++i) {
286N/A String propertyId = recognizedProperties[i];
286N/A Object value = component.getPropertyDefault(propertyId);
286N/A if (value != null) {
286N/A // Do not overwrite values already set on the configuration.
286N/A if (!fProperties.containsKey(propertyId)) {
286N/A fProperties.put(propertyId, value);
286N/A // For newly added components who recognize this property
286N/A // but did not offer a default value, we need to make
286N/A // sure these components will get an opportunity to read
286N/A // the value before parsing begins.
286N/A fConfigUpdated = true;
286N/A }
286N/A }
286N/A }
286N/A }
286N/A }
286N/A
286N/A private void initXML11Components() {
286N/A if (!f11Initialized) {
286N/A
286N/A // create datatype factory
286N/A fXML11DatatypeFactory = DTDDVFactory.getInstance(XML11_DATATYPE_VALIDATOR_FACTORY);
286N/A
286N/A // setup XML 1.1 DTD pipeline
286N/A fXML11DTDScanner = new XML11DTDScannerImpl();
286N/A addXML11Component(fXML11DTDScanner);
286N/A fXML11DTDProcessor = new XML11DTDProcessor();
286N/A addXML11Component(fXML11DTDProcessor);
286N/A
286N/A // setup XML 1.1. document pipeline - namespace aware
286N/A fXML11NSDocScanner = new XML11NSDocumentScannerImpl();
286N/A addXML11Component(fXML11NSDocScanner);
286N/A fXML11NSDTDValidator = new XML11NSDTDValidator();
286N/A addXML11Component(fXML11NSDTDValidator);
286N/A
286N/A f11Initialized = true;
286N/A }
286N/A }
286N/A
286N/A} // class XML11DTDConfiguration