Home » Xerces-J-src.2.9.1 » org.apache.xerces » parsers » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    * 
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    * 
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   
   18   package org.apache.xerces.parsers;
   19   
   20   import java.io.IOException;
   21   import java.util.Locale;
   22   
   23   import org.apache.xerces.impl.Constants;
   24   import org.apache.xerces.impl.XMLDTDScannerImpl;
   25   import org.apache.xerces.impl.XMLDocumentScannerImpl;
   26   import org.apache.xerces.impl.XMLEntityManager;
   27   import org.apache.xerces.impl.XMLErrorReporter;
   28   import org.apache.xerces.impl.XMLNSDocumentScannerImpl;
   29   import org.apache.xerces.impl.dv.DTDDVFactory;
   30   import org.apache.xerces.impl.msg.XMLMessageFormatter;
   31   import org.apache.xerces.impl.validation.ValidationManager;
   32   import org.apache.xerces.util.SymbolTable;
   33   import org.apache.xerces.xni.XMLLocator;
   34   import org.apache.xerces.xni.XNIException;
   35   import org.apache.xerces.xni.grammars.XMLGrammarPool;
   36   import org.apache.xerces.xni.parser.XMLComponent;
   37   import org.apache.xerces.xni.parser.XMLComponentManager;
   38   import org.apache.xerces.xni.parser.XMLConfigurationException;
   39   import org.apache.xerces.xni.parser.XMLDTDScanner;
   40   import org.apache.xerces.xni.parser.XMLDocumentScanner;
   41   import org.apache.xerces.xni.parser.XMLInputSource;
   42   import org.apache.xerces.xni.parser.XMLPullParserConfiguration;
   43   
   44   /**
   45    * This is the non validating parser configuration. It extends the basic
   46    * configuration with the set of following parser components:
   47    * Document scanner, DTD scanner, namespace binder, document handler.
   48    * <p>
   49    * Xerces parser that uses this configuration is <strong>not</strong> <a href="http://www.w3.org/TR/REC-xml#sec-conformance">conformant</a> 
   50    * non-validating XML processor, since conformant non-validating processor is required  
   51    * to process "all the declarations they read in the internal DTD subset ... must use the information in those declarations to normalize attribute values, 
   52    * include the replacement text of internal entities, and supply default attribute values".
   53    * 
   54    * @author Elena Litani, IBM
   55    * @version $Id: NonValidatingConfiguration.java 447239 2006-09-18 05:08:26Z mrglavas $
   56    */
   57   public class NonValidatingConfiguration
   58       extends BasicParserConfiguration 
   59       implements XMLPullParserConfiguration {
   60   
   61       //
   62       // Constants
   63       //
   64   
   65       // feature identifiers
   66   
   67       /** Feature identifier: warn on duplicate attribute definition. */
   68       protected static final String WARN_ON_DUPLICATE_ATTDEF =
   69           Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE;
   70   
   71       /** Feature identifier: warn on duplicate entity definition. */
   72       protected static final String WARN_ON_DUPLICATE_ENTITYDEF =
   73           Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ENTITYDEF_FEATURE;
   74       
   75       /** Feature identifier: warn on undeclared element definition. */
   76       protected static final String WARN_ON_UNDECLARED_ELEMDEF =
   77           Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_UNDECLARED_ELEMDEF_FEATURE;
   78       
   79       /** Feature identifier: allow Java encodings. */
   80       protected static final String ALLOW_JAVA_ENCODINGS = 
   81           Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE;
   82       
   83       /** Feature identifier: continue after fatal error. */
   84       protected static final String CONTINUE_AFTER_FATAL_ERROR = 
   85           Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE;
   86   
   87       /** Feature identifier: load external DTD. */
   88       protected static final String LOAD_EXTERNAL_DTD =
   89           Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE;
   90   
   91       /** Feature identifier: notify built-in refereces. */
   92       protected static final String NOTIFY_BUILTIN_REFS =
   93           Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_BUILTIN_REFS_FEATURE;
   94       
   95       /** Feature identifier: notify character refereces. */
   96       protected static final String NOTIFY_CHAR_REFS =
   97           Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_CHAR_REFS_FEATURE;
   98       
   99   
  100       /** Feature identifier: expose schema normalized value */
  101       protected static final String NORMALIZE_DATA =
  102       Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE;
  103   
  104   
  105       /** Feature identifier: send element default value via characters() */
  106       protected static final String SCHEMA_ELEMENT_DEFAULT =
  107       Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_ELEMENT_DEFAULT;
  108   
  109       // property identifiers
  110   
  111       /** Property identifier: error reporter. */
  112       protected static final String ERROR_REPORTER = 
  113           Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
  114   
  115       /** Property identifier: entity manager. */
  116       protected static final String ENTITY_MANAGER = 
  117           Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;
  118       
  119       /** Property identifier document scanner: */
  120       protected static final String DOCUMENT_SCANNER = 
  121           Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_SCANNER_PROPERTY;
  122   
  123       /** Property identifier: DTD scanner. */
  124       protected static final String DTD_SCANNER = 
  125           Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY;
  126   
  127       /** Property identifier: grammar pool. */
  128       protected static final String XMLGRAMMAR_POOL = 
  129           Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY;
  130       
  131       /** Property identifier: DTD validator. */
  132       protected static final String DTD_VALIDATOR = 
  133           Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_VALIDATOR_PROPERTY;
  134   
  135       /** Property identifier: namespace binder. */
  136       protected static final String NAMESPACE_BINDER =
  137           Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_BINDER_PROPERTY;
  138   
  139       /** Property identifier: datatype validator factory. */
  140       protected static final String DATATYPE_VALIDATOR_FACTORY = 
  141           Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY;
  142   
  143       protected static final String VALIDATION_MANAGER =
  144           Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
  145   
  146       /** Property identifier: XML Schema validator. */
  147       protected static final String SCHEMA_VALIDATOR =
  148           Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_VALIDATOR_PROPERTY;
  149   
  150   
  151       // debugging
  152   
  153       /** Set to true and recompile to print exception stack trace. */
  154       private static final boolean PRINT_EXCEPTION_STACK_TRACE = false;
  155   
  156       //
  157       // Data
  158       //
  159   
  160       // components (non-configurable)
  161   
  162       /** Grammar pool. */
  163       protected XMLGrammarPool fGrammarPool;
  164   
  165       /** Datatype validator factory. */
  166       protected DTDDVFactory fDatatypeValidatorFactory;
  167   
  168       // components (configurable)
  169   
  170       /** Error reporter. */
  171       protected XMLErrorReporter fErrorReporter;
  172   
  173       /** Entity manager. */
  174       protected XMLEntityManager fEntityManager;
  175   
  176       /** Document scanner. */
  177       protected XMLDocumentScanner fScanner;
  178   
  179       /** Input Source */
  180       protected XMLInputSource fInputSource;
  181   
  182       /** DTD scanner. */
  183       protected XMLDTDScanner fDTDScanner;
  184   
  185   
  186       protected ValidationManager fValidationManager;
  187   
  188       // private data
  189   
  190       /** Document scanner that does namespace binding. */
  191       private XMLNSDocumentScannerImpl fNamespaceScanner;
  192   
  193       /** Default Xerces implementation of scanner*/
  194       private XMLDocumentScannerImpl fNonNSScanner;
  195       
  196       
  197   	/** fConfigUpdated is set to true if there has been any change to the configuration settings, 
  198   	 * i.e a feature or a property was changed.
  199   	 */
  200   	protected boolean fConfigUpdated = false;
  201   
  202   
  203       // state
  204   
  205       /** Locator */
  206       protected XMLLocator fLocator;
  207   
  208       /** 
  209        * True if a parse is in progress. This state is needed because
  210        * some features/properties cannot be set while parsing (e.g.
  211        * validation and namespaces).
  212        */
  213       protected boolean fParseInProgress = false;
  214   
  215       //
  216       // Constructors
  217       //
  218   
  219       /** Default constructor. */
  220       public NonValidatingConfiguration() {
  221           this(null, null, null);
  222       } // <init>()
  223   
  224       /** 
  225        * Constructs a parser configuration using the specified symbol table. 
  226        *
  227        * @param symbolTable The symbol table to use.
  228        */
  229       public NonValidatingConfiguration(SymbolTable symbolTable) {
  230           this(symbolTable, null, null);
  231       } // <init>(SymbolTable)
  232   
  233       /**
  234        * Constructs a parser configuration using the specified symbol table and
  235        * grammar pool.
  236        * <p>
  237        * <strong>REVISIT:</strong> 
  238        * Grammar pool will be updated when the new validation engine is
  239        * implemented.
  240        *
  241        * @param symbolTable The symbol table to use.
  242        * @param grammarPool The grammar pool to use.
  243        */
  244       public NonValidatingConfiguration(SymbolTable symbolTable,
  245                                          XMLGrammarPool grammarPool) {
  246           this(symbolTable, grammarPool, null);
  247       } // <init>(SymbolTable,XMLGrammarPool)
  248   
  249       /**
  250        * Constructs a parser configuration using the specified symbol table,
  251        * grammar pool, and parent settings.
  252        * <p>
  253        * <strong>REVISIT:</strong> 
  254        * Grammar pool will be updated when the new validation engine is
  255        * implemented.
  256        *
  257        * @param symbolTable    The symbol table to use.
  258        * @param grammarPool    The grammar pool to use.
  259        * @param parentSettings The parent settings.
  260        */
  261       public NonValidatingConfiguration(SymbolTable symbolTable,
  262                                          XMLGrammarPool grammarPool,
  263                                          XMLComponentManager parentSettings) {
  264           super(symbolTable, parentSettings);
  265   
  266           // add default recognized features
  267           final String[] recognizedFeatures = {        	
  268           	PARSER_SETTINGS,
  269   			NAMESPACES,
  270               //WARN_ON_DUPLICATE_ATTDEF,     // from XMLDTDScannerImpl
  271               //WARN_ON_UNDECLARED_ELEMDEF,   // from XMLDTDScannerImpl
  272               //ALLOW_JAVA_ENCODINGS,         // from XMLEntityManager
  273               CONTINUE_AFTER_FATAL_ERROR,
  274               //LOAD_EXTERNAL_DTD,    // from XMLDTDScannerImpl
  275               //NOTIFY_BUILTIN_REFS,  // from XMLDocumentFragmentScannerImpl
  276               //NOTIFY_CHAR_REFS,		// from XMLDocumentFragmentScannerImpl
  277               //WARN_ON_DUPLICATE_ENTITYDEF   // from XMLEntityManager
  278           };
  279           addRecognizedFeatures(recognizedFeatures);
  280   
  281           // set state for default features
  282           //setFeature(WARN_ON_DUPLICATE_ATTDEF, false);  // from XMLDTDScannerImpl
  283           //setFeature(WARN_ON_UNDECLARED_ELEMDEF, false);    // from XMLDTDScannerImpl
  284           //setFeature(ALLOW_JAVA_ENCODINGS, false);      // from XMLEntityManager
  285           fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE);
  286   		fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);
  287   		fFeatures.put(NAMESPACES, Boolean.TRUE);
  288           //setFeature(LOAD_EXTERNAL_DTD, true);      // from XMLDTDScannerImpl
  289           //setFeature(NOTIFY_BUILTIN_REFS, false);   // from XMLDocumentFragmentScannerImpl
  290           //setFeature(NOTIFY_CHAR_REFS, false);      // from XMLDocumentFragmentScannerImpl
  291           //setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false);   // from XMLEntityManager
  292   
  293           // add default recognized properties
  294           final String[] recognizedProperties = {
  295               ERROR_REPORTER,             
  296               ENTITY_MANAGER, 
  297               DOCUMENT_SCANNER,
  298               DTD_SCANNER,
  299               DTD_VALIDATOR,
  300               NAMESPACE_BINDER,
  301               XMLGRAMMAR_POOL,   
  302               DATATYPE_VALIDATOR_FACTORY,
  303               VALIDATION_MANAGER
  304           };
  305           addRecognizedProperties(recognizedProperties);
  306   	
  307           fGrammarPool = grammarPool;
  308           if(fGrammarPool != null){
  309   			fProperties.put(XMLGRAMMAR_POOL, fGrammarPool);
  310           }
  311   
  312           fEntityManager = createEntityManager();
  313   		fProperties.put(ENTITY_MANAGER, fEntityManager);
  314           addComponent(fEntityManager);
  315   
  316           fErrorReporter = createErrorReporter();
  317           fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());
  318   		fProperties.put(ERROR_REPORTER, fErrorReporter);
  319           addComponent(fErrorReporter);
  320   
  321           // this configuration delays creation of the scanner
  322           // till it is known if namespace processing should be performed
  323   
  324           fDTDScanner = createDTDScanner();
  325           if (fDTDScanner != null) {
  326   			fProperties.put(DTD_SCANNER, fDTDScanner);
  327               if (fDTDScanner instanceof XMLComponent) {
  328                   addComponent((XMLComponent)fDTDScanner);
  329               }
  330           }
  331   
  332           fDatatypeValidatorFactory = createDatatypeValidatorFactory();
  333           if (fDatatypeValidatorFactory != null) {
  334   			fProperties.put(DATATYPE_VALIDATOR_FACTORY,
  335                           fDatatypeValidatorFactory);
  336           }
  337           fValidationManager = createValidationManager();
  338   
  339           if (fValidationManager != null) {
  340   			fProperties.put(VALIDATION_MANAGER, fValidationManager);
  341           }
  342           // add message formatters
  343           if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
  344               XMLMessageFormatter xmft = new XMLMessageFormatter();
  345               fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
  346               fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
  347           }
  348           
  349   		fConfigUpdated = false;
  350   
  351           // set locale
  352           try {
  353               setLocale(Locale.getDefault());
  354           }
  355           catch (XNIException e) {
  356               // do nothing
  357               // REVISIT: What is the right thing to do? -Ac
  358           }
  359   
  360       } // <init>(SymbolTable,XMLGrammarPool)
  361   
  362       //
  363       // Public methods
  364       //
  365   	public void setFeature(String featureId, boolean state)
  366   		throws XMLConfigurationException {
  367   		fConfigUpdated = true;
  368   		super.setFeature(featureId, state);
  369   	}
  370   	
  371   	public void setProperty(String propertyId, Object value)
  372   		throws XMLConfigurationException {
  373   		fConfigUpdated = true;
  374   		super.setProperty(propertyId, value);
  375   		}
  376       /**
  377        * Set the locale to use for messages.
  378        *
  379        * @param locale The locale object to use for localization of messages.
  380        *
  381        * @exception XNIException Thrown if the parser does not support the
  382        *                         specified locale.
  383        */
  384       public void setLocale(Locale locale) throws XNIException {
  385           super.setLocale(locale);
  386           fErrorReporter.setLocale(locale);
  387       } // setLocale(Locale)
  388       
  389   	public boolean getFeature(String featureId)
  390   		throws XMLConfigurationException {
  391   			// make this feature special
  392   		if (featureId.equals(PARSER_SETTINGS)){
  393   			return fConfigUpdated;
  394   		}
  395   		return super.getFeature(featureId);
  396   
  397   	} // getFeature(String):boolean
  398       //
  399       // XMLPullParserConfiguration methods
  400       //
  401   
  402       // parsing
  403   
  404       /**
  405        * Sets the input source for the document to parse.
  406        *
  407        * @param inputSource The document's input source.
  408        *
  409        * @exception XMLConfigurationException Thrown if there is a 
  410        *                        configuration error when initializing the
  411        *                        parser.
  412        * @exception IOException Thrown on I/O error.
  413        *
  414        * @see #parse(boolean)
  415        */
  416       public void setInputSource(XMLInputSource inputSource)
  417           throws XMLConfigurationException, IOException {
  418           
  419           // REVISIT: this method used to reset all the components and
  420           //          construct the pipeline. Now reset() is called
  421           //          in parse (boolean) just before we parse the document
  422           //          Should this method still throw exceptions..?
  423   
  424           fInputSource = inputSource;
  425           
  426       } // setInputSource(XMLInputSource)
  427   
  428       /**
  429        * Parses the document in a pull parsing fashion.
  430        *
  431        * @param complete True if the pull parser should parse the
  432        *                 remaining document completely.
  433        *
  434        * @return True if there is more document to parse.
  435        *
  436        * @exception XNIException Any XNI exception, possibly wrapping 
  437        *                         another exception.
  438        * @exception IOException  An IO exception from the parser, possibly
  439        *                         from a byte stream or character stream
  440        *                         supplied by the parser.
  441        *
  442        * @see #setInputSource
  443        */
  444       public boolean parse(boolean complete) throws XNIException, IOException {
  445           //
  446           // reset and configure pipeline and set InputSource.
  447           if (fInputSource !=null) {
  448               try {
  449                   // resets and sets the pipeline.
  450                   reset();
  451                   fScanner.setInputSource(fInputSource);
  452                   fInputSource = null;
  453               } 
  454               catch (XNIException ex) {
  455                   if (PRINT_EXCEPTION_STACK_TRACE)
  456                       ex.printStackTrace();
  457                   throw ex;
  458               } 
  459               catch (IOException ex) {
  460                   if (PRINT_EXCEPTION_STACK_TRACE)
  461                       ex.printStackTrace();
  462                   throw ex;
  463               } 
  464               catch (RuntimeException ex) {
  465                   if (PRINT_EXCEPTION_STACK_TRACE)
  466                       ex.printStackTrace();
  467                   throw ex;
  468               }
  469               catch (Exception ex) {
  470                   if (PRINT_EXCEPTION_STACK_TRACE)
  471                       ex.printStackTrace();
  472                   throw new XNIException(ex);
  473               }
  474           }
  475   
  476           try {
  477               return fScanner.scanDocument(complete);
  478           } 
  479           catch (XNIException ex) {
  480               if (PRINT_EXCEPTION_STACK_TRACE)
  481                   ex.printStackTrace();
  482               throw ex;
  483           } 
  484           catch (IOException ex) {
  485               if (PRINT_EXCEPTION_STACK_TRACE)
  486                   ex.printStackTrace();
  487               throw ex;
  488           } 
  489           catch (RuntimeException ex) {
  490               if (PRINT_EXCEPTION_STACK_TRACE)
  491                   ex.printStackTrace();
  492               throw ex;
  493           }
  494           catch (Exception ex) {
  495               if (PRINT_EXCEPTION_STACK_TRACE)
  496                   ex.printStackTrace();
  497               throw new XNIException(ex);
  498           }
  499   
  500       } // parse(boolean):boolean
  501   
  502       /**
  503        * If the application decides to terminate parsing before the xml document
  504        * is fully parsed, the application should call this method to free any
  505        * resource allocated during parsing. For example, close all opened streams.
  506        */
  507       public void cleanup() {
  508           fEntityManager.closeReaders();
  509       }
  510       
  511       //
  512       // XMLParserConfiguration methods
  513       //
  514   
  515       /**
  516        * Parses the specified input source.
  517        *
  518        * @param source The input source.
  519        *
  520        * @exception XNIException Throws exception on XNI error.
  521        * @exception java.io.IOException Throws exception on i/o error.
  522        */
  523       public void parse(XMLInputSource source) throws XNIException, IOException {
  524   
  525           if (fParseInProgress) {
  526               // REVISIT - need to add new error message
  527               throw new XNIException("FWK005 parse may not be called while parsing.");
  528           }
  529           fParseInProgress = true;
  530   
  531           try {
  532               setInputSource(source);
  533               parse(true);
  534           } 
  535           catch (XNIException ex) {
  536               if (PRINT_EXCEPTION_STACK_TRACE)
  537                   ex.printStackTrace();
  538               throw ex;
  539           } 
  540           catch (IOException ex) {
  541               if (PRINT_EXCEPTION_STACK_TRACE)
  542                   ex.printStackTrace();
  543               throw ex;
  544           }
  545           catch (RuntimeException ex) {
  546               if (PRINT_EXCEPTION_STACK_TRACE)
  547                   ex.printStackTrace();
  548               throw ex;
  549           }              
  550           catch (Exception ex) {
  551               if (PRINT_EXCEPTION_STACK_TRACE)
  552                   ex.printStackTrace();
  553               throw new XNIException(ex);
  554           }
  555           finally {
  556               fParseInProgress = false;
  557               // close all streams opened by xerces
  558               this.cleanup();
  559           }
  560   
  561       } // parse(InputSource)
  562   
  563       //
  564       // Protected methods
  565       //
  566       
  567       /** 
  568        * Reset all components before parsing. 
  569        *
  570        * @throws XNIException Thrown if an error occurs during initialization.
  571        */
  572       protected void reset() throws XNIException {
  573   
  574           if (fValidationManager != null)
  575               fValidationManager.reset();
  576           // configure the pipeline and initialize the components
  577           configurePipeline();
  578           super.reset();
  579   
  580       } // reset()
  581   
  582       /** Configures the pipeline. */
  583       protected void configurePipeline() {
  584           // create appropriate scanner
  585           // and register it as one of the components.
  586           if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
  587               if (fNamespaceScanner == null) {
  588                   fNamespaceScanner = new XMLNSDocumentScannerImpl();
  589                   addComponent((XMLComponent)fNamespaceScanner);
  590               }
  591               fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner);
  592               fNamespaceScanner.setDTDValidator(null);
  593               fScanner = fNamespaceScanner;
  594           } 
  595           else {
  596               if (fNonNSScanner == null) {
  597                   fNonNSScanner = new XMLDocumentScannerImpl();
  598                   addComponent((XMLComponent)fNonNSScanner);
  599               }
  600               fProperties.put(DOCUMENT_SCANNER, fNonNSScanner);
  601               fScanner = fNonNSScanner;
  602           }
  603   
  604           fScanner.setDocumentHandler(fDocumentHandler);
  605           fLastComponent = fScanner;
  606           // setup dtd pipeline
  607           if (fDTDScanner != null) {
  608                   fDTDScanner.setDTDHandler(fDTDHandler);
  609                   fDTDScanner.setDTDContentModelHandler(fDTDContentModelHandler);
  610           }
  611   
  612   
  613       } // configurePipeline()
  614   
  615       // features and properties
  616   
  617       /**
  618        * Check a feature. If feature is know and supported, this method simply
  619        * returns. Otherwise, the appropriate exception is thrown.
  620        *
  621        * @param featureId The unique identifier (URI) of the feature.
  622        *
  623        * @throws XMLConfigurationException Thrown for configuration error.
  624        *                                   In general, components should
  625        *                                   only throw this exception if
  626        *                                   it is <strong>really</strong>
  627        *                                   a critical error.
  628        */
  629       protected void checkFeature(String featureId)
  630           throws XMLConfigurationException {
  631   
  632           //
  633           // Xerces Features
  634           //
  635   
  636           if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) {
  637               final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length();
  638           	
  639               //
  640               // http://apache.org/xml/features/validation/dynamic
  641               //   Allows the parser to validate a document only when it
  642               //   contains a grammar. Validation is turned on/off based
  643               //   on each document instance, automatically.
  644               //
  645               if (suffixLength == Constants.DYNAMIC_VALIDATION_FEATURE.length() && 
  646                   featureId.endsWith(Constants.DYNAMIC_VALIDATION_FEATURE)) {
  647                   return;
  648               }
  649               //
  650               // http://apache.org/xml/features/validation/default-attribute-values
  651               //
  652               if (suffixLength == Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE.length() && 
  653                   featureId.endsWith(Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE)) {
  654                   // REVISIT
  655                   short type = XMLConfigurationException.NOT_SUPPORTED;
  656                   throw new XMLConfigurationException(type, featureId);
  657               }
  658               //
  659               // http://apache.org/xml/features/validation/default-attribute-values
  660               //
  661               if (suffixLength == Constants.VALIDATE_CONTENT_MODELS_FEATURE.length() && 
  662                   featureId.endsWith(Constants.VALIDATE_CONTENT_MODELS_FEATURE)) {
  663                   // REVISIT
  664                   short type = XMLConfigurationException.NOT_SUPPORTED;
  665                   throw new XMLConfigurationException(type, featureId);
  666               }
  667               //
  668               // http://apache.org/xml/features/validation/nonvalidating/load-dtd-grammar
  669               //
  670               if (suffixLength == Constants.LOAD_DTD_GRAMMAR_FEATURE.length() && 
  671                   featureId.endsWith(Constants.LOAD_DTD_GRAMMAR_FEATURE)) {
  672                   return;
  673               }
  674               //
  675               // http://apache.org/xml/features/validation/nonvalidating/load-external-dtd
  676               //
  677               if (suffixLength == Constants.LOAD_EXTERNAL_DTD_FEATURE.length() && 
  678                   featureId.endsWith(Constants.LOAD_EXTERNAL_DTD_FEATURE)) {
  679                   return;
  680               }
  681   
  682               //
  683               // http://apache.org/xml/features/validation/default-attribute-values
  684               //
  685               if (suffixLength == Constants.VALIDATE_DATATYPES_FEATURE.length() && 
  686                   featureId.endsWith(Constants.VALIDATE_DATATYPES_FEATURE)) {
  687                   short type = XMLConfigurationException.NOT_SUPPORTED;
  688                   throw new XMLConfigurationException(type, featureId);
  689               }
  690           }
  691   
  692           //
  693           // Not recognized
  694           //
  695   
  696           super.checkFeature(featureId);
  697   
  698       } // checkFeature(String)
  699   
  700       /**
  701        * Check a property. If the property is know and supported, this method
  702        * simply returns. Otherwise, the appropriate exception is thrown.
  703        *
  704        * @param propertyId The unique identifier (URI) of the property
  705        *                   being set.
  706        *
  707        * @throws XMLConfigurationException Thrown for configuration error.
  708        *                                   In general, components should
  709        *                                   only throw this exception if
  710        *                                   it is <strong>really</strong>
  711        *                                   a critical error.
  712        */
  713       protected void checkProperty(String propertyId)
  714           throws XMLConfigurationException {
  715   
  716           //
  717           // Xerces Properties
  718           //
  719   
  720           if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
  721               final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length();
  722               
  723               if (suffixLength == Constants.DTD_SCANNER_PROPERTY.length() && 
  724                   propertyId.endsWith(Constants.DTD_SCANNER_PROPERTY)) {
  725                   return;
  726               }
  727           }
  728   
  729           if (propertyId.startsWith(Constants.JAXP_PROPERTY_PREFIX)) {
  730               final int suffixLength = propertyId.length() - Constants.JAXP_PROPERTY_PREFIX.length();
  731   
  732               if (suffixLength == Constants.SCHEMA_SOURCE.length() && 
  733                   propertyId.endsWith(Constants.SCHEMA_SOURCE)) {
  734                   return;
  735               }
  736           }
  737   
  738           //
  739           // Not recognized
  740           //
  741   
  742           super.checkProperty(propertyId);
  743   
  744       } // checkProperty(String)
  745   
  746       // factory methods
  747   
  748       /** Creates an entity manager. */
  749       protected XMLEntityManager createEntityManager() {
  750           return new XMLEntityManager();
  751       } // createEntityManager():XMLEntityManager
  752   
  753       /** Creates an error reporter. */
  754       protected XMLErrorReporter createErrorReporter() {
  755           return new XMLErrorReporter();
  756       } // createErrorReporter():XMLErrorReporter
  757   
  758       /** Create a document scanner. */
  759       protected XMLDocumentScanner createDocumentScanner() {
  760           return null;
  761       } // createDocumentScanner():XMLDocumentScanner
  762   
  763       /** Create a DTD scanner. */
  764       protected XMLDTDScanner createDTDScanner() {
  765           return new XMLDTDScannerImpl();
  766       } // createDTDScanner():XMLDTDScanner
  767   
  768       /** Create a datatype validator factory. */
  769       protected DTDDVFactory createDatatypeValidatorFactory() {
  770           return DTDDVFactory.getInstance();
  771       } // createDatatypeValidatorFactory():DatatypeValidatorFactory
  772       protected ValidationManager createValidationManager(){
  773           return new ValidationManager();
  774       }
  775   
  776   } // class NonValidatingConfiguration

Home » Xerces-J-src.2.9.1 » org.apache.xerces » parsers » [javadoc | source]