src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/DTDConfiguration.java

Print this page


   1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /*
   6  * Copyright 2001-2004 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.Locale;
  25 
  26 import com.sun.org.apache.xerces.internal.impl.Constants;
  27 import com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl;
  28 import com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl;
  29 import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;
  30 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
  31 import com.sun.org.apache.xerces.internal.impl.XMLNamespaceBinder;
  32 import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDProcessor;
  33 import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator;
  34 import com.sun.org.apache.xerces.internal.impl.dv.DTDDVFactory;
  35 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
  36 import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
  37 import com.sun.org.apache.xerces.internal.util.FeatureState;
  38 import com.sun.org.apache.xerces.internal.util.PropertyState;
  39 import com.sun.org.apache.xerces.internal.util.Status;
  40 import com.sun.org.apache.xerces.internal.util.SymbolTable;
  41 import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager;
  42 import com.sun.org.apache.xerces.internal.xni.XMLLocator;
  43 import com.sun.org.apache.xerces.internal.xni.XNIException;
  44 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;
  45 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;
  46 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
  47 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
  48 import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner;
  49 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner;
  50 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
  51 import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration;



  52 
  53 /**
  54  * This is the DTD-only parser configuration.  It extends the basic
  55  * configuration with a standard set of parser components appropriate
  56  * to DTD-centric validation. Since
  57  * the Xerces2 reference implementation document and DTD scanner
  58  * implementations are capable of acting as pull parsers, this
  59  * configuration implements the
  60  * <code>XMLPullParserConfiguration</code> interface.
  61  * <p>
  62  * In addition to the features and properties recognized by the base
  63  * parser configuration, this class recognizes these additional
  64  * features and properties:
  65  * <ul>
  66  * <li>Features
  67  *  <ul>
  68  *   <li>http://apache.org/xml/features/validation/warn-on-duplicate-attdef</li>
  69  *   <li>http://apache.org/xml/features/validation/warn-on-undeclared-elemdef</li>
  70  *   <li>http://apache.org/xml/features/allow-java-encodings</li>
  71  *   <li>http://apache.org/xml/features/continue-after-fatal-error</li>


 291      *
 292      * @param symbolTable    The symbol table to use.
 293      * @param grammarPool    The grammar pool to use.
 294      * @param parentSettings The parent settings.
 295      */
 296     public DTDConfiguration(SymbolTable symbolTable,
 297                                        XMLGrammarPool grammarPool,
 298                                        XMLComponentManager parentSettings) {
 299         super(symbolTable, parentSettings);
 300 
 301         // add default recognized features
 302         final String[] recognizedFeatures = {
 303             //WARN_ON_DUPLICATE_ATTDEF,     // from XMLDTDScannerImpl
 304             //WARN_ON_UNDECLARED_ELEMDEF,   // from XMLDTDScannerImpl
 305             //ALLOW_JAVA_ENCODINGS,         // from XMLEntityManager
 306             CONTINUE_AFTER_FATAL_ERROR,
 307             LOAD_EXTERNAL_DTD,    // from XMLDTDScannerImpl
 308             //NOTIFY_BUILTIN_REFS,  // from XMLDocumentFragmentScannerImpl
 309             //NOTIFY_CHAR_REFS,         // from XMLDocumentFragmentScannerImpl
 310             //WARN_ON_DUPLICATE_ENTITYDEF,  // from XMLEntityManager

 311         };
 312         addRecognizedFeatures(recognizedFeatures);
 313 
 314         // set state for default features
 315         //setFeature(WARN_ON_DUPLICATE_ATTDEF, false);  // from XMLDTDScannerImpl
 316         //setFeature(WARN_ON_UNDECLARED_ELEMDEF, false);  // from XMLDTDScannerImpl
 317         //setFeature(ALLOW_JAVA_ENCODINGS, false);      // from XMLEntityManager
 318         setFeature(CONTINUE_AFTER_FATAL_ERROR, false);
 319         setFeature(LOAD_EXTERNAL_DTD, true);      // from XMLDTDScannerImpl
 320         //setFeature(NOTIFY_BUILTIN_REFS, false);   // from XMLDocumentFragmentScannerImpl
 321         //setFeature(NOTIFY_CHAR_REFS, false);      // from XMLDocumentFragmentScannerImpl
 322         //setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false);   // from XMLEntityManager

 323 
 324         // add default recognized properties
 325         final String[] recognizedProperties = {
 326             ERROR_REPORTER,
 327             ENTITY_MANAGER,
 328             DOCUMENT_SCANNER,
 329             DTD_SCANNER,
 330             DTD_PROCESSOR,
 331             DTD_VALIDATOR,
 332             NAMESPACE_BINDER,
 333             XMLGRAMMAR_POOL,
 334             DATATYPE_VALIDATOR_FACTORY,
 335             VALIDATION_MANAGER,
 336             JAXP_SCHEMA_SOURCE,
 337             JAXP_SCHEMA_LANGUAGE,
 338             LOCALE,
 339             SECURITY_MANAGER,
 340             XML_SECURITY_PROPERTY_MANAGER




 341         };
 342         addRecognizedProperties(recognizedProperties);
 343 
 344         fGrammarPool = grammarPool;
 345         if(fGrammarPool != null){
 346             setProperty(XMLGRAMMAR_POOL, fGrammarPool);
 347         }
 348 
 349         fEntityManager = createEntityManager();
 350         setProperty(ENTITY_MANAGER, fEntityManager);
 351         addComponent(fEntityManager);
 352 
 353         fErrorReporter = createErrorReporter();
 354         fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());
 355         setProperty(ERROR_REPORTER, fErrorReporter);
 356         addComponent(fErrorReporter);
 357 
 358         fScanner = createDocumentScanner();
 359         setProperty(DOCUMENT_SCANNER, fScanner);
 360         if (fScanner instanceof XMLComponent) {


 399         if (fValidationManager != null) {
 400             setProperty (VALIDATION_MANAGER, fValidationManager);
 401         }
 402         // add message formatters
 403         if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
 404             XMLMessageFormatter xmft = new XMLMessageFormatter();
 405             fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
 406             fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
 407         }
 408 
 409         // set locale
 410         try {
 411             setLocale(Locale.getDefault());
 412         }
 413         catch (XNIException e) {
 414             // do nothing
 415             // REVISIT: What is the right thing to do? -Ac
 416         }
 417 
 418         setProperty(XML_SECURITY_PROPERTY_MANAGER, new XMLSecurityPropertyManager());





 419     } // <init>(SymbolTable,XMLGrammarPool)
 420 
 421     //
 422     // Public methods
 423     //
 424 
 425     public PropertyState getPropertyState(String propertyId)
 426         throws XMLConfigurationException {
 427         if (LOCALE.equals(propertyId)) {
 428             return PropertyState.is(getLocale());
 429         }
 430         return super.getPropertyState(propertyId);
 431     }
 432 
 433     public void setProperty(String propertyId, Object value)
 434         throws XMLConfigurationException {
 435         if (LOCALE.equals(propertyId)) {
 436             setLocale((Locale) value);
 437         }
 438         super.setProperty(propertyId, value);


   1 /*
   2  * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.

   3  */
   4 /*
   5  * Licensed to the Apache Software Foundation (ASF) under one or more
   6  * contributor license agreements.  See the NOTICE file distributed with
   7  * this work for additional information regarding copyright ownership.
   8  * The ASF licenses this file to You under the Apache License, Version 2.0
   9  * (the "License"); you may not use this file except in compliance with
  10  * the License.  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.Locale;
  25 
  26 import com.sun.org.apache.xerces.internal.impl.Constants;
  27 import com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl;
  28 import com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl;
  29 import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;
  30 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
  31 import com.sun.org.apache.xerces.internal.impl.XMLNamespaceBinder;
  32 import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDProcessor;
  33 import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator;
  34 import com.sun.org.apache.xerces.internal.impl.dv.DTDDVFactory;
  35 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
  36 import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
  37 import com.sun.org.apache.xerces.internal.util.FeatureState;
  38 import com.sun.org.apache.xerces.internal.util.PropertyState;

  39 import com.sun.org.apache.xerces.internal.util.SymbolTable;
  40 import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager;
  41 import com.sun.org.apache.xerces.internal.xni.XMLLocator;
  42 import com.sun.org.apache.xerces.internal.xni.XNIException;
  43 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;
  44 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;
  45 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
  46 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
  47 import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner;
  48 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner;
  49 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
  50 import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration;
  51 import javax.xml.XMLConstants;
  52 import javax.xml.catalog.CatalogFeatures;
  53 import jdk.xml.internal.JdkXmlUtils;
  54 
  55 /**
  56  * This is the DTD-only parser configuration.  It extends the basic
  57  * configuration with a standard set of parser components appropriate
  58  * to DTD-centric validation. Since
  59  * the Xerces2 reference implementation document and DTD scanner
  60  * implementations are capable of acting as pull parsers, this
  61  * configuration implements the
  62  * <code>XMLPullParserConfiguration</code> interface.
  63  * <p>
  64  * In addition to the features and properties recognized by the base
  65  * parser configuration, this class recognizes these additional
  66  * features and properties:
  67  * <ul>
  68  * <li>Features
  69  *  <ul>
  70  *   <li>http://apache.org/xml/features/validation/warn-on-duplicate-attdef</li>
  71  *   <li>http://apache.org/xml/features/validation/warn-on-undeclared-elemdef</li>
  72  *   <li>http://apache.org/xml/features/allow-java-encodings</li>
  73  *   <li>http://apache.org/xml/features/continue-after-fatal-error</li>


 293      *
 294      * @param symbolTable    The symbol table to use.
 295      * @param grammarPool    The grammar pool to use.
 296      * @param parentSettings The parent settings.
 297      */
 298     public DTDConfiguration(SymbolTable symbolTable,
 299                                        XMLGrammarPool grammarPool,
 300                                        XMLComponentManager parentSettings) {
 301         super(symbolTable, parentSettings);
 302 
 303         // add default recognized features
 304         final String[] recognizedFeatures = {
 305             //WARN_ON_DUPLICATE_ATTDEF,     // from XMLDTDScannerImpl
 306             //WARN_ON_UNDECLARED_ELEMDEF,   // from XMLDTDScannerImpl
 307             //ALLOW_JAVA_ENCODINGS,         // from XMLEntityManager
 308             CONTINUE_AFTER_FATAL_ERROR,
 309             LOAD_EXTERNAL_DTD,    // from XMLDTDScannerImpl
 310             //NOTIFY_BUILTIN_REFS,  // from XMLDocumentFragmentScannerImpl
 311             //NOTIFY_CHAR_REFS,         // from XMLDocumentFragmentScannerImpl
 312             //WARN_ON_DUPLICATE_ENTITYDEF,  // from XMLEntityManager
 313             XMLConstants.USE_CATALOG
 314         };
 315         addRecognizedFeatures(recognizedFeatures);
 316 
 317         // set state for default features
 318         //setFeature(WARN_ON_DUPLICATE_ATTDEF, false);  // from XMLDTDScannerImpl
 319         //setFeature(WARN_ON_UNDECLARED_ELEMDEF, false);  // from XMLDTDScannerImpl
 320         //setFeature(ALLOW_JAVA_ENCODINGS, false);      // from XMLEntityManager
 321         setFeature(CONTINUE_AFTER_FATAL_ERROR, false);
 322         setFeature(LOAD_EXTERNAL_DTD, true);      // from XMLDTDScannerImpl
 323         //setFeature(NOTIFY_BUILTIN_REFS, false);   // from XMLDocumentFragmentScannerImpl
 324         //setFeature(NOTIFY_CHAR_REFS, false);      // from XMLDocumentFragmentScannerImpl
 325         //setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false);   // from XMLEntityManager
 326         fFeatures.put(XMLConstants.USE_CATALOG, JdkXmlUtils.USE_CATALOG_DEFAULT);
 327 
 328         // add default recognized properties
 329         final String[] recognizedProperties = {
 330             ERROR_REPORTER,
 331             ENTITY_MANAGER,
 332             DOCUMENT_SCANNER,
 333             DTD_SCANNER,
 334             DTD_PROCESSOR,
 335             DTD_VALIDATOR,
 336             NAMESPACE_BINDER,
 337             XMLGRAMMAR_POOL,
 338             DATATYPE_VALIDATOR_FACTORY,
 339             VALIDATION_MANAGER,
 340             JAXP_SCHEMA_SOURCE,
 341             JAXP_SCHEMA_LANGUAGE,
 342             LOCALE,
 343             SECURITY_MANAGER,
 344             XML_SECURITY_PROPERTY_MANAGER,
 345             JdkXmlUtils.CATALOG_DEFER,
 346             JdkXmlUtils.CATALOG_FILES,
 347             JdkXmlUtils.CATALOG_PREFER,
 348             JdkXmlUtils.CATALOG_RESOLVE
 349         };
 350         addRecognizedProperties(recognizedProperties);
 351 
 352         fGrammarPool = grammarPool;
 353         if(fGrammarPool != null){
 354             setProperty(XMLGRAMMAR_POOL, fGrammarPool);
 355         }
 356 
 357         fEntityManager = createEntityManager();
 358         setProperty(ENTITY_MANAGER, fEntityManager);
 359         addComponent(fEntityManager);
 360 
 361         fErrorReporter = createErrorReporter();
 362         fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());
 363         setProperty(ERROR_REPORTER, fErrorReporter);
 364         addComponent(fErrorReporter);
 365 
 366         fScanner = createDocumentScanner();
 367         setProperty(DOCUMENT_SCANNER, fScanner);
 368         if (fScanner instanceof XMLComponent) {


 407         if (fValidationManager != null) {
 408             setProperty (VALIDATION_MANAGER, fValidationManager);
 409         }
 410         // add message formatters
 411         if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
 412             XMLMessageFormatter xmft = new XMLMessageFormatter();
 413             fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
 414             fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
 415         }
 416 
 417         // set locale
 418         try {
 419             setLocale(Locale.getDefault());
 420         }
 421         catch (XNIException e) {
 422             // do nothing
 423             // REVISIT: What is the right thing to do? -Ac
 424         }
 425 
 426         setProperty(XML_SECURITY_PROPERTY_MANAGER, new XMLSecurityPropertyManager());
 427 
 428         // Initialize Catalog features
 429         for( CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) {
 430             setProperty(f.getPropertyName(), null);
 431         }
 432     } // <init>(SymbolTable,XMLGrammarPool)
 433 
 434     //
 435     // Public methods
 436     //
 437 
 438     public PropertyState getPropertyState(String propertyId)
 439         throws XMLConfigurationException {
 440         if (LOCALE.equals(propertyId)) {
 441             return PropertyState.is(getLocale());
 442         }
 443         return super.getPropertyState(propertyId);
 444     }
 445 
 446     public void setProperty(String propertyId, Object value)
 447         throws XMLConfigurationException {
 448         if (LOCALE.equals(propertyId)) {
 449             setLocale((Locale) value);
 450         }
 451         super.setProperty(propertyId, value);