src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/XML11DTDConfiguration.java
changeset 47359 e1a6c0168741
parent 47216 71c04702a3d5
child 48409 5ab69533994b
equal deleted inserted replaced
47358:d07d5f7cab35 47359:e1a6c0168741
     1 /*
     1 /*
     2  * reserved comment block
     2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT REMOVE OR ALTER!
     3  * @LastModified: Oct 2017
     4  */
     4  */
     5 /*
     5 /*
     6  * Licensed to the Apache Software Foundation (ASF) under one or more
     6  * Licensed to the Apache Software Foundation (ASF) under one or more
     7  * contributor license agreements.  See the NOTICE file distributed with
     7  * contributor license agreements.  See the NOTICE file distributed with
     8  * this work for additional information regarding copyright ownership.
     8  * this work for additional information regarding copyright ownership.
    18  * See the License for the specific language governing permissions and
    18  * See the License for the specific language governing permissions and
    19  * limitations under the License.
    19  * limitations under the License.
    20  */
    20  */
    21 
    21 
    22 package com.sun.org.apache.xerces.internal.parsers;
    22 package com.sun.org.apache.xerces.internal.parsers;
    23 
       
    24 import java.io.IOException;
       
    25 import java.util.ArrayList;
       
    26 import java.util.HashMap;
       
    27 import java.util.Locale;
       
    28 
    23 
    29 import com.sun.org.apache.xerces.internal.impl.Constants;
    24 import com.sun.org.apache.xerces.internal.impl.Constants;
    30 import com.sun.org.apache.xerces.internal.impl.XML11DTDScannerImpl;
    25 import com.sun.org.apache.xerces.internal.impl.XML11DTDScannerImpl;
    31 import com.sun.org.apache.xerces.internal.impl.XML11DocumentScannerImpl;
    26 import com.sun.org.apache.xerces.internal.impl.XML11DocumentScannerImpl;
    32 import com.sun.org.apache.xerces.internal.impl.XML11NSDocumentScannerImpl;
    27 import com.sun.org.apache.xerces.internal.impl.XML11NSDocumentScannerImpl;
    65 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource;
    60 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource;
    66 import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver;
    61 import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver;
    67 import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler;
    62 import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler;
    68 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
    63 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
    69 import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration;
    64 import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration;
       
    65 import java.io.IOException;
       
    66 import java.util.ArrayList;
       
    67 import java.util.HashMap;
       
    68 import java.util.List;
       
    69 import java.util.Locale;
    70 
    70 
    71 /**
    71 /**
    72  * This class is the DTD-only parser configuration
    72  * This class is the DTD-only parser configuration
    73  * used to parse XML 1.0 and XML 1.1 documents.
    73  * used to parse XML 1.0 and XML 1.1 documents.
    74  *
    74  *
   219     protected XMLVersionDetector fVersionDetector;
   219     protected XMLVersionDetector fVersionDetector;
   220     protected XMLLocator fLocator;
   220     protected XMLLocator fLocator;
   221     protected Locale fLocale;
   221     protected Locale fLocale;
   222 
   222 
   223     /** XML 1.0 Components. */
   223     /** XML 1.0 Components. */
   224     protected ArrayList fComponents;
   224     protected List<XMLComponent> fComponents;
   225 
   225 
   226     /** XML 1.1. Components. */
   226     /** XML 1.1. Components. */
   227     protected ArrayList fXML11Components = null;
   227     protected List<XMLComponent> fXML11Components = null;
   228 
   228 
   229     /** Common components: XMLEntityManager, XMLErrorReporter */
   229     /** Common components: XMLEntityManager, XMLErrorReporter */
   230     protected ArrayList fCommonComponents = null;
   230     protected List<XMLComponent> fCommonComponents = null;
   231 
   231 
   232     /** The document handler. */
   232     /** The document handler. */
   233     protected XMLDocumentHandler fDocumentHandler;
   233     protected XMLDocumentHandler fDocumentHandler;
   234 
   234 
   235     /** The DTD handler. */
   235     /** The DTD handler. */
   381 
   381 
   382                 super(parentSettings);
   382                 super(parentSettings);
   383 
   383 
   384                 // create a vector to hold all the components in use
   384                 // create a vector to hold all the components in use
   385                 // XML 1.0 specialized components
   385                 // XML 1.0 specialized components
   386                 fComponents = new ArrayList();
   386                 fComponents = new ArrayList<>();
   387                 // XML 1.1 specialized components
   387                 // XML 1.1 specialized components
   388                 fXML11Components = new ArrayList();
   388                 fXML11Components = new ArrayList<>();
   389                 // Common components for XML 1.1. and XML 1.0
   389                 // Common components for XML 1.1. and XML 1.0
   390                 fCommonComponents = new ArrayList();
   390                 fCommonComponents = new ArrayList<>();
   391 
   391 
   392                 // create table for features and properties
   392                 // create table for features and properties
   393                 fFeatures = new HashMap();
   393                 fFeatures = new HashMap<>();
   394                 fProperties = new HashMap();
   394                 fProperties = new HashMap<>();
   395 
   395 
   396         // add default recognized features
   396         // add default recognized features
   397         final String[] recognizedFeatures =
   397         final String[] recognizedFeatures =
   398             {
   398             {
   399                 CONTINUE_AFTER_FATAL_ERROR, LOAD_EXTERNAL_DTD, // from XMLDTDScannerImpl
   399                 CONTINUE_AFTER_FATAL_ERROR, LOAD_EXTERNAL_DTD, // from XMLDTDScannerImpl
   797          */
   797          */
   798         public void setFeature(String featureId, boolean state)
   798         public void setFeature(String featureId, boolean state)
   799                 throws XMLConfigurationException {
   799                 throws XMLConfigurationException {
   800                 fConfigUpdated = true;
   800                 fConfigUpdated = true;
   801                 // forward to every XML 1.0 component
   801                 // forward to every XML 1.0 component
   802                 int count = fComponents.size();
   802                 for (XMLComponent c : fComponents) {
   803                 for (int i = 0; i < count; i++) {
   803                     c.setFeature(featureId, state);
   804                         XMLComponent c = (XMLComponent) fComponents.get(i);
       
   805                         c.setFeature(featureId, state);
       
   806                 }
   804                 }
   807                 // forward it to common components
   805                 // forward it to common components
   808                 count = fCommonComponents.size();
   806                 for (XMLComponent c : fCommonComponents) {
   809                 for (int i = 0; i < count; i++) {
   807                     c.setFeature(featureId, state);
   810                         XMLComponent c = (XMLComponent) fCommonComponents.get(i);
   808                 }
       
   809                 // forward to every XML 1.1 component
       
   810                 for (XMLComponent c : fXML11Components) {
       
   811                     try {
   811                         c.setFeature(featureId, state);
   812                         c.setFeature(featureId, state);
   812                 }
   813                     }
   813 
   814                     catch (Exception e){
   814                 // forward to every XML 1.1 component
   815                         // no op
   815                 count = fXML11Components.size();
   816                     }
   816                 for (int i = 0; i < count; i++) {
       
   817                         XMLComponent c = (XMLComponent) fXML11Components.get(i);
       
   818                         try{
       
   819                                 c.setFeature(featureId, state);
       
   820                         }
       
   821                         catch (Exception e){
       
   822                                 // no op
       
   823                         }
       
   824                 }
   817                 }
   825                 // save state if noone "objects"
   818                 // save state if noone "objects"
   826                 super.setFeature(featureId, state);
   819                 super.setFeature(featureId, state);
   827 
   820 
   828         } // setFeature(String,boolean)
   821         } // setFeature(String,boolean)
   835          */
   828          */
   836         public void setProperty(String propertyId, Object value)
   829         public void setProperty(String propertyId, Object value)
   837                 throws XMLConfigurationException {
   830                 throws XMLConfigurationException {
   838                 fConfigUpdated = true;
   831                 fConfigUpdated = true;
   839                 // forward to every XML 1.0 component
   832                 // forward to every XML 1.0 component
   840                 int count = fComponents.size();
   833                 for (XMLComponent c : fComponents) {
   841                 for (int i = 0; i < count; i++) {
   834                     c.setProperty(propertyId, value);
   842                         XMLComponent c = (XMLComponent) fComponents.get(i);
       
   843                         c.setProperty(propertyId, value);
       
   844                 }
   835                 }
   845                 // forward it to every common Component
   836                 // forward it to every common Component
   846                 count = fCommonComponents.size();
   837                 for (XMLComponent c : fCommonComponents) {
   847                 for (int i = 0; i < count; i++) {
   838                     c.setProperty(propertyId, value);
   848                         XMLComponent c = (XMLComponent) fCommonComponents.get(i);
       
   849                         c.setProperty(propertyId, value);
       
   850                 }
   839                 }
   851                 // forward it to every XML 1.1 component
   840                 // forward it to every XML 1.1 component
   852                 count = fXML11Components.size();
   841                 for (XMLComponent c : fXML11Components) {
   853                 for (int i = 0; i < count; i++) {
   842                     try {
   854                         XMLComponent c = (XMLComponent) fXML11Components.get(i);
   843                         c.setProperty(propertyId, value);
   855                         try{
   844                     }
   856                                 c.setProperty(propertyId, value);
   845                     catch (Exception e){
   857                         }
       
   858                         catch (Exception e){
       
   859                                 // ignore it
   846                                 // ignore it
   860                         }
   847                     }
   861                 }
   848                 }
   862 
   849 
   863                 // store value if noone "objects"
   850                 // store value if noone "objects"
   864                 super.setProperty(propertyId, value);
   851                 super.setProperty(propertyId, value);
   865 
   852 
   873 
   860 
   874         /**
   861         /**
   875          * reset all XML 1.0 components before parsing and namespace context
   862          * reset all XML 1.0 components before parsing and namespace context
   876          */
   863          */
   877         protected void reset() throws XNIException {
   864         protected void reset() throws XNIException {
   878                 int count = fComponents.size();
   865             for (XMLComponent c : fComponents) {
   879                 for (int i = 0; i < count; i++) {
   866                 c.reset(this);
   880                         XMLComponent c = (XMLComponent) fComponents.get(i);
   867             }
   881                         c.reset(this);
       
   882                 }
       
   883 
       
   884         } // reset()
   868         } // reset()
   885 
   869 
   886         /**
   870         /**
   887          * reset all common components before parsing
   871          * reset all common components before parsing
   888          */
   872          */
   889         protected void resetCommon() throws XNIException {
   873         protected void resetCommon() throws XNIException {
   890                 // reset common components
   874             // reset common components
   891                 int count = fCommonComponents.size();
   875             for (XMLComponent c : fCommonComponents) {
   892                 for (int i = 0; i < count; i++) {
   876                 c.reset(this);
   893                         XMLComponent c = (XMLComponent) fCommonComponents.get(i);
   877             }
   894                         c.reset(this);
       
   895                 }
       
   896 
       
   897         } // resetCommon()
   878         } // resetCommon()
   898 
   879 
   899         /**
   880         /**
   900          * reset all components before parsing and namespace context
   881          * reset all components before parsing and namespace context
   901          */
   882          */
   902         protected void resetXML11() throws XNIException {
   883         protected void resetXML11() throws XNIException {
   903                 // reset every component
   884             // reset every component
   904                 int count = fXML11Components.size();
   885             for (XMLComponent c : fXML11Components) {
   905                 for (int i = 0; i < count; i++) {
   886                 c.reset(this);
   906                         XMLComponent c = (XMLComponent) fXML11Components.get(i);
   887             }
   907                         c.reset(this);
       
   908                 }
       
   909 
       
   910         } // resetXML11()
   888         } // resetXML11()
   911 
   889 
   912     /**
   890     /**
   913      *  Configures the XML 1.1 pipeline.
   891      *  Configures the XML 1.1 pipeline.
   914      *  Note: this method also resets the new XML11 components.
   892      *  Note: this method also resets the new XML11 components.