src/com/sun/org/apache/xerces/internal/dom/DOMConfigurationImpl.java

Print this page




   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.dom;
  22 
  23 import java.io.IOException;
  24 import java.util.ArrayList;
  25 import java.util.HashMap;
  26 import java.util.Locale;
  27 import java.util.Vector;
  28 
  29 import com.sun.org.apache.xerces.internal.util.PropertyState;
  30 import com.sun.org.apache.xerces.internal.util.Status;
  31 import org.w3c.dom.DOMConfiguration;
  32 import org.w3c.dom.DOMErrorHandler;
  33 import org.w3c.dom.DOMStringList;
  34 
  35 import com.sun.org.apache.xerces.internal.impl.Constants;
  36 import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;
  37 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
  38 import com.sun.org.apache.xerces.internal.impl.dv.DTDDVFactory;
  39 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
  40 import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
  41 import com.sun.org.apache.xerces.internal.util.DOMEntityResolverWrapper;
  42 import com.sun.org.apache.xerces.internal.util.DOMErrorHandlerWrapper;
  43 import com.sun.org.apache.xerces.internal.util.MessageFormatter;
  44 import com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings;

  45 import com.sun.org.apache.xerces.internal.util.SymbolTable;


  46 import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler;
  47 import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler;
  48 import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler;
  49 import com.sun.org.apache.xerces.internal.xni.XNIException;
  50 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;
  51 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;
  52 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
  53 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
  54 import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver;
  55 import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler;
  56 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
  57 import com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration;
  58 import com.sun.org.apache.xerces.internal.utils.ObjectFactory;







  59 import org.w3c.dom.DOMException;

  60 import org.w3c.dom.ls.LSResourceResolver;
  61 
  62 
  63 
  64 /**
  65  * Xerces implementation of DOMConfiguration that maintains a table of recognized parameters.
  66  *
  67  * @xerces.internal
  68  *
  69  * @author Elena Litani, IBM
  70  * @author Neeraj Bajaj, Sun Microsystems.
  71  * @version $Id: DOMConfigurationImpl.java,v 1.9 2010-11-01 04:39:37 joehw Exp $
  72  */
  73 public class DOMConfigurationImpl extends ParserConfigurationSettings
  74     implements XMLParserConfiguration, DOMConfiguration {
  75 
  76     //
  77     // Constants
  78     //
  79 
  80     // feature identifiers
  81 
  82     /** Feature identifier: validation. */
  83     protected static final String XERCES_VALIDATION =


 141 
 142     /** Property identifier: entity resolver. */
 143     protected static final String ENTITY_RESOLVER =
 144         Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
 145 
 146     /** Property identifier: JAXP schema language / DOM schema-type. */
 147     protected static final String JAXP_SCHEMA_LANGUAGE =
 148     Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE;
 149 
 150     /** Property identifier: JAXP schema source/ DOM schema-location. */
 151     protected static final String JAXP_SCHEMA_SOURCE =
 152     Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE;
 153 
 154     protected static final String VALIDATION_MANAGER =
 155         Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
 156 
 157     /** Property identifier: Schema DV Factory */
 158     protected static final String SCHEMA_DV_FACTORY =
 159         Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_DV_FACTORY_PROPERTY;
 160 








 161     //
 162     // Data
 163     //
 164     XMLDocumentHandler fDocumentHandler;
 165 
 166     /** Normalization features*/
 167     protected short features = 0;
 168 
 169     protected final static short NAMESPACES          = 0x1<<0;
 170     protected final static short DTNORMALIZATION     = 0x1<<1;
 171     protected final static short ENTITIES            = 0x1<<2;
 172     protected final static short CDATA               = 0x1<<3;
 173     protected final static short SPLITCDATA          = 0x1<<4;
 174     protected final static short COMMENTS            = 0x1<<5;
 175     protected final static short VALIDATE            = 0x1<<6;
 176     protected final static short PSVI                = 0x1<<7;
 177     protected final static short WELLFORMED          = 0x1<<8;
 178     protected final static short NSDECL              = 0x1<<9;
 179 
 180     protected final static short INFOSET_TRUE_PARAMS = NAMESPACES | COMMENTS | WELLFORMED | NSDECL;


 259         setFeature(SCHEMA_FULL_CHECKING, false);
 260         setFeature(DYNAMIC_VALIDATION, false);
 261         setFeature(NORMALIZE_DATA, false);
 262         setFeature(XERCES_NAMESPACES, true);
 263         setFeature(SEND_PSVI, true);
 264         setFeature(NAMESPACE_GROWTH, false);
 265 
 266         // add default recognized properties
 267         final String[] recognizedProperties = {
 268             XML_STRING,
 269             SYMBOL_TABLE,
 270             ERROR_HANDLER,
 271             ENTITY_RESOLVER,
 272             ERROR_REPORTER,
 273             ENTITY_MANAGER,
 274             VALIDATION_MANAGER,
 275             GRAMMAR_POOL,
 276             JAXP_SCHEMA_SOURCE,
 277             JAXP_SCHEMA_LANGUAGE,
 278             DTD_VALIDATOR_FACTORY_PROPERTY,
 279             SCHEMA_DV_FACTORY


 280         };
 281         addRecognizedProperties(recognizedProperties);
 282 
 283         // set default values for normalization features
 284         features |= NAMESPACES;
 285         features |= ENTITIES;
 286         features |= COMMENTS;
 287         features |= CDATA;
 288         features |= SPLITCDATA;
 289         features |= WELLFORMED;
 290         features |= NSDECL;
 291 
 292         if (symbolTable == null) {
 293             symbolTable = new SymbolTable();
 294         }
 295         fSymbolTable = symbolTable;
 296 
 297         fComponents = new ArrayList();
 298 
 299         setProperty(SYMBOL_TABLE, fSymbolTable);
 300         fErrorReporter = new XMLErrorReporter();
 301         setProperty(ERROR_REPORTER, fErrorReporter);
 302         addComponent(fErrorReporter);
 303 
 304         setProperty(DTD_VALIDATOR_FACTORY_PROPERTY, DTDDVFactory.getInstance());
 305 
 306         XMLEntityManager manager =  new XMLEntityManager();
 307         setProperty(ENTITY_MANAGER, manager);
 308         addComponent(manager);
 309 
 310         fValidationManager = createValidationManager();
 311         setProperty(VALIDATION_MANAGER, fValidationManager);
 312 




 313 




 314         // add message formatters
 315         if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
 316             XMLMessageFormatter xmft = new XMLMessageFormatter();
 317             fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
 318             fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
 319         }
 320 
 321         // REVISIT: try to include XML Schema formatter.
 322         //          This is a hack to allow DTD configuration to be build.
 323         //
 324         if (fErrorReporter.getMessageFormatter("http://www.w3.org/TR/xml-schema-1") == null) {
 325             MessageFormatter xmft = null;
 326             try {
 327                xmft = (MessageFormatter)(
 328                     ObjectFactory.newInstance("com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter", true));
 329             } catch (Exception exception){
 330             }
 331 
 332              if (xmft !=  null) {
 333                  fErrorReporter.putMessageFormatter("http://www.w3.org/TR/xml-schema-1", xmft);




   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.dom;
  22 












  23 import com.sun.org.apache.xerces.internal.impl.Constants;
  24 import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;
  25 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
  26 import com.sun.org.apache.xerces.internal.impl.dv.DTDDVFactory;
  27 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
  28 import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
  29 import com.sun.org.apache.xerces.internal.util.DOMEntityResolverWrapper;
  30 import com.sun.org.apache.xerces.internal.util.DOMErrorHandlerWrapper;
  31 import com.sun.org.apache.xerces.internal.util.MessageFormatter;
  32 import com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings;
  33 import com.sun.org.apache.xerces.internal.util.PropertyState;
  34 import com.sun.org.apache.xerces.internal.util.SymbolTable;
  35 import com.sun.org.apache.xerces.internal.utils.ObjectFactory;
  36 import com.sun.org.apache.xerces.internal.utils.SecuritySupport;
  37 import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler;
  38 import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler;
  39 import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler;
  40 import com.sun.org.apache.xerces.internal.xni.XNIException;
  41 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;
  42 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;
  43 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
  44 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
  45 import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver;
  46 import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler;
  47 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
  48 import com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration;
  49 import java.io.IOException;
  50 import java.util.ArrayList;
  51 import java.util.HashMap;
  52 import java.util.Locale;
  53 import java.util.Vector;
  54 import javax.xml.XMLConstants;
  55 import org.w3c.dom.DOMConfiguration;
  56 import org.w3c.dom.DOMErrorHandler;
  57 import org.w3c.dom.DOMException;
  58 import org.w3c.dom.DOMStringList;
  59 import org.w3c.dom.ls.LSResourceResolver;
  60 
  61 

  62 /**
  63  * Xerces implementation of DOMConfiguration that maintains a table of recognized parameters.
  64  *
  65  * @xerces.internal
  66  *
  67  * @author Elena Litani, IBM
  68  * @author Neeraj Bajaj, Sun Microsystems.
  69  * @version $Id: DOMConfigurationImpl.java,v 1.9 2010-11-01 04:39:37 joehw Exp $
  70  */
  71 public class DOMConfigurationImpl extends ParserConfigurationSettings
  72     implements XMLParserConfiguration, DOMConfiguration {
  73 
  74     //
  75     // Constants
  76     //
  77 
  78     // feature identifiers
  79 
  80     /** Feature identifier: validation. */
  81     protected static final String XERCES_VALIDATION =


 139 
 140     /** Property identifier: entity resolver. */
 141     protected static final String ENTITY_RESOLVER =
 142         Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
 143 
 144     /** Property identifier: JAXP schema language / DOM schema-type. */
 145     protected static final String JAXP_SCHEMA_LANGUAGE =
 146     Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE;
 147 
 148     /** Property identifier: JAXP schema source/ DOM schema-location. */
 149     protected static final String JAXP_SCHEMA_SOURCE =
 150     Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE;
 151 
 152     protected static final String VALIDATION_MANAGER =
 153         Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
 154 
 155     /** Property identifier: Schema DV Factory */
 156     protected static final String SCHEMA_DV_FACTORY =
 157         Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_DV_FACTORY_PROPERTY;
 158 
 159     /** Property identifier: access to external dtd */
 160     protected static final String ACCESS_EXTERNAL_DTD =
 161         XMLConstants.ACCESS_EXTERNAL_DTD;
 162 
 163     /** Property identifier: access to external schema  */
 164     protected static final String ACCESS_EXTERNAL_SCHEMA =
 165         XMLConstants.ACCESS_EXTERNAL_SCHEMA;
 166 
 167     //
 168     // Data
 169     //
 170     XMLDocumentHandler fDocumentHandler;
 171 
 172     /** Normalization features*/
 173     protected short features = 0;
 174 
 175     protected final static short NAMESPACES          = 0x1<<0;
 176     protected final static short DTNORMALIZATION     = 0x1<<1;
 177     protected final static short ENTITIES            = 0x1<<2;
 178     protected final static short CDATA               = 0x1<<3;
 179     protected final static short SPLITCDATA          = 0x1<<4;
 180     protected final static short COMMENTS            = 0x1<<5;
 181     protected final static short VALIDATE            = 0x1<<6;
 182     protected final static short PSVI                = 0x1<<7;
 183     protected final static short WELLFORMED          = 0x1<<8;
 184     protected final static short NSDECL              = 0x1<<9;
 185 
 186     protected final static short INFOSET_TRUE_PARAMS = NAMESPACES | COMMENTS | WELLFORMED | NSDECL;


 265         setFeature(SCHEMA_FULL_CHECKING, false);
 266         setFeature(DYNAMIC_VALIDATION, false);
 267         setFeature(NORMALIZE_DATA, false);
 268         setFeature(XERCES_NAMESPACES, true);
 269         setFeature(SEND_PSVI, true);
 270         setFeature(NAMESPACE_GROWTH, false);
 271 
 272         // add default recognized properties
 273         final String[] recognizedProperties = {
 274             XML_STRING,
 275             SYMBOL_TABLE,
 276             ERROR_HANDLER,
 277             ENTITY_RESOLVER,
 278             ERROR_REPORTER,
 279             ENTITY_MANAGER,
 280             VALIDATION_MANAGER,
 281             GRAMMAR_POOL,
 282             JAXP_SCHEMA_SOURCE,
 283             JAXP_SCHEMA_LANGUAGE,
 284             DTD_VALIDATOR_FACTORY_PROPERTY,
 285             SCHEMA_DV_FACTORY,
 286             ACCESS_EXTERNAL_DTD,
 287             ACCESS_EXTERNAL_SCHEMA
 288         };
 289         addRecognizedProperties(recognizedProperties);
 290 
 291         // set default values for normalization features
 292         features |= NAMESPACES;
 293         features |= ENTITIES;
 294         features |= COMMENTS;
 295         features |= CDATA;
 296         features |= SPLITCDATA;
 297         features |= WELLFORMED;
 298         features |= NSDECL;
 299 
 300         if (symbolTable == null) {
 301             symbolTable = new SymbolTable();
 302         }
 303         fSymbolTable = symbolTable;
 304 
 305         fComponents = new ArrayList();
 306 
 307         setProperty(SYMBOL_TABLE, fSymbolTable);
 308         fErrorReporter = new XMLErrorReporter();
 309         setProperty(ERROR_REPORTER, fErrorReporter);
 310         addComponent(fErrorReporter);
 311 
 312         setProperty(DTD_VALIDATOR_FACTORY_PROPERTY, DTDDVFactory.getInstance());
 313 
 314         XMLEntityManager manager =  new XMLEntityManager();
 315         setProperty(ENTITY_MANAGER, manager);
 316         addComponent(manager);
 317 
 318         fValidationManager = createValidationManager();
 319         setProperty(VALIDATION_MANAGER, fValidationManager);
 320 
 321         //For DOM, the secure feature is set to true by default
 322         String accessExternal =  SecuritySupport.getDefaultAccessProperty(
 323                 Constants.SP_ACCESS_EXTERNAL_DTD, Constants.EXTERNAL_ACCESS_DEFAULT);
 324         setProperty(ACCESS_EXTERNAL_DTD, accessExternal);        
 325 
 326         accessExternal =  SecuritySupport.getDefaultAccessProperty(
 327                 Constants.SP_ACCESS_EXTERNAL_SCHEMA, Constants.EXTERNAL_ACCESS_DEFAULT);
 328         setProperty(ACCESS_EXTERNAL_SCHEMA, accessExternal);
 329 
 330         // add message formatters
 331         if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
 332             XMLMessageFormatter xmft = new XMLMessageFormatter();
 333             fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
 334             fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
 335         }
 336 
 337         // REVISIT: try to include XML Schema formatter.
 338         //          This is a hack to allow DTD configuration to be build.
 339         //
 340         if (fErrorReporter.getMessageFormatter("http://www.w3.org/TR/xml-schema-1") == null) {
 341             MessageFormatter xmft = null;
 342             try {
 343                xmft = (MessageFormatter)(
 344                     ObjectFactory.newInstance("com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter", true));
 345             } catch (Exception exception){
 346             }
 347 
 348              if (xmft !=  null) {
 349                  fErrorReporter.putMessageFormatter("http://www.w3.org/TR/xml-schema-1", xmft);