Save This Page
Home » openjdk-7 » com.sun.org.apache.xerces.internal » parsers » [javadoc | source]
    1   /*
    2    * reserved comment block
    3    * DO NOT REMOVE OR ALTER!
    4    */
    5   /*
    6    * Copyright 2001-2005 The Apache Software Foundation.
    7    *
    8    * Licensed under the Apache License, Version 2.0 (the "License");
    9    * you may not use this file except in compliance with the License.
   10    * You may obtain a copy of the License at
   11    *
   12    *      http://www.apache.org/licenses/LICENSE-2.0
   13    *
   14    * Unless required by applicable law or agreed to in writing, software
   15    * distributed under the License is distributed on an "AS IS" BASIS,
   16    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   17    * See the License for the specific language governing permissions and
   18    * limitations under the License.
   19    */
   20   
   21   package com.sun.org.apache.xerces.internal.parsers;
   22   
   23   import java.io.IOException;
   24   import java.util.ArrayList;
   25   import java.util.HashMap;
   26   import java.util.Locale;
   27   
   28   import com.sun.org.apache.xerces.internal.impl.Constants;
   29   import com.sun.org.apache.xerces.internal.impl.XML11DTDScannerImpl;
   30   import com.sun.org.apache.xerces.internal.impl.XML11DocumentScannerImpl;
   31   import com.sun.org.apache.xerces.internal.impl.XML11NSDocumentScannerImpl;
   32   import com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl;
   33   import com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl;
   34   import com.sun.org.apache.xerces.internal.impl.XMLEntityHandler;
   35   import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;
   36   import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
   37   import com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl;
   38   import com.sun.org.apache.xerces.internal.impl.XMLVersionDetector;
   39   import com.sun.org.apache.xerces.internal.impl.dtd.XML11DTDProcessor;
   40   import com.sun.org.apache.xerces.internal.impl.dtd.XML11DTDValidator;
   41   import com.sun.org.apache.xerces.internal.impl.dtd.XML11NSDTDValidator;
   42   import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDProcessor;
   43   import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator;
   44   import com.sun.org.apache.xerces.internal.impl.dtd.XMLNSDTDValidator;
   45   import com.sun.org.apache.xerces.internal.impl.dv.DTDDVFactory;
   46   import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
   47   import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
   48   import com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator;
   49   import com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter;
   50   import com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings;
   51   import com.sun.org.apache.xerces.internal.util.SymbolTable;
   52   import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler;
   53   import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler;
   54   import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler;
   55   import com.sun.org.apache.xerces.internal.xni.XMLLocator;
   56   import com.sun.org.apache.xerces.internal.xni.XNIException;
   57   import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;
   58   import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;
   59   import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
   60   import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
   61   import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner;
   62   import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner;
   63   import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource;
   64   import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver;
   65   import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler;
   66   import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
   67   import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration;
   68   
   69   /**
   70    * This class is the configuration used to parse XML 1.0 and XML 1.1 documents.
   71    *
   72    * @author Elena Litani, IBM
   73    * @author Neil Graham, IBM
   74    * @author Michael Glavassevich, IBM
   75    *
   76    */
   77   public class XML11Configuration extends ParserConfigurationSettings
   78       implements XMLPullParserConfiguration, XML11Configurable {
   79   
   80       //
   81       // Constants
   82       //
   83       protected final static String XML11_DATATYPE_VALIDATOR_FACTORY =
   84           "com.sun.org.apache.xerces.internal.impl.dv.dtd.XML11DTDDVFactoryImpl";
   85   
   86       // feature identifiers
   87   
   88       /** Feature identifier: warn on duplicate attribute definition. */
   89       protected static final String WARN_ON_DUPLICATE_ATTDEF =
   90           Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE;
   91   
   92       /** Feature identifier: warn on duplicate entity definition. */
   93       protected static final String WARN_ON_DUPLICATE_ENTITYDEF =
   94           Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ENTITYDEF_FEATURE;
   95   
   96       /** Feature identifier: warn on undeclared element definition. */
   97       protected static final String WARN_ON_UNDECLARED_ELEMDEF =
   98           Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_UNDECLARED_ELEMDEF_FEATURE;
   99   
  100       /** Feature identifier: allow Java encodings. */
  101       protected static final String ALLOW_JAVA_ENCODINGS =
  102           Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE;
  103   
  104       /** Feature identifier: continue after fatal error. */
  105       protected static final String CONTINUE_AFTER_FATAL_ERROR =
  106           Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE;
  107   
  108       /** Feature identifier: load external DTD. */
  109       protected static final String LOAD_EXTERNAL_DTD =
  110           Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE;
  111   
  112       /** Feature identifier: notify built-in refereces. */
  113       protected static final String NOTIFY_BUILTIN_REFS =
  114           Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_BUILTIN_REFS_FEATURE;
  115   
  116       /** Feature identifier: notify character refereces. */
  117       protected static final String NOTIFY_CHAR_REFS =
  118           Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_CHAR_REFS_FEATURE;
  119   
  120       /** Feature identifier: expose schema normalized value */
  121       protected static final String NORMALIZE_DATA =
  122           Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE;
  123   
  124       /** Feature identifier: send element default value via characters() */
  125       protected static final String SCHEMA_ELEMENT_DEFAULT =
  126           Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_ELEMENT_DEFAULT;
  127   
  128       /** Feature identifier: augment PSVI */
  129       protected static final String SCHEMA_AUGMENT_PSVI =
  130           Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI;
  131   
  132       /** feature identifier: XML Schema validation */
  133       protected static final String XMLSCHEMA_VALIDATION =
  134           Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE;
  135   
  136       /** feature identifier: XML Schema validation -- full checking */
  137       protected static final String XMLSCHEMA_FULL_CHECKING =
  138           Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_FULL_CHECKING;
  139   
  140       /** Feature: generate synthetic annotations */
  141       protected static final String GENERATE_SYNTHETIC_ANNOTATIONS =
  142           Constants.XERCES_FEATURE_PREFIX + Constants.GENERATE_SYNTHETIC_ANNOTATIONS_FEATURE;
  143   
  144       /** Feature identifier: validate annotations */
  145       protected static final String VALIDATE_ANNOTATIONS =
  146           Constants.XERCES_FEATURE_PREFIX + Constants.VALIDATE_ANNOTATIONS_FEATURE;
  147   
  148       /** Feature identifier: honour all schemaLocations */
  149       protected static final String HONOUR_ALL_SCHEMALOCATIONS =
  150           Constants.XERCES_FEATURE_PREFIX + Constants.HONOUR_ALL_SCHEMALOCATIONS_FEATURE;
  151   
  152       /** Feature identifier: use grammar pool only */
  153       protected static final String USE_GRAMMAR_POOL_ONLY =
  154           Constants.XERCES_FEATURE_PREFIX + Constants.USE_GRAMMAR_POOL_ONLY_FEATURE;
  155   
  156           // feature identifiers
  157   
  158           /** Feature identifier: validation. */
  159           protected static final String VALIDATION =
  160                   Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;
  161   
  162           /** Feature identifier: namespaces. */
  163           protected static final String NAMESPACES =
  164                   Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;
  165   
  166           /** Feature identifier: external general entities. */
  167           protected static final String EXTERNAL_GENERAL_ENTITIES =
  168                   Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE;
  169   
  170           /** Feature identifier: external parameter entities. */
  171           protected static final String EXTERNAL_PARAMETER_ENTITIES =
  172                   Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE;
  173   
  174   
  175   
  176       // property identifiers
  177   
  178   
  179           /** Property identifier: xml string. */
  180           protected static final String XML_STRING =
  181                   Constants.SAX_PROPERTY_PREFIX + Constants.XML_STRING_PROPERTY;
  182   
  183           /** Property identifier: symbol table. */
  184           protected static final String SYMBOL_TABLE =
  185                   Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY;
  186   
  187           /** Property identifier: error handler. */
  188           protected static final String ERROR_HANDLER =
  189                   Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY;
  190   
  191           /** Property identifier: entity resolver. */
  192           protected static final String ENTITY_RESOLVER =
  193                   Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
  194   
  195   
  196       /** Property identifier: XML Schema validator. */
  197       protected static final String SCHEMA_VALIDATOR =
  198           Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_VALIDATOR_PROPERTY;
  199   
  200       /** Property identifier: schema location. */
  201       protected static final String SCHEMA_LOCATION =
  202           Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_LOCATION;
  203   
  204       /** Property identifier: no namespace schema location. */
  205       protected static final String SCHEMA_NONS_LOCATION =
  206           Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_NONS_LOCATION;
  207   
  208       // property identifiers
  209   
  210       /** Property identifier: error reporter. */
  211       protected static final String ERROR_REPORTER =
  212           Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
  213   
  214       /** Property identifier: entity manager. */
  215       protected static final String ENTITY_MANAGER =
  216           Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;
  217   
  218       /** Property identifier document scanner: */
  219       protected static final String DOCUMENT_SCANNER =
  220           Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_SCANNER_PROPERTY;
  221   
  222       /** Property identifier: DTD scanner. */
  223       protected static final String DTD_SCANNER =
  224           Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY;
  225   
  226       /** Property identifier: grammar pool. */
  227       protected static final String XMLGRAMMAR_POOL =
  228           Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY;
  229   
  230       /** Property identifier: DTD loader. */
  231       protected static final String DTD_PROCESSOR =
  232           Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_PROCESSOR_PROPERTY;
  233   
  234       /** Property identifier: DTD validator. */
  235       protected static final String DTD_VALIDATOR =
  236           Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_VALIDATOR_PROPERTY;
  237   
  238       /** Property identifier: namespace binder. */
  239       protected static final String NAMESPACE_BINDER =
  240           Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_BINDER_PROPERTY;
  241   
  242       /** Property identifier: datatype validator factory. */
  243       protected static final String DATATYPE_VALIDATOR_FACTORY =
  244           Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY;
  245   
  246       protected static final String VALIDATION_MANAGER =
  247           Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
  248   
  249       /** Property identifier: JAXP schema language / DOM schema-type. */
  250       protected static final String JAXP_SCHEMA_LANGUAGE =
  251           Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE;
  252   
  253       /** Property identifier: JAXP schema source/ DOM schema-location. */
  254       protected static final String JAXP_SCHEMA_SOURCE =
  255           Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE;
  256   
  257       // debugging
  258   
  259       /** Set to true and recompile to print exception stack trace. */
  260       protected static final boolean PRINT_EXCEPTION_STACK_TRACE = false;
  261   
  262       //
  263       // Data
  264       //
  265   
  266           protected SymbolTable fSymbolTable;
  267       protected XMLInputSource fInputSource;
  268       protected ValidationManager fValidationManager;
  269           protected XMLVersionDetector fVersionDetector;
  270       protected XMLLocator fLocator;
  271           protected Locale fLocale;
  272   
  273           /** XML 1.0 Components. */
  274           protected ArrayList fComponents;
  275   
  276           /** XML 1.1. Components. */
  277           protected ArrayList fXML11Components = null;
  278   
  279           /** Common components: XMLEntityManager, XMLErrorReporter, XMLSchemaValidator */
  280           protected ArrayList fCommonComponents = null;
  281   
  282           /** The document handler. */
  283           protected XMLDocumentHandler fDocumentHandler;
  284   
  285           /** The DTD handler. */
  286           protected XMLDTDHandler fDTDHandler;
  287   
  288           /** The DTD content model handler. */
  289           protected XMLDTDContentModelHandler fDTDContentModelHandler;
  290   
  291           /** Last component in the document pipeline */
  292           protected XMLDocumentSource fLastComponent;
  293   
  294       /**
  295        * True if a parse is in progress. This state is needed because
  296        * some features/properties cannot be set while parsing (e.g.
  297        * validation and namespaces).
  298        */
  299       protected boolean fParseInProgress = false;
  300   
  301       /** fConfigUpdated is set to true if there has been any change to the configuration settings,
  302        * i.e a feature or a property was changed.
  303        */
  304           protected boolean fConfigUpdated = false;
  305   
  306       //
  307       // XML 1.0 components
  308       //
  309   
  310       /** The XML 1.0 Datatype validator factory. */
  311       protected DTDDVFactory fDatatypeValidatorFactory;
  312   
  313       /** The XML 1.0 Document scanner that does namespace binding. */
  314       protected XMLNSDocumentScannerImpl fNamespaceScanner;
  315       /** The XML 1.0 Non-namespace implementation of scanner */
  316       protected XMLDocumentScannerImpl fNonNSScanner;
  317       /** The XML 1.0 DTD Validator: binds namespaces */
  318       protected XMLDTDValidator fDTDValidator;
  319       /** The XML 1.0 DTD Validator that does not bind namespaces */
  320       protected XMLDTDValidator fNonNSDTDValidator;
  321       /** The XML 1.0 DTD scanner. */
  322       protected XMLDTDScanner fDTDScanner;
  323       /** The XML 1.0 DTD Processor . */
  324       protected XMLDTDProcessor fDTDProcessor;
  325   
  326       //
  327       // XML 1.1 components
  328       //
  329   
  330       /** The XML 1.1 datatype factory. **/
  331       protected DTDDVFactory fXML11DatatypeFactory = null;
  332   
  333       /** The XML 1.1 document scanner that does namespace binding. **/
  334       protected XML11NSDocumentScannerImpl fXML11NSDocScanner = null;
  335   
  336       /** The XML 1.1 document scanner that does not do namespace binding. **/
  337       protected XML11DocumentScannerImpl fXML11DocScanner = null;
  338   
  339       /** The XML 1.1 DTD validator that does namespace binding. **/
  340       protected XML11NSDTDValidator fXML11NSDTDValidator = null;
  341   
  342       /** The XML 1.1 DTD validator that does not do namespace binding. **/
  343       protected XML11DTDValidator fXML11DTDValidator = null;
  344   
  345       /** The XML 1.1 DTD scanner. **/
  346       protected XML11DTDScannerImpl fXML11DTDScanner = null;
  347       /** The XML 1.1 DTD processor. **/
  348       protected XML11DTDProcessor fXML11DTDProcessor = null;
  349   
  350       //
  351       // Common components
  352       //
  353   
  354       /** Grammar pool. */
  355       protected XMLGrammarPool fGrammarPool;
  356   
  357       /** Error reporter. */
  358       protected XMLErrorReporter fErrorReporter;
  359   
  360       /** Entity manager. */
  361       protected XMLEntityManager fEntityManager;
  362   
  363       /** XML Schema Validator. */
  364       protected XMLSchemaValidator fSchemaValidator;
  365   
  366       /** Current scanner */
  367       protected XMLDocumentScanner fCurrentScanner;
  368       /** Current Datatype validator factory. */
  369       protected DTDDVFactory fCurrentDVFactory;
  370       /** Current DTD scanner. */
  371       protected XMLDTDScanner fCurrentDTDScanner;
  372   
  373       /** Flag indiciating whether XML11 components have been initialized. */
  374       private boolean f11Initialized = false;
  375   
  376       //
  377       // Constructors
  378       //
  379   
  380       /** Default constructor. */
  381       public XML11Configuration() {
  382           this(null, null, null);
  383       } // <init>()
  384   
  385       /**
  386        * Constructs a parser configuration using the specified symbol table.
  387        *
  388        * @param symbolTable The symbol table to use.
  389        */
  390       public XML11Configuration(SymbolTable symbolTable) {
  391           this(symbolTable, null, null);
  392       } // <init>(SymbolTable)
  393   
  394       /**
  395        * Constructs a parser configuration using the specified symbol table and
  396        * grammar pool.
  397        * <p>
  398        * <strong>REVISIT:</strong>
  399        * Grammar pool will be updated when the new validation engine is
  400        * implemented.
  401        *
  402        * @param symbolTable The symbol table to use.
  403        * @param grammarPool The grammar pool to use.
  404        */
  405       public XML11Configuration(SymbolTable symbolTable, XMLGrammarPool grammarPool) {
  406           this(symbolTable, grammarPool, null);
  407       } // <init>(SymbolTable,XMLGrammarPool)
  408   
  409       /**
  410        * Constructs a parser configuration using the specified symbol table,
  411        * grammar pool, and parent settings.
  412        * <p>
  413        * <strong>REVISIT:</strong>
  414        * Grammar pool will be updated when the new validation engine is
  415        * implemented.
  416        *
  417        * @param symbolTable    The symbol table to use.
  418        * @param grammarPool    The grammar pool to use.
  419        * @param parentSettings The parent settings.
  420        */
  421       public XML11Configuration(
  422           SymbolTable symbolTable,
  423           XMLGrammarPool grammarPool,
  424           XMLComponentManager parentSettings) {
  425   
  426                   super(parentSettings);
  427   
  428                   // create a vector to hold all the components in use
  429                   // XML 1.0 specialized components
  430                   fComponents = new ArrayList();
  431                   // XML 1.1 specialized components
  432                   fXML11Components = new ArrayList();
  433                   // Common components for XML 1.1. and XML 1.0
  434                   fCommonComponents = new ArrayList();
  435   
  436                   // create storage for recognized features and properties
  437                   fRecognizedFeatures = new ArrayList();
  438                   fRecognizedProperties = new ArrayList();
  439   
  440                   // create table for features and properties
  441                   fFeatures = new HashMap();
  442                   fProperties = new HashMap();
  443   
  444           // add default recognized features
  445           final String[] recognizedFeatures =
  446               {
  447                   CONTINUE_AFTER_FATAL_ERROR, LOAD_EXTERNAL_DTD, // from XMLDTDScannerImpl
  448                                   VALIDATION,
  449                                   NAMESPACES,
  450                   NORMALIZE_DATA, SCHEMA_ELEMENT_DEFAULT, SCHEMA_AUGMENT_PSVI,
  451                   GENERATE_SYNTHETIC_ANNOTATIONS, VALIDATE_ANNOTATIONS,
  452                   HONOUR_ALL_SCHEMALOCATIONS, USE_GRAMMAR_POOL_ONLY,
  453                   // NOTE: These shouldn't really be here but since the XML Schema
  454                   //       validator is constructed dynamically, its recognized
  455                   //       features might not have been set and it would cause a
  456                   //       not-recognized exception to be thrown. -Ac
  457                   XMLSCHEMA_VALIDATION, XMLSCHEMA_FULL_CHECKING,
  458                                   EXTERNAL_GENERAL_ENTITIES,
  459                                   EXTERNAL_PARAMETER_ENTITIES,
  460                                   PARSER_SETTINGS
  461                           };
  462           addRecognizedFeatures(recognizedFeatures);
  463                   // set state for default features
  464                   fFeatures.put(VALIDATION, Boolean.FALSE);
  465                   fFeatures.put(NAMESPACES, Boolean.TRUE);
  466                   fFeatures.put(EXTERNAL_GENERAL_ENTITIES, Boolean.TRUE);
  467                   fFeatures.put(EXTERNAL_PARAMETER_ENTITIES, Boolean.TRUE);
  468                   fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE);
  469                   fFeatures.put(LOAD_EXTERNAL_DTD, Boolean.TRUE);
  470                   fFeatures.put(SCHEMA_ELEMENT_DEFAULT, Boolean.TRUE);
  471                   fFeatures.put(NORMALIZE_DATA, Boolean.TRUE);
  472                   fFeatures.put(SCHEMA_AUGMENT_PSVI, Boolean.TRUE);
  473           fFeatures.put(GENERATE_SYNTHETIC_ANNOTATIONS, Boolean.FALSE);
  474           fFeatures.put(VALIDATE_ANNOTATIONS, Boolean.FALSE);
  475           fFeatures.put(HONOUR_ALL_SCHEMALOCATIONS, Boolean.FALSE);
  476           fFeatures.put(USE_GRAMMAR_POOL_ONLY, Boolean.FALSE);
  477                   fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);
  478   
  479           // add default recognized properties
  480           final String[] recognizedProperties =
  481               {
  482                                   SYMBOL_TABLE,
  483                                   ERROR_HANDLER,
  484                                   ENTITY_RESOLVER,
  485                   ERROR_REPORTER,
  486                   ENTITY_MANAGER,
  487                   DOCUMENT_SCANNER,
  488                   DTD_SCANNER,
  489                   DTD_PROCESSOR,
  490                   DTD_VALIDATOR,
  491                                   DATATYPE_VALIDATOR_FACTORY,
  492                                   VALIDATION_MANAGER,
  493                                   SCHEMA_VALIDATOR,
  494                                   XML_STRING,
  495                   XMLGRAMMAR_POOL,
  496                   JAXP_SCHEMA_SOURCE,
  497                   JAXP_SCHEMA_LANGUAGE,
  498                   // NOTE: These shouldn't really be here but since the XML Schema
  499                   //       validator is constructed dynamically, its recognized
  500                   //       properties might not have been set and it would cause a
  501                   //       not-recognized exception to be thrown. -Ac
  502                   SCHEMA_LOCATION, SCHEMA_NONS_LOCATION, };
  503           addRecognizedProperties(recognizedProperties);
  504   
  505                   if (symbolTable == null) {
  506                           symbolTable = new SymbolTable();
  507                   }
  508                   fSymbolTable = symbolTable;
  509                   fProperties.put(SYMBOL_TABLE, fSymbolTable);
  510   
  511           fGrammarPool = grammarPool;
  512           if (fGrammarPool != null) {
  513                           fProperties.put(XMLGRAMMAR_POOL, fGrammarPool);
  514           }
  515   
  516           fEntityManager = new XMLEntityManager();
  517                   fProperties.put(ENTITY_MANAGER, fEntityManager);
  518           addCommonComponent(fEntityManager);
  519   
  520           fErrorReporter = new XMLErrorReporter();
  521           fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());
  522                   fProperties.put(ERROR_REPORTER, fErrorReporter);
  523           addCommonComponent(fErrorReporter);
  524   
  525           fNamespaceScanner = new XMLNSDocumentScannerImpl();
  526                   fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner);
  527           addComponent((XMLComponent) fNamespaceScanner);
  528   
  529           fDTDScanner = new XMLDTDScannerImpl();
  530                   fProperties.put(DTD_SCANNER, fDTDScanner);
  531           addComponent((XMLComponent) fDTDScanner);
  532   
  533           fDTDProcessor = new XMLDTDProcessor();
  534                   fProperties.put(DTD_PROCESSOR, fDTDProcessor);
  535           addComponent((XMLComponent) fDTDProcessor);
  536   
  537           fDTDValidator = new XMLNSDTDValidator();
  538                   fProperties.put(DTD_VALIDATOR, fDTDValidator);
  539           addComponent(fDTDValidator);
  540   
  541           fDatatypeValidatorFactory = DTDDVFactory.getInstance();
  542                   fProperties.put(DATATYPE_VALIDATOR_FACTORY, fDatatypeValidatorFactory);
  543   
  544           fValidationManager = new ValidationManager();
  545                   fProperties.put(VALIDATION_MANAGER, fValidationManager);
  546   
  547           fVersionDetector = new XMLVersionDetector();
  548   
  549           // add message formatters
  550           if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
  551               XMLMessageFormatter xmft = new XMLMessageFormatter();
  552               fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
  553               fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
  554           }
  555   
  556           // set locale
  557           try {
  558               setLocale(Locale.getDefault());
  559           } catch (XNIException e) {
  560               // do nothing
  561               // REVISIT: What is the right thing to do? -Ac
  562           }
  563   
  564                   fConfigUpdated = false;
  565   
  566       } // <init>(SymbolTable,XMLGrammarPool)
  567   
  568       //
  569       // Public methods
  570       //
  571       /**
  572        * Sets the input source for the document to parse.
  573        *
  574        * @param inputSource The document's input source.
  575        *
  576        * @exception XMLConfigurationException Thrown if there is a
  577        *                        configuration error when initializing the
  578        *                        parser.
  579        * @exception IOException Thrown on I/O error.
  580        *
  581        * @see #parse(boolean)
  582        */
  583       public void setInputSource(XMLInputSource inputSource)
  584           throws XMLConfigurationException, IOException {
  585   
  586           // REVISIT: this method used to reset all the components and
  587           //          construct the pipeline. Now reset() is called
  588           //          in parse (boolean) just before we parse the document
  589           //          Should this method still throw exceptions..?
  590   
  591           fInputSource = inputSource;
  592   
  593       } // setInputSource(XMLInputSource)
  594   
  595       /**
  596        * Set the locale to use for messages.
  597        *
  598        * @param locale The locale object to use for localization of messages.
  599        *
  600        * @exception XNIException Thrown if the parser does not support the
  601        *                         specified locale.
  602        */
  603       public void setLocale(Locale locale) throws XNIException {
  604           fLocale = locale;
  605           fErrorReporter.setLocale(locale);
  606       } // setLocale(Locale)
  607           /**
  608            * Sets the document handler on the last component in the pipeline
  609            * to receive information about the document.
  610            *
  611            * @param documentHandler   The document handler.
  612            */
  613           public void setDocumentHandler(XMLDocumentHandler documentHandler) {
  614                   fDocumentHandler = documentHandler;
  615                   if (fLastComponent != null) {
  616                           fLastComponent.setDocumentHandler(fDocumentHandler);
  617                           if (fDocumentHandler !=null){
  618                                   fDocumentHandler.setDocumentSource(fLastComponent);
  619                           }
  620                   }
  621           } // setDocumentHandler(XMLDocumentHandler)
  622   
  623           /** Returns the registered document handler. */
  624           public XMLDocumentHandler getDocumentHandler() {
  625                   return fDocumentHandler;
  626           } // getDocumentHandler():XMLDocumentHandler
  627   
  628           /**
  629            * Sets the DTD handler.
  630            *
  631            * @param dtdHandler The DTD handler.
  632            */
  633           public void setDTDHandler(XMLDTDHandler dtdHandler) {
  634                   fDTDHandler = dtdHandler;
  635           } // setDTDHandler(XMLDTDHandler)
  636   
  637           /** Returns the registered DTD handler. */
  638           public XMLDTDHandler getDTDHandler() {
  639                   return fDTDHandler;
  640           } // getDTDHandler():XMLDTDHandler
  641   
  642           /**
  643            * Sets the DTD content model handler.
  644            *
  645            * @param handler The DTD content model handler.
  646            */
  647           public void setDTDContentModelHandler(XMLDTDContentModelHandler handler) {
  648                   fDTDContentModelHandler = handler;
  649           } // setDTDContentModelHandler(XMLDTDContentModelHandler)
  650   
  651           /** Returns the registered DTD content model handler. */
  652           public XMLDTDContentModelHandler getDTDContentModelHandler() {
  653                   return fDTDContentModelHandler;
  654           } // getDTDContentModelHandler():XMLDTDContentModelHandler
  655   
  656           /**
  657            * Sets the resolver used to resolve external entities. The EntityResolver
  658            * interface supports resolution of public and system identifiers.
  659            *
  660            * @param resolver The new entity resolver. Passing a null value will
  661            *                 uninstall the currently installed resolver.
  662            */
  663           public void setEntityResolver(XMLEntityResolver resolver) {
  664                   fProperties.put(ENTITY_RESOLVER, resolver);
  665           } // setEntityResolver(XMLEntityResolver)
  666   
  667           /**
  668            * Return the current entity resolver.
  669            *
  670            * @return The current entity resolver, or null if none
  671            *         has been registered.
  672            * @see #setEntityResolver
  673            */
  674           public XMLEntityResolver getEntityResolver() {
  675                   return (XMLEntityResolver)fProperties.get(ENTITY_RESOLVER);
  676           } // getEntityResolver():XMLEntityResolver
  677   
  678           /**
  679            * Allow an application to register an error event handler.
  680            *
  681            * <p>If the application does not register an error handler, all
  682            * error events reported by the SAX parser will be silently
  683            * ignored; however, normal processing may not continue.  It is
  684            * highly recommended that all SAX applications implement an
  685            * error handler to avoid unexpected bugs.</p>
  686            *
  687            * <p>Applications may register a new or different handler in the
  688            * middle of a parse, and the SAX parser must begin using the new
  689            * handler immediately.</p>
  690            *
  691            * @param errorHandler The error handler.
  692            * @exception java.lang.NullPointerException If the handler
  693            *            argument is null.
  694            * @see #getErrorHandler
  695            */
  696           public void setErrorHandler(XMLErrorHandler errorHandler) {
  697                   fProperties.put(ERROR_HANDLER, errorHandler);
  698           } // setErrorHandler(XMLErrorHandler)
  699   
  700           /**
  701            * Return the current error handler.
  702            *
  703            * @return The current error handler, or null if none
  704            *         has been registered.
  705            * @see #setErrorHandler
  706            */
  707           public XMLErrorHandler getErrorHandler() {
  708                   // REVISIT: Should this be a property?
  709                   return (XMLErrorHandler)fProperties.get(ERROR_HANDLER);
  710           } // getErrorHandler():XMLErrorHandler
  711   
  712   
  713       /**
  714        * If the application decides to terminate parsing before the xml document
  715        * is fully parsed, the application should call this method to free any
  716        * resource allocated during parsing. For example, close all opened streams.
  717        */
  718       public void cleanup() {
  719           fEntityManager.closeReaders();
  720       }
  721   
  722       /**
  723        * Parses the specified input source.
  724        *
  725        * @param source The input source.
  726        *
  727        * @exception XNIException Throws exception on XNI error.
  728        * @exception java.io.IOException Throws exception on i/o error.
  729        */
  730       public void parse(XMLInputSource source) throws XNIException, IOException {
  731   
  732           if (fParseInProgress) {
  733               // REVISIT - need to add new error message
  734               throw new XNIException("FWK005 parse may not be called while parsing.");
  735           }
  736           fParseInProgress = true;
  737   
  738           try {
  739               setInputSource(source);
  740               parse(true);
  741           } catch (XNIException ex) {
  742               if (PRINT_EXCEPTION_STACK_TRACE)
  743                   ex.printStackTrace();
  744               throw ex;
  745           } catch (IOException ex) {
  746               if (PRINT_EXCEPTION_STACK_TRACE)
  747                   ex.printStackTrace();
  748               throw ex;
  749           } catch (RuntimeException ex) {
  750               if (PRINT_EXCEPTION_STACK_TRACE)
  751                   ex.printStackTrace();
  752               throw ex;
  753           } catch (Exception ex) {
  754               if (PRINT_EXCEPTION_STACK_TRACE)
  755                   ex.printStackTrace();
  756               throw new XNIException(ex);
  757           } finally {
  758               fParseInProgress = false;
  759               // close all streams opened by xerces
  760               this.cleanup();
  761           }
  762   
  763       } // parse(InputSource)
  764   
  765       public boolean parse(boolean complete) throws XNIException, IOException {
  766           //
  767           // reset and configure pipeline and set InputSource.
  768           if (fInputSource != null) {
  769               try {
  770                                   fValidationManager.reset();
  771                   fVersionDetector.reset(this);
  772                   resetCommon();
  773   
  774                   short version = fVersionDetector.determineDocVersion(fInputSource);
  775                   if (version == Constants.XML_VERSION_1_1) {
  776                       initXML11Components();
  777                       configureXML11Pipeline();
  778                       resetXML11();
  779                   } else {
  780                       configurePipeline();
  781                       reset();
  782                   }
  783   
  784                   // mark configuration as fixed
  785                   fConfigUpdated = false;
  786   
  787                   // resets and sets the pipeline.
  788                   fVersionDetector.startDocumentParsing((XMLEntityHandler) fCurrentScanner, version);
  789                   fInputSource = null;
  790               } catch (XNIException ex) {
  791                   if (PRINT_EXCEPTION_STACK_TRACE)
  792                       ex.printStackTrace();
  793                   throw ex;
  794               } catch (IOException ex) {
  795                   if (PRINT_EXCEPTION_STACK_TRACE)
  796                       ex.printStackTrace();
  797                   throw ex;
  798               } catch (RuntimeException ex) {
  799                   if (PRINT_EXCEPTION_STACK_TRACE)
  800                       ex.printStackTrace();
  801                   throw ex;
  802               } catch (Exception ex) {
  803                   if (PRINT_EXCEPTION_STACK_TRACE)
  804                       ex.printStackTrace();
  805                   throw new XNIException(ex);
  806               }
  807           }
  808   
  809           try {
  810               return fCurrentScanner.scanDocument(complete);
  811           } catch (XNIException ex) {
  812               if (PRINT_EXCEPTION_STACK_TRACE)
  813                   ex.printStackTrace();
  814               throw ex;
  815           } catch (IOException ex) {
  816               if (PRINT_EXCEPTION_STACK_TRACE)
  817                   ex.printStackTrace();
  818               throw ex;
  819           } catch (RuntimeException ex) {
  820               if (PRINT_EXCEPTION_STACK_TRACE)
  821                   ex.printStackTrace();
  822               throw ex;
  823           } catch (Exception ex) {
  824               if (PRINT_EXCEPTION_STACK_TRACE)
  825                   ex.printStackTrace();
  826               throw new XNIException(ex);
  827           }
  828   
  829       } // parse(boolean):boolean
  830   
  831           /**
  832            * Returns the state of a feature.
  833            *
  834            * @param featureId The feature identifier.
  835                    * @return true if the feature is supported
  836            *
  837            * @throws XMLConfigurationException Thrown for configuration error.
  838            *                                   In general, components should
  839            *                                   only throw this exception if
  840            *                                   it is <strong>really</strong>
  841            *                                   a critical error.
  842            */
  843           public boolean getFeature(String featureId)
  844                   throws XMLConfigurationException {
  845                           // make this feature special
  846           if (featureId.equals(PARSER_SETTINGS)){
  847                   return fConfigUpdated;
  848           }
  849           return super.getFeature(featureId);
  850   
  851           } // getFeature(String):boolean
  852   
  853           /**
  854            * Set the state of a feature.
  855            *
  856            * Set the state of any feature in a SAX2 parser.  The parser
  857            * might not recognize the feature, and if it does recognize
  858            * it, it might not be able to fulfill the request.
  859            *
  860            * @param featureId The unique identifier (URI) of the feature.
  861            * @param state The requested state of the feature (true or false).
  862            *
  863            * @exception com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException If the
  864            *            requested feature is not known.
  865            */
  866           public void setFeature(String featureId, boolean state)
  867                   throws XMLConfigurationException {
  868                   fConfigUpdated = true;
  869                   // forward to every XML 1.0 component
  870                   int count = fComponents.size();
  871                   for (int i = 0; i < count; i++) {
  872                           XMLComponent c = (XMLComponent) fComponents.get(i);
  873                           c.setFeature(featureId, state);
  874                   }
  875                   // forward it to common components
  876                   count = fCommonComponents.size();
  877                   for (int i = 0; i < count; i++) {
  878                           XMLComponent c = (XMLComponent) fCommonComponents.get(i);
  879                           c.setFeature(featureId, state);
  880                   }
  881   
  882                   // forward to every XML 1.1 component
  883                   count = fXML11Components.size();
  884                   for (int i = 0; i < count; i++) {
  885                           XMLComponent c = (XMLComponent) fXML11Components.get(i);
  886                           try{
  887                                   c.setFeature(featureId, state);
  888                           }
  889                           catch (Exception e){
  890                                   // no op
  891                           }
  892                   }
  893                   // save state if noone "objects"
  894                   super.setFeature(featureId, state);
  895   
  896           } // setFeature(String,boolean)
  897   
  898           /**
  899            * setProperty
  900            *
  901            * @param propertyId
  902            * @param value
  903            */
  904           public void setProperty(String propertyId, Object value)
  905                   throws XMLConfigurationException {
  906                   fConfigUpdated = true;
  907                   // forward to every XML 1.0 component
  908                   int count = fComponents.size();
  909                   for (int i = 0; i < count; i++) {
  910                           XMLComponent c = (XMLComponent) fComponents.get(i);
  911                           c.setProperty(propertyId, value);
  912                   }
  913                   // forward it to every common Component
  914                   count = fCommonComponents.size();
  915                   for (int i = 0; i < count; i++) {
  916                           XMLComponent c = (XMLComponent) fCommonComponents.get(i);
  917                           c.setProperty(propertyId, value);
  918                   }
  919                   // forward it to every XML 1.1 component
  920                   count = fXML11Components.size();
  921                   for (int i = 0; i < count; i++) {
  922                           XMLComponent c = (XMLComponent) fXML11Components.get(i);
  923                           try{
  924                                   c.setProperty(propertyId, value);
  925                           }
  926                           catch (Exception e){
  927                                   // ignore it
  928                           }
  929                   }
  930   
  931                   // store value if noone "objects"
  932                   super.setProperty(propertyId, value);
  933   
  934           } // setProperty(String,Object)
  935   
  936   
  937           /** Returns the locale. */
  938           public Locale getLocale() {
  939                   return fLocale;
  940           } // getLocale():Locale
  941   
  942           /**
  943            * reset all XML 1.0 components before parsing and namespace context
  944            */
  945           protected void reset() throws XNIException {
  946                   int count = fComponents.size();
  947                   for (int i = 0; i < count; i++) {
  948                           XMLComponent c = (XMLComponent) fComponents.get(i);
  949                           c.reset(this);
  950                   }
  951   
  952           } // reset()
  953   
  954           /**
  955            * reset all common components before parsing
  956            */
  957           protected void resetCommon() throws XNIException {
  958                   // reset common components
  959                   int count = fCommonComponents.size();
  960                   for (int i = 0; i < count; i++) {
  961                           XMLComponent c = (XMLComponent) fCommonComponents.get(i);
  962                           c.reset(this);
  963                   }
  964   
  965           } // resetCommon()
  966   
  967   
  968           /**
  969            * reset all components before parsing and namespace context
  970            */
  971           protected void resetXML11() throws XNIException {
  972                   // reset every component
  973                   int count = fXML11Components.size();
  974                   for (int i = 0; i < count; i++) {
  975                           XMLComponent c = (XMLComponent) fXML11Components.get(i);
  976                           c.reset(this);
  977                   }
  978   
  979           } // resetXML11()
  980   
  981   
  982       /**
  983        *  Configures the XML 1.1 pipeline.
  984        *  Note: this method also resets the new XML11 components.
  985        */
  986       protected void configureXML11Pipeline() {
  987           if (fCurrentDVFactory != fXML11DatatypeFactory) {
  988               fCurrentDVFactory = fXML11DatatypeFactory;
  989               setProperty(DATATYPE_VALIDATOR_FACTORY, fCurrentDVFactory);
  990           }
  991           if (fCurrentDTDScanner != fXML11DTDScanner) {
  992               fCurrentDTDScanner = fXML11DTDScanner;
  993               setProperty(DTD_SCANNER, fCurrentDTDScanner);
  994                           setProperty(DTD_PROCESSOR, fXML11DTDProcessor);
  995           }
  996   
  997           fXML11DTDScanner.setDTDHandler(fXML11DTDProcessor);
  998           fXML11DTDProcessor.setDTDSource(fXML11DTDScanner);
  999           fXML11DTDProcessor.setDTDHandler(fDTDHandler);
 1000           if (fDTDHandler != null) {
 1001               fDTDHandler.setDTDSource(fXML11DTDProcessor);
 1002           }
 1003   
 1004           fXML11DTDScanner.setDTDContentModelHandler(fXML11DTDProcessor);
 1005           fXML11DTDProcessor.setDTDContentModelSource(fXML11DTDScanner);
 1006           fXML11DTDProcessor.setDTDContentModelHandler(fDTDContentModelHandler);
 1007           if (fDTDContentModelHandler != null) {
 1008               fDTDContentModelHandler.setDTDContentModelSource(fXML11DTDProcessor);
 1009           }
 1010   
 1011           // setup XML 1.1 document pipeline
 1012           if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
 1013               if (fCurrentScanner != fXML11NSDocScanner) {
 1014                   fCurrentScanner = fXML11NSDocScanner;
 1015                   setProperty(DOCUMENT_SCANNER, fXML11NSDocScanner);
 1016                   setProperty(DTD_VALIDATOR, fXML11NSDTDValidator);
 1017               }
 1018   
 1019               fXML11NSDocScanner.setDTDValidator(fXML11NSDTDValidator);
 1020               fXML11NSDocScanner.setDocumentHandler(fXML11NSDTDValidator);
 1021               fXML11NSDTDValidator.setDocumentSource(fXML11NSDocScanner);
 1022               fXML11NSDTDValidator.setDocumentHandler(fDocumentHandler);
 1023   
 1024               if (fDocumentHandler != null) {
 1025                   fDocumentHandler.setDocumentSource(fXML11NSDTDValidator);
 1026               }
 1027               fLastComponent = fXML11NSDTDValidator;
 1028   
 1029           } else {
 1030                           // create components
 1031                             if (fXML11DocScanner == null) {
 1032                                           // non namespace document pipeline
 1033                                           fXML11DocScanner = new XML11DocumentScannerImpl();
 1034                                           addXML11Component(fXML11DocScanner);
 1035                                           fXML11DTDValidator = new XML11DTDValidator();
 1036                                           addXML11Component(fXML11DTDValidator);
 1037                             }
 1038               if (fCurrentScanner != fXML11DocScanner) {
 1039                   fCurrentScanner = fXML11DocScanner;
 1040                   setProperty(DOCUMENT_SCANNER, fXML11DocScanner);
 1041                   setProperty(DTD_VALIDATOR, fXML11DTDValidator);
 1042               }
 1043               fXML11DocScanner.setDocumentHandler(fXML11DTDValidator);
 1044               fXML11DTDValidator.setDocumentSource(fXML11DocScanner);
 1045               fXML11DTDValidator.setDocumentHandler(fDocumentHandler);
 1046   
 1047               if (fDocumentHandler != null) {
 1048                   fDocumentHandler.setDocumentSource(fXML11DTDValidator);
 1049               }
 1050               fLastComponent = fXML11DTDValidator;
 1051           }
 1052   
 1053           // setup document pipeline
 1054           if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) {
 1055               // If schema validator was not in the pipeline insert it.
 1056               if (fSchemaValidator == null) {
 1057                   fSchemaValidator = new XMLSchemaValidator();
 1058                   // add schema component
 1059                   setProperty(SCHEMA_VALIDATOR, fSchemaValidator);
 1060                                   addCommonComponent(fSchemaValidator);
 1061                                   fSchemaValidator.reset(this);
 1062                   // add schema message formatter
 1063                   if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {
 1064                       XSMessageFormatter xmft = new XSMessageFormatter();
 1065                       fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft);
 1066                   }
 1067               }
 1068   
 1069               fLastComponent.setDocumentHandler(fSchemaValidator);
 1070               fSchemaValidator.setDocumentSource(fLastComponent);
 1071               fSchemaValidator.setDocumentHandler(fDocumentHandler);
 1072               if (fDocumentHandler != null) {
 1073                   fDocumentHandler.setDocumentSource(fSchemaValidator);
 1074               }
 1075               fLastComponent = fSchemaValidator;
 1076           }
 1077   
 1078       } // configureXML11Pipeline()
 1079   
 1080       /** Configures the pipeline. */
 1081       protected void configurePipeline() {
 1082           if (fCurrentDVFactory != fDatatypeValidatorFactory) {
 1083               fCurrentDVFactory = fDatatypeValidatorFactory;
 1084               // use XML 1.0 datatype library
 1085               setProperty(DATATYPE_VALIDATOR_FACTORY, fCurrentDVFactory);
 1086           }
 1087   
 1088           // setup DTD pipeline
 1089           if (fCurrentDTDScanner != fDTDScanner) {
 1090               fCurrentDTDScanner = fDTDScanner;
 1091               setProperty(DTD_SCANNER, fCurrentDTDScanner);
 1092               setProperty(DTD_PROCESSOR, fDTDProcessor);
 1093           }
 1094           fDTDScanner.setDTDHandler(fDTDProcessor);
 1095           fDTDProcessor.setDTDSource(fDTDScanner);
 1096           fDTDProcessor.setDTDHandler(fDTDHandler);
 1097           if (fDTDHandler != null) {
 1098               fDTDHandler.setDTDSource(fDTDProcessor);
 1099           }
 1100   
 1101           fDTDScanner.setDTDContentModelHandler(fDTDProcessor);
 1102           fDTDProcessor.setDTDContentModelSource(fDTDScanner);
 1103           fDTDProcessor.setDTDContentModelHandler(fDTDContentModelHandler);
 1104           if (fDTDContentModelHandler != null) {
 1105               fDTDContentModelHandler.setDTDContentModelSource(fDTDProcessor);
 1106           }
 1107   
 1108           // setup document pipeline
 1109           if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
 1110               if (fCurrentScanner != fNamespaceScanner) {
 1111                   fCurrentScanner = fNamespaceScanner;
 1112                   setProperty(DOCUMENT_SCANNER, fNamespaceScanner);
 1113                   setProperty(DTD_VALIDATOR, fDTDValidator);
 1114               }
 1115               fNamespaceScanner.setDTDValidator(fDTDValidator);
 1116               fNamespaceScanner.setDocumentHandler(fDTDValidator);
 1117               fDTDValidator.setDocumentSource(fNamespaceScanner);
 1118               fDTDValidator.setDocumentHandler(fDocumentHandler);
 1119               if (fDocumentHandler != null) {
 1120                   fDocumentHandler.setDocumentSource(fDTDValidator);
 1121               }
 1122               fLastComponent = fDTDValidator;
 1123           } else {
 1124               // create components
 1125               if (fNonNSScanner == null) {
 1126                   fNonNSScanner = new XMLDocumentScannerImpl();
 1127                   fNonNSDTDValidator = new XMLDTDValidator();
 1128                   // add components
 1129                   addComponent((XMLComponent) fNonNSScanner);
 1130                   addComponent((XMLComponent) fNonNSDTDValidator);
 1131               }
 1132               if (fCurrentScanner != fNonNSScanner) {
 1133                   fCurrentScanner = fNonNSScanner;
 1134                   setProperty(DOCUMENT_SCANNER, fNonNSScanner);
 1135                   setProperty(DTD_VALIDATOR, fNonNSDTDValidator);
 1136               }
 1137   
 1138               fNonNSScanner.setDocumentHandler(fNonNSDTDValidator);
 1139               fNonNSDTDValidator.setDocumentSource(fNonNSScanner);
 1140               fNonNSDTDValidator.setDocumentHandler(fDocumentHandler);
 1141               if (fDocumentHandler != null) {
 1142                   fDocumentHandler.setDocumentSource(fNonNSDTDValidator);
 1143               }
 1144               fLastComponent = fNonNSDTDValidator;
 1145           }
 1146   
 1147           // add XML Schema validator if needed
 1148           if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) {
 1149               // If schema validator was not in the pipeline insert it.
 1150               if (fSchemaValidator == null) {
 1151                   fSchemaValidator = new XMLSchemaValidator();
 1152                   // add schema component
 1153                   setProperty(SCHEMA_VALIDATOR, fSchemaValidator);
 1154                   addCommonComponent(fSchemaValidator);
 1155                   fSchemaValidator.reset(this);
 1156                   // add schema message formatter
 1157                   if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {
 1158                       XSMessageFormatter xmft = new XSMessageFormatter();
 1159                       fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft);
 1160                   }
 1161   
 1162               }
 1163               fLastComponent.setDocumentHandler(fSchemaValidator);
 1164               fSchemaValidator.setDocumentSource(fLastComponent);
 1165               fSchemaValidator.setDocumentHandler(fDocumentHandler);
 1166               if (fDocumentHandler != null) {
 1167                   fDocumentHandler.setDocumentSource(fSchemaValidator);
 1168               }
 1169               fLastComponent = fSchemaValidator;
 1170           }
 1171       } // configurePipeline()
 1172   
 1173   
 1174       // features and properties
 1175   
 1176       /**
 1177        * Check a feature. If feature is know and supported, this method simply
 1178        * returns. Otherwise, the appropriate exception is thrown.
 1179        *
 1180        * @param featureId The unique identifier (URI) of the feature.
 1181        *
 1182        * @throws XMLConfigurationException Thrown for configuration error.
 1183        *                                   In general, components should
 1184        *                                   only throw this exception if
 1185        *                                   it is <strong>really</strong>
 1186        *                                   a critical error.
 1187        */
 1188       protected void checkFeature(String featureId) throws XMLConfigurationException {
 1189   
 1190           //
 1191           // Xerces Features
 1192           //
 1193   
 1194           if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) {
 1195               final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length();
 1196   
 1197               //
 1198               // http://apache.org/xml/features/validation/dynamic
 1199               //   Allows the parser to validate a document only when it
 1200               //   contains a grammar. Validation is turned on/off based
 1201               //   on each document instance, automatically.
 1202               //
 1203               if (suffixLength == Constants.DYNAMIC_VALIDATION_FEATURE.length() &&
 1204                   featureId.endsWith(Constants.DYNAMIC_VALIDATION_FEATURE)) {
 1205                   return;
 1206               }
 1207   
 1208               //
 1209               // http://apache.org/xml/features/validation/default-attribute-values
 1210               //
 1211               if (suffixLength == Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE.length() &&
 1212                   featureId.endsWith(Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE)) {
 1213                   // REVISIT
 1214                   short type = XMLConfigurationException.NOT_SUPPORTED;
 1215                   throw new XMLConfigurationException(type, featureId);
 1216               }
 1217               //
 1218               // http://apache.org/xml/features/validation/default-attribute-values
 1219               //
 1220               if (suffixLength == Constants.VALIDATE_CONTENT_MODELS_FEATURE.length() &&
 1221                   featureId.endsWith(Constants.VALIDATE_CONTENT_MODELS_FEATURE)) {
 1222                   // REVISIT
 1223                   short type = XMLConfigurationException.NOT_SUPPORTED;
 1224                   throw new XMLConfigurationException(type, featureId);
 1225               }
 1226               //
 1227               // http://apache.org/xml/features/validation/nonvalidating/load-dtd-grammar
 1228               //
 1229               if (suffixLength == Constants.LOAD_DTD_GRAMMAR_FEATURE.length() &&
 1230                   featureId.endsWith(Constants.LOAD_DTD_GRAMMAR_FEATURE)) {
 1231                   return;
 1232               }
 1233               //
 1234               // http://apache.org/xml/features/validation/nonvalidating/load-external-dtd
 1235               //
 1236               if (suffixLength == Constants.LOAD_EXTERNAL_DTD_FEATURE.length() &&
 1237                   featureId.endsWith(Constants.LOAD_EXTERNAL_DTD_FEATURE)) {
 1238                   return;
 1239               }
 1240   
 1241               //
 1242               // http://apache.org/xml/features/validation/default-attribute-values
 1243               //
 1244               if (suffixLength == Constants.VALIDATE_DATATYPES_FEATURE.length() &&
 1245                   featureId.endsWith(Constants.VALIDATE_DATATYPES_FEATURE)) {
 1246                   short type = XMLConfigurationException.NOT_SUPPORTED;
 1247                   throw new XMLConfigurationException(type, featureId);
 1248               }
 1249   
 1250               //
 1251               // http://apache.org/xml/features/validation/schema
 1252               //   Lets the user turn Schema validation support on/off.
 1253               //
 1254               if (suffixLength == Constants.SCHEMA_VALIDATION_FEATURE.length() &&
 1255                   featureId.endsWith(Constants.SCHEMA_VALIDATION_FEATURE)) {
 1256                   return;
 1257               }
 1258               // activate full schema checking
 1259               if (suffixLength == Constants.SCHEMA_FULL_CHECKING.length() &&
 1260                   featureId.endsWith(Constants.SCHEMA_FULL_CHECKING)) {
 1261                   return;
 1262               }
 1263               // Feature identifier: expose schema normalized value
 1264               //  http://apache.org/xml/features/validation/schema/normalized-value
 1265               if (suffixLength == Constants.SCHEMA_NORMALIZED_VALUE.length() &&
 1266                   featureId.endsWith(Constants.SCHEMA_NORMALIZED_VALUE)) {
 1267                   return;
 1268               }
 1269               // Feature identifier: send element default value via characters()
 1270               // http://apache.org/xml/features/validation/schema/element-default
 1271               if (suffixLength == Constants.SCHEMA_ELEMENT_DEFAULT.length() &&
 1272                   featureId.endsWith(Constants.SCHEMA_ELEMENT_DEFAULT)) {
 1273                   return;
 1274               }
 1275   
 1276               // special performance feature: only component manager is allowed to set it.
 1277               if (suffixLength == Constants.PARSER_SETTINGS.length() &&
 1278                   featureId.endsWith(Constants.PARSER_SETTINGS)) {
 1279                   short type = XMLConfigurationException.NOT_SUPPORTED;
 1280                   throw new XMLConfigurationException(type, featureId);
 1281               }
 1282   
 1283           }
 1284   
 1285           //
 1286           // Not recognized
 1287           //
 1288   
 1289           super.checkFeature(featureId);
 1290   
 1291       } // checkFeature(String)
 1292   
 1293       /**
 1294        * Check a property. If the property is know and supported, this method
 1295        * simply returns. Otherwise, the appropriate exception is thrown.
 1296        *
 1297        * @param propertyId The unique identifier (URI) of the property
 1298        *                   being set.
 1299        *
 1300        * @throws XMLConfigurationException Thrown for configuration error.
 1301        *                                   In general, components should
 1302        *                                   only throw this exception if
 1303        *                                   it is <strong>really</strong>
 1304        *                                   a critical error.
 1305        */
 1306       protected void checkProperty(String propertyId) throws XMLConfigurationException {
 1307   
 1308           //
 1309           // Xerces Properties
 1310           //
 1311   
 1312           if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
 1313               final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length();
 1314   
 1315               if (suffixLength == Constants.DTD_SCANNER_PROPERTY.length() &&
 1316                   propertyId.endsWith(Constants.DTD_SCANNER_PROPERTY)) {
 1317                   return;
 1318               }
 1319               if (suffixLength == Constants.SCHEMA_LOCATION.length() &&
 1320                   propertyId.endsWith(Constants.SCHEMA_LOCATION)) {
 1321                   return;
 1322               }
 1323               if (suffixLength == Constants.SCHEMA_NONS_LOCATION.length() &&
 1324                   propertyId.endsWith(Constants.SCHEMA_NONS_LOCATION)) {
 1325                   return;
 1326               }
 1327           }
 1328   
 1329           if (propertyId.startsWith(Constants.JAXP_PROPERTY_PREFIX)) {
 1330               final int suffixLength = propertyId.length() - Constants.JAXP_PROPERTY_PREFIX.length();
 1331   
 1332               if (suffixLength == Constants.SCHEMA_SOURCE.length() &&
 1333                   propertyId.endsWith(Constants.SCHEMA_SOURCE)) {
 1334                   return;
 1335               }
 1336           }
 1337   
 1338           // special cases
 1339           if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) {
 1340               final int suffixLength = propertyId.length() - Constants.SAX_PROPERTY_PREFIX.length();
 1341   
 1342               //
 1343               // http://xml.org/sax/properties/xml-string
 1344               // Value type: String
 1345               // Access: read-only
 1346               //   Get the literal string of characters associated with the
 1347               //   current event.  If the parser recognises and supports this
 1348               //   property but is not currently parsing text, it should return
 1349               //   null (this is a good way to check for availability before the
 1350               //   parse begins).
 1351               //
 1352               if (suffixLength == Constants.XML_STRING_PROPERTY.length() &&
 1353                   propertyId.endsWith(Constants.XML_STRING_PROPERTY)) {
 1354                   // REVISIT - we should probably ask xml-dev for a precise
 1355                   // definition of what this is actually supposed to return, and
 1356                   // in exactly which circumstances.
 1357                   short type = XMLConfigurationException.NOT_SUPPORTED;
 1358                   throw new XMLConfigurationException(type, propertyId);
 1359               }
 1360           }
 1361   
 1362           //
 1363           // Not recognized
 1364           //
 1365   
 1366           super.checkProperty(propertyId);
 1367   
 1368       } // checkProperty(String)
 1369   
 1370   
 1371       /**
 1372        * Adds a component to the parser configuration. This method will
 1373        * also add all of the component's recognized features and properties
 1374        * to the list of default recognized features and properties.
 1375        *
 1376        * @param component The component to add.
 1377        */
 1378       protected void addComponent(XMLComponent component) {
 1379   
 1380           // don't add a component more than once
 1381           if (fComponents.contains(component)) {
 1382               return;
 1383           }
 1384           fComponents.add(component);
 1385           addRecognizedParamsAndSetDefaults(component);
 1386   
 1387       } // addComponent(XMLComponent)
 1388   
 1389       /**
 1390        * Adds common component to the parser configuration. This method will
 1391        * also add all of the component's recognized features and properties
 1392        * to the list of default recognized features and properties.
 1393        *
 1394        * @param component The component to add.
 1395        */
 1396       protected void addCommonComponent(XMLComponent component) {
 1397   
 1398           // don't add a component more than once
 1399           if (fCommonComponents.contains(component)) {
 1400               return;
 1401           }
 1402           fCommonComponents.add(component);
 1403           addRecognizedParamsAndSetDefaults(component);
 1404   
 1405       } // addCommonComponent(XMLComponent)
 1406   
 1407       /**
 1408        * Adds an XML 1.1 component to the parser configuration. This method will
 1409        * also add all of the component's recognized features and properties
 1410        * to the list of default recognized features and properties.
 1411        *
 1412        * @param component The component to add.
 1413        */
 1414       protected void addXML11Component(XMLComponent component) {
 1415   
 1416           // don't add a component more than once
 1417           if (fXML11Components.contains(component)) {
 1418               return;
 1419           }
 1420           fXML11Components.add(component);
 1421           addRecognizedParamsAndSetDefaults(component);
 1422   
 1423       } // addXML11Component(XMLComponent)
 1424   
 1425       /**
 1426        * Adds all of the component's recognized features and properties
 1427        * to the list of default recognized features and properties, and
 1428        * sets default values on the configuration for features and
 1429        * properties which were previously absent from the configuration.
 1430        *
 1431        * @param component The component whose recognized features
 1432        * and properties will be added to the configuration
 1433        */
 1434       protected void addRecognizedParamsAndSetDefaults(XMLComponent component) {
 1435   
 1436           // register component's recognized features
 1437           String[] recognizedFeatures = component.getRecognizedFeatures();
 1438           addRecognizedFeatures(recognizedFeatures);
 1439   
 1440           // register component's recognized properties
 1441           String[] recognizedProperties = component.getRecognizedProperties();
 1442           addRecognizedProperties(recognizedProperties);
 1443   
 1444           // set default values
 1445           if (recognizedFeatures != null) {
 1446               for (int i = 0; i < recognizedFeatures.length; ++i) {
 1447                   String featureId = recognizedFeatures[i];
 1448                   Boolean state = component.getFeatureDefault(featureId);
 1449                   if (state != null) {
 1450                       // Do not overwrite values already set on the configuration.
 1451                       if (!fFeatures.containsKey(featureId)) {
 1452                           fFeatures.put(featureId, state);
 1453                           // For newly added components who recognize this feature
 1454                           // but did not offer a default value, we need to make
 1455                           // sure these components will get an opportunity to read
 1456                           // the value before parsing begins.
 1457                           fConfigUpdated = true;
 1458                       }
 1459                   }
 1460               }
 1461           }
 1462           if (recognizedProperties != null) {
 1463               for (int i = 0; i < recognizedProperties.length; ++i) {
 1464                   String propertyId = recognizedProperties[i];
 1465                   Object value = component.getPropertyDefault(propertyId);
 1466                   if (value != null) {
 1467                       // Do not overwrite values already set on the configuration.
 1468                       if (!fProperties.containsKey(propertyId)) {
 1469                           fProperties.put(propertyId, value);
 1470                           // For newly added components who recognize this property
 1471                           // but did not offer a default value, we need to make
 1472                           // sure these components will get an opportunity to read
 1473                           // the value before parsing begins.
 1474                           fConfigUpdated = true;
 1475                       }
 1476                   }
 1477               }
 1478           }
 1479       }
 1480   
 1481       private void initXML11Components() {
 1482           if (!f11Initialized) {
 1483   
 1484               // create datatype factory
 1485               fXML11DatatypeFactory = DTDDVFactory.getInstance(XML11_DATATYPE_VALIDATOR_FACTORY);
 1486   
 1487               // setup XML 1.1 DTD pipeline
 1488               fXML11DTDScanner = new XML11DTDScannerImpl();
 1489               addXML11Component(fXML11DTDScanner);
 1490               fXML11DTDProcessor = new XML11DTDProcessor();
 1491               addXML11Component(fXML11DTDProcessor);
 1492   
 1493               // setup XML 1.1. document pipeline - namespace aware
 1494               fXML11NSDocScanner = new XML11NSDocumentScannerImpl();
 1495               addXML11Component(fXML11NSDocScanner);
 1496               fXML11NSDTDValidator = new XML11NSDTDValidator();
 1497               addXML11Component(fXML11NSDTDValidator);
 1498   
 1499               f11Initialized = true;
 1500           }
 1501       }
 1502   
 1503       /**
 1504        * Returns the state of a feature. This method calls getFeature()
 1505        * on ParserConfigurationSettings, bypassing getFeature() on this
 1506        * class.
 1507        */
 1508       boolean getFeature0(String featureId)
 1509           throws XMLConfigurationException {
 1510           return super.getFeature(featureId);
 1511       }
 1512   
 1513   } // class XML11Configuration

Save This Page
Home » openjdk-7 » com.sun.org.apache.xerces.internal » parsers » [javadoc | source]