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