KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > parsers > XML11DTDConfiguration


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.xerces.parsers;
18
19 import java.io.IOException JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.Locale JavaDoc;
23
24 import org.apache.xerces.impl.Constants;
25 import org.apache.xerces.impl.XML11DTDScannerImpl;
26 import org.apache.xerces.impl.XML11DocumentScannerImpl;
27 import org.apache.xerces.impl.XML11NSDocumentScannerImpl;
28 import org.apache.xerces.impl.XMLDTDScannerImpl;
29 import org.apache.xerces.impl.XMLDocumentScannerImpl;
30 import org.apache.xerces.impl.XMLEntityHandler;
31 import org.apache.xerces.impl.XMLEntityManager;
32 import org.apache.xerces.impl.XMLErrorReporter;
33 import org.apache.xerces.impl.XMLNSDocumentScannerImpl;
34 import org.apache.xerces.impl.XMLVersionDetector;
35 import org.apache.xerces.impl.dtd.XML11DTDProcessor;
36 import org.apache.xerces.impl.dtd.XML11DTDValidator;
37 import org.apache.xerces.impl.dtd.XML11NSDTDValidator;
38 import org.apache.xerces.impl.dtd.XMLDTDProcessor;
39 import org.apache.xerces.impl.dtd.XMLDTDValidator;
40 import org.apache.xerces.impl.dtd.XMLNSDTDValidator;
41 import org.apache.xerces.impl.dv.DTDDVFactory;
42 import org.apache.xerces.impl.msg.XMLMessageFormatter;
43 import org.apache.xerces.impl.validation.ValidationManager;
44 import org.apache.xerces.util.ParserConfigurationSettings;
45 import org.apache.xerces.util.SymbolTable;
46 import org.apache.xerces.xni.XMLDTDContentModelHandler;
47 import org.apache.xerces.xni.XMLDTDHandler;
48 import org.apache.xerces.xni.XMLDocumentHandler;
49 import org.apache.xerces.xni.XMLLocator;
50 import org.apache.xerces.xni.XNIException;
51 import org.apache.xerces.xni.grammars.XMLGrammarPool;
52 import org.apache.xerces.xni.parser.XMLComponent;
53 import org.apache.xerces.xni.parser.XMLComponentManager;
54 import org.apache.xerces.xni.parser.XMLConfigurationException;
55 import org.apache.xerces.xni.parser.XMLDTDScanner;
56 import org.apache.xerces.xni.parser.XMLDocumentScanner;
57 import org.apache.xerces.xni.parser.XMLDocumentSource;
58 import org.apache.xerces.xni.parser.XMLEntityResolver;
59 import org.apache.xerces.xni.parser.XMLErrorHandler;
60 import org.apache.xerces.xni.parser.XMLInputSource;
61 import org.apache.xerces.xni.parser.XMLPullParserConfiguration;
62
63 /**
64  * This class is the DTD-only parser configuration
65  * used to parse XML 1.0 and XML 1.1 documents.
66  *
67  * <p>
68  * This class recognizes the following features and properties:
69  * <ul>
70  * <li>Features
71  * <ul>
72  * <li>http://xml.org/sax/features/validation</li>
73  * <li>http://xml.org/sax/features/namespaces</li>
74  * <li>http://xml.org/sax/features/external-general-entities</li>
75  * <li>http://xml.org/sax/features/external-parameter-entities</li>
76  * <li>http://apache.org/xml/features/continue-after-fatal-error</li>
77  * <li>http://apache.org/xml/features/load-external-dtd</li>
78  * </ul>
79  * <li>Properties
80  * <ul>
81  * <li>http://xml.org/sax/properties/xml-string</li>
82  * <li>http://apache.org/xml/properties/internal/symbol-table</li>
83  * <li>http://apache.org/xml/properties/internal/error-handler</li>
84  * <li>http://apache.org/xml/properties/internal/entity-resolver</li>
85  * <li>http://apache.org/xml/properties/internal/error-reporter</li>
86  * <li>http://apache.org/xml/properties/internal/entity-manager</li>
87  * <li>http://apache.org/xml/properties/internal/document-scanner</li>
88  * <li>http://apache.org/xml/properties/internal/dtd-scanner</li>
89  * <li>http://apache.org/xml/properties/internal/grammar-pool</li>
90  * <li>http://apache.org/xml/properties/internal/validator/dtd</li>
91  * <li>http://apache.org/xml/properties/internal/datatype-validator-factory</li>
92  * </ul>
93  * </ul>
94  * @author Elena Litani, IBM
95  * @author Neil Graham, IBM
96  * @author Michael Glavassevich, IBM
97  * @author John Kim, IBM
98  *
99  * @version $Id: XML11DTDConfiguration.java,v 1.2 2004/07/23 15:50:15 mrglavas Exp $
100  */

101 public class XML11DTDConfiguration extends ParserConfigurationSettings
102     implements XMLPullParserConfiguration, XML11Configurable {
103
104     //
105
// Constants
106
//
107
protected final static String JavaDoc XML11_DATATYPE_VALIDATOR_FACTORY =
108         "org.apache.xerces.impl.dv.dtd.XML11DTDDVFactoryImpl";
109
110     // feature identifiers
111

112     /** Feature identifier: validation. */
113     protected static final String JavaDoc VALIDATION =
114         Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;
115     
116     /** Feature identifier: namespaces. */
117     protected static final String JavaDoc NAMESPACES =
118         Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;
119     
120     /** Feature identifier: external general entities. */
121     protected static final String JavaDoc EXTERNAL_GENERAL_ENTITIES =
122         Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE;
123     
124     /** Feature identifier: external parameter entities. */
125     protected static final String JavaDoc EXTERNAL_PARAMETER_ENTITIES =
126         Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE;
127     
128     /** Feature identifier: continue after fatal error. */
129     protected static final String JavaDoc CONTINUE_AFTER_FATAL_ERROR =
130         Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE;
131     
132     /** Feature identifier: load external DTD. */
133     protected static final String JavaDoc LOAD_EXTERNAL_DTD =
134         Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE;
135     
136     // property identifiers
137

138     /** Property identifier: xml string. */
139     protected static final String JavaDoc XML_STRING =
140         Constants.SAX_PROPERTY_PREFIX + Constants.XML_STRING_PROPERTY;
141
142     /** Property identifier: symbol table. */
143     protected static final String JavaDoc SYMBOL_TABLE =
144         Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY;
145
146     /** Property identifier: error handler. */
147     protected static final String JavaDoc ERROR_HANDLER =
148         Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY;
149
150     /** Property identifier: entity resolver. */
151     protected static final String JavaDoc ENTITY_RESOLVER =
152         Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
153
154     /** Property identifier: error reporter. */
155     protected static final String JavaDoc ERROR_REPORTER =
156         Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
157
158     /** Property identifier: entity manager. */
159     protected static final String JavaDoc ENTITY_MANAGER =
160         Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;
161
162     /** Property identifier document scanner: */
163     protected static final String JavaDoc DOCUMENT_SCANNER =
164         Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_SCANNER_PROPERTY;
165
166     /** Property identifier: DTD scanner. */
167     protected static final String JavaDoc DTD_SCANNER =
168         Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY;
169
170     /** Property identifier: grammar pool. */
171     protected static final String JavaDoc XMLGRAMMAR_POOL =
172         Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY;
173
174     /** Property identifier: DTD loader. */
175     protected static final String JavaDoc DTD_PROCESSOR =
176         Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_PROCESSOR_PROPERTY;
177
178     /** Property identifier: DTD validator. */
179     protected static final String JavaDoc DTD_VALIDATOR =
180         Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_VALIDATOR_PROPERTY;
181
182     /** Property identifier: namespace binder. */
183     protected static final String JavaDoc NAMESPACE_BINDER =
184         Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_BINDER_PROPERTY;
185
186     /** Property identifier: datatype validator factory. */
187     protected static final String JavaDoc DATATYPE_VALIDATOR_FACTORY =
188         Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY;
189
190     protected static final String JavaDoc VALIDATION_MANAGER =
191         Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
192
193     /** Property identifier: JAXP schema language / DOM schema-type. */
194     protected static final String JavaDoc JAXP_SCHEMA_LANGUAGE =
195         Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE;
196
197     /** Property identifier: JAXP schema source/ DOM schema-location. */
198     protected static final String JavaDoc JAXP_SCHEMA_SOURCE =
199         Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE;
200
201     // debugging
202

203     /** Set to true and recompile to print exception stack trace. */
204     protected static final boolean PRINT_EXCEPTION_STACK_TRACE = false;
205
206     //
207
// Data
208
//
209
protected SymbolTable fSymbolTable;
210     protected XMLInputSource fInputSource;
211     protected ValidationManager fValidationManager;
212     protected XMLVersionDetector fVersionDetector;
213     protected XMLLocator fLocator;
214     protected Locale JavaDoc fLocale;
215     
216     /** XML 1.0 Components. */
217     protected ArrayList JavaDoc fComponents;
218     
219     /** XML 1.1. Components. */
220     protected ArrayList JavaDoc fXML11Components = null;
221     
222     /** Common components: XMLEntityManager, XMLErrorReporter */
223     protected ArrayList JavaDoc fCommonComponents = null;
224     
225     /** The document handler. */
226     protected XMLDocumentHandler fDocumentHandler;
227     
228     /** The DTD handler. */
229     protected XMLDTDHandler fDTDHandler;
230     
231     /** The DTD content model handler. */
232     protected XMLDTDContentModelHandler fDTDContentModelHandler;
233     
234     /** Last component in the document pipeline */
235     protected XMLDocumentSource fLastComponent;
236     
237     /**
238      * True if a parse is in progress. This state is needed because
239      * some features/properties cannot be set while parsing (e.g.
240      * validation and namespaces).
241      */

242     protected boolean fParseInProgress = false;
243     
244     /**
245      * fConfigUpdated is set to true if there has been any change to the configuration settings,
246      * i.e a feature or a property was changed.
247      */

248     protected boolean fConfigUpdated = false;
249     
250     //
251
// XML 1.0 components
252
//
253

254     /** The XML 1.0 Datatype validator factory. */
255     protected DTDDVFactory fDatatypeValidatorFactory;
256     
257     /** The XML 1.0 Document scanner that does namespace binding. */
258     protected XMLNSDocumentScannerImpl fNamespaceScanner;
259     
260     /** The XML 1.0 Non-namespace implementation of scanner */
261     protected XMLDocumentScannerImpl fNonNSScanner;
262     
263     /** The XML 1.0 DTD Validator: binds namespaces */
264     protected XMLDTDValidator fDTDValidator;
265     
266     /** The XML 1.0 DTD Validator that does not bind namespaces */
267     protected XMLDTDValidator fNonNSDTDValidator;
268     
269     /** The XML 1.0 DTD scanner. */
270     protected XMLDTDScanner fDTDScanner;
271     
272     /** The XML 1.0 DTD Processor . */
273     protected XMLDTDProcessor fDTDProcessor;
274     
275     //
276
// XML 1.1 components
277
//
278

279     /** The XML 1.1 datatype factory. **/
280     protected DTDDVFactory fXML11DatatypeFactory = null;
281     
282     /** The XML 1.1 document scanner that does namespace binding. **/
283     protected XML11NSDocumentScannerImpl fXML11NSDocScanner = null;
284     
285     /** The XML 1.1 document scanner that does not do namespace binding. **/
286     protected XML11DocumentScannerImpl fXML11DocScanner = null;
287     
288     /** The XML 1.1 DTD validator that does namespace binding. **/
289     protected XML11NSDTDValidator fXML11NSDTDValidator = null;
290     
291     /** The XML 1.1 DTD validator that does not do namespace binding. **/
292     protected XML11DTDValidator fXML11DTDValidator = null;
293     
294     /** The XML 1.1 DTD scanner. **/
295     protected XML11DTDScannerImpl fXML11DTDScanner = null;
296     
297     /** The XML 1.1 DTD processor. **/
298     protected XML11DTDProcessor fXML11DTDProcessor = null;
299
300     //
301
// Common components
302
//
303

304     /** Grammar pool. */
305     protected XMLGrammarPool fGrammarPool;
306
307     /** Error reporter. */
308     protected XMLErrorReporter fErrorReporter;
309
310     /** Entity manager. */
311     protected XMLEntityManager fEntityManager;
312
313     /** Current scanner */
314     protected XMLDocumentScanner fCurrentScanner;
315     
316     /** Current Datatype validator factory. */
317     protected DTDDVFactory fCurrentDVFactory;
318     
319     /** Current DTD scanner. */
320     protected XMLDTDScanner fCurrentDTDScanner;
321
322     /** Flag indiciating whether XML11 components have been initialized. */
323     private boolean f11Initialized = false;
324
325     //
326
// Constructors
327
//
328

329     /** Default constructor. */
330     public XML11DTDConfiguration() {
331         this(null, null, null);
332     } // <init>()
333

334     /**
335      * Constructs a parser configuration using the specified symbol table.
336      *
337      * @param symbolTable The symbol table to use.
338      */

339     public XML11DTDConfiguration(SymbolTable symbolTable) {
340         this(symbolTable, null, null);
341     } // <init>(SymbolTable)
342

343     /**
344      * Constructs a parser configuration using the specified symbol table and
345      * grammar pool.
346      * <p>
347      * <strong>REVISIT:</strong>
348      * Grammar pool will be updated when the new validation engine is
349      * implemented.
350      *
351      * @param symbolTable The symbol table to use.
352      * @param grammarPool The grammar pool to use.
353      */

354     public XML11DTDConfiguration(SymbolTable symbolTable, XMLGrammarPool grammarPool) {
355         this(symbolTable, grammarPool, null);
356     } // <init>(SymbolTable,XMLGrammarPool)
357

358     /**
359      * Constructs a parser configuration using the specified symbol table,
360      * grammar pool, and parent settings.
361      * <p>
362      * <strong>REVISIT:</strong>
363      * Grammar pool will be updated when the new validation engine is
364      * implemented.
365      *
366      * @param symbolTable The symbol table to use.
367      * @param grammarPool The grammar pool to use.
368      * @param parentSettings The parent settings.
369      */

370     public XML11DTDConfiguration(
371         SymbolTable symbolTable,
372         XMLGrammarPool grammarPool,
373         XMLComponentManager parentSettings) {
374         
375         super(parentSettings);
376
377         // create a vector to hold all the components in use
378
// XML 1.0 specialized components
379
fComponents = new ArrayList JavaDoc();
380         // XML 1.1 specialized components
381
fXML11Components = new ArrayList JavaDoc();
382         // Common components for XML 1.1. and XML 1.0
383
fCommonComponents = new ArrayList JavaDoc();
384
385         // create storage for recognized features and properties
386
fRecognizedFeatures = new ArrayList JavaDoc();
387         fRecognizedProperties = new ArrayList JavaDoc();
388
389         // create table for features and properties
390
fFeatures = new HashMap JavaDoc();
391         fProperties = new HashMap JavaDoc();
392
393         // add default recognized features
394
final String JavaDoc[] recognizedFeatures =
395             {
396                 CONTINUE_AFTER_FATAL_ERROR, LOAD_EXTERNAL_DTD, // from XMLDTDScannerImpl
397
VALIDATION,
398                 NAMESPACES,
399                 EXTERNAL_GENERAL_ENTITIES,
400                 EXTERNAL_PARAMETER_ENTITIES,
401                 PARSER_SETTINGS
402             };
403         addRecognizedFeatures(recognizedFeatures);
404         // set state for default features
405
fFeatures.put(VALIDATION, Boolean.FALSE);
406         fFeatures.put(NAMESPACES, Boolean.TRUE);
407         fFeatures.put(EXTERNAL_GENERAL_ENTITIES, Boolean.TRUE);
408         fFeatures.put(EXTERNAL_PARAMETER_ENTITIES, Boolean.TRUE);
409         fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE);
410         fFeatures.put(LOAD_EXTERNAL_DTD, Boolean.TRUE);
411         fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);
412
413         // add default recognized properties
414
final String JavaDoc[] recognizedProperties =
415             {
416                 SYMBOL_TABLE,
417                 ERROR_HANDLER,
418                 ENTITY_RESOLVER,
419                 ERROR_REPORTER,
420                 ENTITY_MANAGER,
421                 DOCUMENT_SCANNER,
422                 DTD_SCANNER,
423                 DTD_PROCESSOR,
424                 DTD_VALIDATOR,
425                 DATATYPE_VALIDATOR_FACTORY,
426                 VALIDATION_MANAGER,
427                 XML_STRING,
428                 XMLGRAMMAR_POOL,
429                 JAXP_SCHEMA_SOURCE,
430                 JAXP_SCHEMA_LANGUAGE};
431         addRecognizedProperties(recognizedProperties);
432         
433         if (symbolTable == null) {
434             symbolTable = new SymbolTable();
435         }
436         fSymbolTable = symbolTable;
437         fProperties.put(SYMBOL_TABLE, fSymbolTable);
438         
439         fGrammarPool = grammarPool;
440         if (fGrammarPool != null) {
441             fProperties.put(XMLGRAMMAR_POOL, fGrammarPool);
442         }
443
444         fEntityManager = new XMLEntityManager();
445         fProperties.put(ENTITY_MANAGER, fEntityManager);
446         addCommonComponent(fEntityManager);
447
448         fErrorReporter = new XMLErrorReporter();
449         fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());
450         fProperties.put(ERROR_REPORTER, fErrorReporter);
451         addCommonComponent(fErrorReporter);
452
453         fNamespaceScanner = new XMLNSDocumentScannerImpl();
454         fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner);
455         addComponent((XMLComponent) fNamespaceScanner);
456
457         fDTDScanner = new XMLDTDScannerImpl();
458         fProperties.put(DTD_SCANNER, fDTDScanner);
459         addComponent((XMLComponent) fDTDScanner);
460
461         fDTDProcessor = new XMLDTDProcessor();
462         fProperties.put(DTD_PROCESSOR, fDTDProcessor);
463         addComponent((XMLComponent) fDTDProcessor);
464
465         fDTDValidator = new XMLNSDTDValidator();
466         fProperties.put(DTD_VALIDATOR, fDTDValidator);
467         addComponent(fDTDValidator);
468         
469         fDatatypeValidatorFactory = DTDDVFactory.getInstance();
470         fProperties.put(DATATYPE_VALIDATOR_FACTORY, fDatatypeValidatorFactory);
471
472         fValidationManager = new ValidationManager();
473         fProperties.put(VALIDATION_MANAGER, fValidationManager);
474         
475         fVersionDetector = new XMLVersionDetector();
476         
477         // add message formatters
478
if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
479             XMLMessageFormatter xmft = new XMLMessageFormatter();
480             fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
481             fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
482         }
483
484         // set locale
485
try {
486             setLocale(Locale.getDefault());
487         } catch (XNIException e) {
488             // do nothing
489
// REVISIT: What is the right thing to do? -Ac
490
}
491         
492         fConfigUpdated = false;
493
494     } // <init>(SymbolTable,XMLGrammarPool)
495

496     //
497
// Public methods
498
//
499
/**
500      * Sets the input source for the document to parse.
501      *
502      * @param inputSource The document's input source.
503      *
504      * @exception XMLConfigurationException Thrown if there is a
505      * configuration error when initializing the
506      * parser.
507      * @exception IOException Thrown on I/O error.
508      *
509      * @see #parse(boolean)
510      */

511     public void setInputSource(XMLInputSource inputSource)
512         throws XMLConfigurationException, IOException JavaDoc {
513
514         // REVISIT: this method used to reset all the components and
515
// construct the pipeline. Now reset() is called
516
// in parse (boolean) just before we parse the document
517
// Should this method still throw exceptions..?
518

519         fInputSource = inputSource;
520
521     } // setInputSource(XMLInputSource)
522

523     /**
524      * Set the locale to use for messages.
525      *
526      * @param locale The locale object to use for localization of messages.
527      *
528      * @exception XNIException Thrown if the parser does not support the
529      * specified locale.
530      */

531     public void setLocale(Locale JavaDoc locale) throws XNIException {
532         fLocale = locale;
533         fErrorReporter.setLocale(locale);
534     } // setLocale(Locale)
535

536     /**
537      * Sets the document handler on the last component in the pipeline
538      * to receive information about the document.
539      *
540      * @param documentHandler The document handler.
541      */

542     public void setDocumentHandler(XMLDocumentHandler documentHandler) {
543         fDocumentHandler = documentHandler;
544         if (fLastComponent != null) {
545             fLastComponent.setDocumentHandler(fDocumentHandler);
546             if (fDocumentHandler !=null){
547                 fDocumentHandler.setDocumentSource(fLastComponent);
548             }
549         }
550     } // setDocumentHandler(XMLDocumentHandler)
551

552     /** Returns the registered document handler. */
553     public XMLDocumentHandler getDocumentHandler() {
554         return fDocumentHandler;
555     } // getDocumentHandler():XMLDocumentHandler
556

557     /**
558      * Sets the DTD handler.
559      *
560      * @param dtdHandler The DTD handler.
561      */

562     public void setDTDHandler(XMLDTDHandler dtdHandler) {
563         fDTDHandler = dtdHandler;
564     } // setDTDHandler(XMLDTDHandler)
565

566     /** Returns the registered DTD handler. */
567     public XMLDTDHandler getDTDHandler() {
568         return fDTDHandler;
569     } // getDTDHandler():XMLDTDHandler
570

571     /**
572      * Sets the DTD content model handler.
573      *
574      * @param handler The DTD content model handler.
575      */

576     public void setDTDContentModelHandler(XMLDTDContentModelHandler handler) {
577         fDTDContentModelHandler = handler;
578     } // setDTDContentModelHandler(XMLDTDContentModelHandler)
579

580     /** Returns the registered DTD content model handler. */
581     public XMLDTDContentModelHandler getDTDContentModelHandler() {
582         return fDTDContentModelHandler;
583     } // getDTDContentModelHandler():XMLDTDContentModelHandler
584

585     /**
586      * Sets the resolver used to resolve external entities. The EntityResolver
587      * interface supports resolution of public and system identifiers.
588      *
589      * @param resolver The new entity resolver. Passing a null value will
590      * uninstall the currently installed resolver.
591      */

592     public void setEntityResolver(XMLEntityResolver resolver) {
593         fProperties.put(ENTITY_RESOLVER, resolver);
594     } // setEntityResolver(XMLEntityResolver)
595

596     /**
597      * Return the current entity resolver.
598      *
599      * @return The current entity resolver, or null if none
600      * has been registered.
601      * @see #setEntityResolver
602      */

603     public XMLEntityResolver getEntityResolver() {
604         return (XMLEntityResolver)fProperties.get(ENTITY_RESOLVER);
605     } // getEntityResolver():XMLEntityResolver
606

607     /**
608      * Allow an application to register an error event handler.
609      *
610      * <p>If the application does not register an error handler, all
611      * error events reported by the SAX parser will be silently
612      * ignored; however, normal processing may not continue. It is
613      * highly recommended that all SAX applications implement an
614      * error handler to avoid unexpected bugs.</p>
615      *
616      * <p>Applications may register a new or different handler in the
617      * middle of a parse, and the SAX parser must begin using the new
618      * handler immediately.</p>
619      *
620      * @param errorHandler The error handler.
621      * @exception java.lang.NullPointerException If the handler
622      * argument is null.
623      * @see #getErrorHandler
624      */

625     public void setErrorHandler(XMLErrorHandler errorHandler) {
626         fProperties.put(ERROR_HANDLER, errorHandler);
627     } // setErrorHandler(XMLErrorHandler)
628

629     /**
630      * Return the current error handler.
631      *
632      * @return The current error handler, or null if none
633      * has been registered.
634      * @see #setErrorHandler
635      */

636     public XMLErrorHandler getErrorHandler() {
637         // REVISIT: Should this be a property?
638
return (XMLErrorHandler)fProperties.get(ERROR_HANDLER);
639     } // getErrorHandler():XMLErrorHandler
640

641
642     /**
643      * If the application decides to terminate parsing before the xml document
644      * is fully parsed, the application should call this method to free any
645      * resource allocated during parsing. For example, close all opened streams.
646      */

647     public void cleanup() {
648         fEntityManager.closeReaders();
649     }
650
651     /**
652      * Parses the specified input source.
653      *
654      * @param source The input source.
655      *
656      * @exception XNIException Throws exception on XNI error.
657      * @exception java.io.IOException Throws exception on i/o error.
658      */

659     public void parse(XMLInputSource source) throws XNIException, IOException JavaDoc {
660
661         if (fParseInProgress) {
662             // REVISIT - need to add new error message
663
throw new XNIException("FWK005 parse may not be called while parsing.");
664         }
665         fParseInProgress = true;
666
667         try {
668             setInputSource(source);
669             parse(true);
670         } catch (XNIException ex) {
671             if (PRINT_EXCEPTION_STACK_TRACE)
672                 ex.printStackTrace();
673             throw ex;
674         } catch (IOException JavaDoc ex) {
675             if (PRINT_EXCEPTION_STACK_TRACE)
676                 ex.printStackTrace();
677             throw ex;
678         } catch (RuntimeException JavaDoc ex) {
679             if (PRINT_EXCEPTION_STACK_TRACE)
680                 ex.printStackTrace();
681             throw ex;
682         } catch (Exception JavaDoc ex) {
683             if (PRINT_EXCEPTION_STACK_TRACE)
684                 ex.printStackTrace();
685             throw new XNIException(ex);
686         } finally {
687             fParseInProgress = false;
688             // close all streams opened by xerces
689
this.cleanup();
690         }
691
692     } // parse(InputSource)
693

694     public boolean parse(boolean complete) throws XNIException, IOException JavaDoc {
695         //
696
// reset and configure pipeline and set InputSource.
697
if (fInputSource != null) {
698             try {
699                 fValidationManager.reset();
700                 fVersionDetector.reset(this);
701                 resetCommon();
702
703                 short version = fVersionDetector.determineDocVersion(fInputSource);
704                 if (version == Constants.XML_VERSION_1_1) {
705                     initXML11Components();
706                     configureXML11Pipeline();
707                     resetXML11();
708                 } else {
709                     configurePipeline();
710                     reset();
711                 }
712                 
713                 // mark configuration as fixed
714
fConfigUpdated = false;
715
716                 // resets and sets the pipeline.
717
fVersionDetector.startDocumentParsing((XMLEntityHandler) fCurrentScanner, version);
718                 fInputSource = null;
719             } catch (XNIException ex) {
720                 if (PRINT_EXCEPTION_STACK_TRACE)
721                     ex.printStackTrace();
722                 throw ex;
723             } catch (IOException JavaDoc ex) {
724                 if (PRINT_EXCEPTION_STACK_TRACE)
725                     ex.printStackTrace();
726                 throw ex;
727             } catch (RuntimeException JavaDoc ex) {
728                 if (PRINT_EXCEPTION_STACK_TRACE)
729                     ex.printStackTrace();
730                 throw ex;
731             } catch (Exception JavaDoc ex) {
732                 if (PRINT_EXCEPTION_STACK_TRACE)
733                     ex.printStackTrace();
734                 throw new XNIException(ex);
735             }
736         }
737
738         try {
739             return fCurrentScanner.scanDocument(complete);
740         } catch (XNIException ex) {
741             if (PRINT_EXCEPTION_STACK_TRACE)
742                 ex.printStackTrace();
743             throw ex;
744         } catch (IOException JavaDoc ex) {
745             if (PRINT_EXCEPTION_STACK_TRACE)
746                 ex.printStackTrace();
747             throw ex;
748         } catch (RuntimeException JavaDoc ex) {
749             if (PRINT_EXCEPTION_STACK_TRACE)
750                 ex.printStackTrace();
751             throw ex;
752         } catch (Exception JavaDoc ex) {
753             if (PRINT_EXCEPTION_STACK_TRACE)
754                 ex.printStackTrace();
755             throw new XNIException(ex);
756         }
757
758     } // parse(boolean):boolean
759

760     /**
761      * Returns the state of a feature.
762      *
763      * @param featureId The feature identifier.
764          * @return true if the feature is supported
765      *
766      * @throws XMLConfigurationException Thrown for configuration error.
767      * In general, components should
768      * only throw this exception if
769      * it is <strong>really</strong>
770      * a critical error.
771      */

772     public boolean getFeature(String JavaDoc featureId)
773         throws XMLConfigurationException {
774             // make this feature special
775
if (featureId.equals(PARSER_SETTINGS)){
776             return fConfigUpdated;
777         }
778         return super.getFeature(featureId);
779
780     } // getFeature(String):boolean
781

782     /**
783      * Set the state of a feature.
784      *
785      * Set the state of any feature in a SAX2 parser. The parser
786      * might not recognize the feature, and if it does recognize
787      * it, it might not be able to fulfill the request.
788      *
789      * @param featureId The unique identifier (URI) of the feature.
790      * @param state The requested state of the feature (true or false).
791      *
792      * @exception org.apache.xerces.xni.parser.XMLConfigurationException If the
793      * requested feature is not known.
794      */

795     public void setFeature(String JavaDoc featureId, boolean state)
796         throws XMLConfigurationException {
797         fConfigUpdated = true;
798         // forward to every XML 1.0 component
799
int count = fComponents.size();
800         for (int i = 0; i < count; i++) {
801             XMLComponent c = (XMLComponent) fComponents.get(i);
802             c.setFeature(featureId, state);
803         }
804         // forward it to common components
805
count = fCommonComponents.size();
806         for (int i = 0; i < count; i++) {
807             XMLComponent c = (XMLComponent) fCommonComponents.get(i);
808             c.setFeature(featureId, state);
809         }
810                 
811         // forward to every XML 1.1 component
812
count = fXML11Components.size();
813         for (int i = 0; i < count; i++) {
814             XMLComponent c = (XMLComponent) fXML11Components.get(i);
815             try{
816                 c.setFeature(featureId, state);
817             }
818             catch (Exception JavaDoc e){
819                 // no op
820
}
821         }
822         // save state if noone "objects"
823
super.setFeature(featureId, state);
824
825     } // setFeature(String,boolean)
826

827     /**
828      * setProperty
829      *
830      * @param propertyId
831      * @param value
832      */

833     public void setProperty(String JavaDoc propertyId, Object JavaDoc value)
834         throws XMLConfigurationException {
835         fConfigUpdated = true;
836         // forward to every XML 1.0 component
837
int count = fComponents.size();
838         for (int i = 0; i < count; i++) {
839             XMLComponent c = (XMLComponent) fComponents.get(i);
840             c.setProperty(propertyId, value);
841         }
842         // forward it to every common Component
843
count = fCommonComponents.size();
844         for (int i = 0; i < count; i++) {
845             XMLComponent c = (XMLComponent) fCommonComponents.get(i);
846             c.setProperty(propertyId, value);
847         }
848         // forward it to every XML 1.1 component
849
count = fXML11Components.size();
850         for (int i = 0; i < count; i++) {
851             XMLComponent c = (XMLComponent) fXML11Components.get(i);
852             try{
853                 c.setProperty(propertyId, value);
854             }
855             catch (Exception JavaDoc e){
856                 // ignore it
857
}
858         }
859
860         // store value if noone "objects"
861
super.setProperty(propertyId, value);
862
863     } // setProperty(String,Object)
864

865
866     /** Returns the locale. */
867     public Locale JavaDoc getLocale() {
868         return fLocale;
869     } // getLocale():Locale
870

871     /**
872      * reset all XML 1.0 components before parsing and namespace context
873      */

874     protected void reset() throws XNIException {
875         int count = fComponents.size();
876         for (int i = 0; i < count; i++) {
877             XMLComponent c = (XMLComponent) fComponents.get(i);
878             c.reset(this);
879         }
880
881     } // reset()
882

883     /**
884      * reset all common components before parsing
885      */

886     protected void resetCommon() throws XNIException {
887         // reset common components
888
int count = fCommonComponents.size();
889         for (int i = 0; i < count; i++) {
890             XMLComponent c = (XMLComponent) fCommonComponents.get(i);
891             c.reset(this);
892         }
893
894     } // resetCommon()
895

896     /**
897      * reset all components before parsing and namespace context
898      */

899     protected void resetXML11() throws XNIException {
900         // reset every component
901
int count = fXML11Components.size();
902         for (int i = 0; i < count; i++) {
903             XMLComponent c = (XMLComponent) fXML11Components.get(i);
904             c.reset(this);
905         }
906
907     } // resetXML11()
908

909     /**
910      * Configures the XML 1.1 pipeline.
911      * Note: this method also resets the new XML11 components.
912      */

913     protected void configureXML11Pipeline() {
914         if (fCurrentDVFactory != fXML11DatatypeFactory) {
915             fCurrentDVFactory = fXML11DatatypeFactory;
916             setProperty(DATATYPE_VALIDATOR_FACTORY, fCurrentDVFactory);
917         }
918         if (fCurrentDTDScanner != fXML11DTDScanner) {
919             fCurrentDTDScanner = fXML11DTDScanner;
920             setProperty(DTD_SCANNER, fCurrentDTDScanner);
921             setProperty(DTD_PROCESSOR, fXML11DTDProcessor);
922         }
923
924         fXML11DTDScanner.setDTDHandler(fXML11DTDProcessor);
925         fXML11DTDProcessor.setDTDSource(fXML11DTDScanner);
926         fXML11DTDProcessor.setDTDHandler(fDTDHandler);
927         if (fDTDHandler != null) {
928             fDTDHandler.setDTDSource(fXML11DTDProcessor);
929         }
930
931         fXML11DTDScanner.setDTDContentModelHandler(fXML11DTDProcessor);
932         fXML11DTDProcessor.setDTDContentModelSource(fXML11DTDScanner);
933         fXML11DTDProcessor.setDTDContentModelHandler(fDTDContentModelHandler);
934         if (fDTDContentModelHandler != null) {
935             fDTDContentModelHandler.setDTDContentModelSource(fXML11DTDProcessor);
936         }
937
938         // setup XML 1.1 document pipeline
939
if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
940             if (fCurrentScanner != fXML11NSDocScanner) {
941                 fCurrentScanner = fXML11NSDocScanner;
942                 setProperty(DOCUMENT_SCANNER, fXML11NSDocScanner);
943                 setProperty(DTD_VALIDATOR, fXML11NSDTDValidator);
944             }
945
946             fXML11NSDocScanner.setDTDValidator(fXML11NSDTDValidator);
947             fXML11NSDocScanner.setDocumentHandler(fXML11NSDTDValidator);
948             fXML11NSDTDValidator.setDocumentSource(fXML11NSDocScanner);
949             fXML11NSDTDValidator.setDocumentHandler(fDocumentHandler);
950
951             if (fDocumentHandler != null) {
952                 fDocumentHandler.setDocumentSource(fXML11NSDTDValidator);
953             }
954             fLastComponent = fXML11NSDTDValidator;
955
956         } else {
957             // create components
958
if (fXML11DocScanner == null) {
959                     // non namespace document pipeline
960
fXML11DocScanner = new XML11DocumentScannerImpl();
961                     addXML11Component(fXML11DocScanner);
962                     fXML11DTDValidator = new XML11DTDValidator();
963                     addXML11Component(fXML11DTDValidator);
964               }
965             if (fCurrentScanner != fXML11DocScanner) {
966                 fCurrentScanner = fXML11DocScanner;
967                 setProperty(DOCUMENT_SCANNER, fXML11DocScanner);
968                 setProperty(DTD_VALIDATOR, fXML11DTDValidator);
969             }
970             fXML11DocScanner.setDocumentHandler(fXML11DTDValidator);
971             fXML11DTDValidator.setDocumentSource(fXML11DocScanner);
972             fXML11DTDValidator.setDocumentHandler(fDocumentHandler);
973
974             if (fDocumentHandler != null) {
975                 fDocumentHandler.setDocumentSource(fXML11DTDValidator);
976             }
977             fLastComponent = fXML11DTDValidator;
978         }
979
980     } // configureXML11Pipeline()
981

982     /** Configures the pipeline. */
983     protected void configurePipeline() {
984         if (fCurrentDVFactory != fDatatypeValidatorFactory) {
985             fCurrentDVFactory = fDatatypeValidatorFactory;
986             // use XML 1.0 datatype library
987
setProperty(DATATYPE_VALIDATOR_FACTORY, fCurrentDVFactory);
988         }
989
990         // setup DTD pipeline
991
if (fCurrentDTDScanner != fDTDScanner) {
992             fCurrentDTDScanner = fDTDScanner;
993             setProperty(DTD_SCANNER, fCurrentDTDScanner);
994             setProperty(DTD_PROCESSOR, fDTDProcessor);
995         }
996         fDTDScanner.setDTDHandler(fDTDProcessor);
997         fDTDProcessor.setDTDSource(fDTDScanner);
998         fDTDProcessor.setDTDHandler(fDTDHandler);
999         if (fDTDHandler != null) {
1000            fDTDHandler.setDTDSource(fDTDProcessor);
1001        }
1002
1003        fDTDScanner.setDTDContentModelHandler(fDTDProcessor);
1004        fDTDProcessor.setDTDContentModelSource(fDTDScanner);
1005        fDTDProcessor.setDTDContentModelHandler(fDTDContentModelHandler);
1006        if (fDTDContentModelHandler != null) {
1007            fDTDContentModelHandler.setDTDContentModelSource(fDTDProcessor);
1008        }
1009
1010        // setup document pipeline
1011
if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
1012            if (fCurrentScanner != fNamespaceScanner) {
1013                fCurrentScanner = fNamespaceScanner;
1014                setProperty(DOCUMENT_SCANNER, fNamespaceScanner);
1015                setProperty(DTD_VALIDATOR, fDTDValidator);
1016            }
1017            fNamespaceScanner.setDTDValidator(fDTDValidator);
1018            fNamespaceScanner.setDocumentHandler(fDTDValidator);
1019            fDTDValidator.setDocumentSource(fNamespaceScanner);
1020            fDTDValidator.setDocumentHandler(fDocumentHandler);
1021            if (fDocumentHandler != null) {
1022                fDocumentHandler.setDocumentSource(fDTDValidator);
1023            }
1024            fLastComponent = fDTDValidator;
1025        } else {
1026            // create components
1027
if (fNonNSScanner == null) {
1028                fNonNSScanner = new XMLDocumentScannerImpl();
1029                fNonNSDTDValidator = new XMLDTDValidator();
1030                // add components
1031
addComponent((XMLComponent) fNonNSScanner);
1032                addComponent((XMLComponent) fNonNSDTDValidator);
1033            }
1034            if (fCurrentScanner != fNonNSScanner) {
1035                fCurrentScanner = fNonNSScanner;
1036                setProperty(DOCUMENT_SCANNER, fNonNSScanner);
1037                setProperty(DTD_VALIDATOR, fNonNSDTDValidator);
1038            }
1039
1040            fNonNSScanner.setDocumentHandler(fNonNSDTDValidator);
1041            fNonNSDTDValidator.setDocumentSource(fNonNSScanner);
1042            fNonNSDTDValidator.setDocumentHandler(fDocumentHandler);
1043            if (fDocumentHandler != null) {
1044                fDocumentHandler.setDocumentSource(fNonNSDTDValidator);
1045            }
1046            fLastComponent = fNonNSDTDValidator;
1047        }
1048
1049    } // configurePipeline()
1050

1051
1052    // features and properties
1053

1054    /**
1055     * Check a feature. If feature is know and supported, this method simply
1056     * returns. Otherwise, the appropriate exception is thrown.
1057     *
1058     * @param featureId The unique identifier (URI) of the feature.
1059     *
1060     * @throws XMLConfigurationException Thrown for configuration error.
1061     * In general, components should
1062     * only throw this exception if
1063     * it is <strong>really</strong>
1064     * a critical error.
1065     */

1066    protected void checkFeature(String JavaDoc featureId) throws XMLConfigurationException {
1067
1068        //
1069
// Xerces Features
1070
//
1071

1072        if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) {
1073            final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length();
1074            
1075            //
1076
// http://apache.org/xml/features/validation/dynamic
1077
// Allows the parser to validate a document only when it
1078
// contains a grammar. Validation is turned on/off based
1079
// on each document instance, automatically.
1080
//
1081
if (suffixLength == Constants.DYNAMIC_VALIDATION_FEATURE.length() &&
1082                featureId.endsWith(Constants.DYNAMIC_VALIDATION_FEATURE)) {
1083                return;
1084            }
1085
1086            //
1087
// http://apache.org/xml/features/validation/default-attribute-values
1088
//
1089
if (suffixLength == Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE.length() &&
1090                featureId.endsWith(Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE)) {
1091                // REVISIT
1092
short type = XMLConfigurationException.NOT_SUPPORTED;
1093                throw new XMLConfigurationException(type, featureId);
1094            }
1095            //
1096
// http://apache.org/xml/features/validation/default-attribute-values
1097
//
1098
if (suffixLength == Constants.VALIDATE_CONTENT_MODELS_FEATURE.length() &&
1099                featureId.endsWith(Constants.VALIDATE_CONTENT_MODELS_FEATURE)) {
1100                // REVISIT
1101
short type = XMLConfigurationException.NOT_SUPPORTED;
1102                throw new XMLConfigurationException(type, featureId);
1103            }
1104            //
1105
// http://apache.org/xml/features/validation/nonvalidating/load-dtd-grammar
1106
//
1107
if (suffixLength == Constants.LOAD_DTD_GRAMMAR_FEATURE.length() &&
1108                featureId.endsWith(Constants.LOAD_DTD_GRAMMAR_FEATURE)) {
1109                return;
1110            }
1111            //
1112
// http://apache.org/xml/features/validation/nonvalidating/load-external-dtd
1113
//
1114
if (suffixLength == Constants.LOAD_EXTERNAL_DTD_FEATURE.length() &&
1115                featureId.endsWith(Constants.LOAD_EXTERNAL_DTD_FEATURE)) {
1116                return;
1117            }
1118
1119            //
1120
// http://apache.org/xml/features/validation/default-attribute-values
1121
//
1122
if (suffixLength == Constants.VALIDATE_DATATYPES_FEATURE.length() &&
1123                featureId.endsWith(Constants.VALIDATE_DATATYPES_FEATURE)) {
1124                short type = XMLConfigurationException.NOT_SUPPORTED;
1125                throw new XMLConfigurationException(type, featureId);
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                short type = XMLConfigurationException.NOT_SUPPORTED;
1132                throw new XMLConfigurationException(type, featureId);
1133            }
1134        }
1135
1136        //
1137
// Not recognized
1138
//
1139

1140        super.checkFeature(featureId);
1141
1142    } // checkFeature(String)
1143

1144    /**
1145     * Check a property. If the property is know and supported, this method
1146     * simply returns. Otherwise, the appropriate exception is thrown.
1147     *
1148     * @param propertyId The unique identifier (URI) of the property
1149     * being set.
1150     *
1151     * @throws XMLConfigurationException Thrown for configuration error.
1152     * In general, components should
1153     * only throw this exception if
1154     * it is <strong>really</strong>
1155     * a critical error.
1156     */

1157    protected void checkProperty(String JavaDoc propertyId) throws XMLConfigurationException {
1158
1159        //
1160
// Xerces Properties
1161
//
1162

1163        if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
1164            final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length();
1165
1166            if (suffixLength == Constants.DTD_SCANNER_PROPERTY.length() &&
1167                propertyId.endsWith(Constants.DTD_SCANNER_PROPERTY)) {
1168                return;
1169            }
1170        }
1171        
1172        // special cases
1173
if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) {
1174            final int suffixLength = propertyId.length() - Constants.SAX_PROPERTY_PREFIX.length();
1175            
1176            //
1177
// http://xml.org/sax/properties/xml-string
1178
// Value type: String
1179
// Access: read-only
1180
// Get the literal string of characters associated with the
1181
// current event. If the parser recognises and supports this
1182
// property but is not currently parsing text, it should return
1183
// null (this is a good way to check for availability before the
1184
// parse begins).
1185
//
1186
if (suffixLength == Constants.XML_STRING_PROPERTY.length() &&
1187                propertyId.endsWith(Constants.XML_STRING_PROPERTY)) {
1188                // REVISIT - we should probably ask xml-dev for a precise
1189
// definition of what this is actually supposed to return, and
1190
// in exactly which circumstances.
1191
short type = XMLConfigurationException.NOT_SUPPORTED;
1192                throw new XMLConfigurationException(type, propertyId);
1193            }
1194        }
1195
1196        //
1197
// Not recognized
1198
//
1199

1200        super.checkProperty(propertyId);
1201
1202    } // checkProperty(String)
1203

1204
1205    /**
1206     * Adds a component to the parser configuration. This method will
1207     * also add all of the component's recognized features and properties
1208     * to the list of default recognized features and properties.
1209     *
1210     * @param component The component to add.
1211     */

1212    protected void addComponent(XMLComponent component) {
1213
1214        // don't add a component more than once
1215
if (fComponents.contains(component)) {
1216            return;
1217        }
1218        fComponents.add(component);
1219        addRecognizedParamsAndSetDefaults(component);
1220    
1221    } // addComponent(XMLComponent)
1222

1223    /**
1224     * Adds common component to the parser configuration. This method will
1225     * also add all of the component's recognized features and properties
1226     * to the list of default recognized features and properties.
1227     *
1228     * @param component The component to add.
1229     */

1230    protected void addCommonComponent(XMLComponent component) {
1231
1232        // don't add a component more than once
1233
if (fCommonComponents.contains(component)) {
1234            return;
1235        }
1236        fCommonComponents.add(component);
1237        addRecognizedParamsAndSetDefaults(component);
1238
1239    } // addCommonComponent(XMLComponent)
1240

1241    /**
1242     * Adds an XML 1.1 component to the parser configuration. This method will
1243     * also add all of the component's recognized features and properties
1244     * to the list of default recognized features and properties.
1245     *
1246     * @param component The component to add.
1247     */

1248    protected void addXML11Component(XMLComponent component) {
1249
1250        // don't add a component more than once
1251
if (fXML11Components.contains(component)) {
1252            return;
1253        }
1254        fXML11Components.add(component);
1255        addRecognizedParamsAndSetDefaults(component);
1256        
1257    } // addXML11Component(XMLComponent)
1258

1259    /**
1260     * Adds all of the component's recognized features and properties
1261     * to the list of default recognized features and properties, and
1262     * sets default values on the configuration for features and
1263     * properties which were previously absent from the configuration.
1264     *
1265     * @param component The component whose recognized features
1266     * and properties will be added to the configuration
1267     */

1268    protected void addRecognizedParamsAndSetDefaults(XMLComponent component) {
1269        
1270        // register component's recognized features
1271
String JavaDoc[] recognizedFeatures = component.getRecognizedFeatures();
1272        addRecognizedFeatures(recognizedFeatures);
1273        
1274        // register component's recognized properties
1275
String JavaDoc[] recognizedProperties = component.getRecognizedProperties();
1276        addRecognizedProperties(recognizedProperties);
1277
1278        // set default values
1279
if (recognizedFeatures != null) {
1280            for (int i = 0; i < recognizedFeatures.length; ++i) {
1281                String JavaDoc featureId = recognizedFeatures[i];
1282                Boolean JavaDoc state = component.getFeatureDefault(featureId);
1283                if (state != null) {
1284                    // Do not overwrite values already set on the configuration.
1285
if (!fFeatures.containsKey(featureId)) {
1286                        fFeatures.put(featureId, state);
1287                        // For newly added components who recognize this feature
1288
// but did not offer a default value, we need to make
1289
// sure these components will get an opportunity to read
1290
// the value before parsing begins.
1291
fConfigUpdated = true;
1292                    }
1293                }
1294            }
1295        }
1296        if (recognizedProperties != null) {
1297            for (int i = 0; i < recognizedProperties.length; ++i) {
1298                String JavaDoc propertyId = recognizedProperties[i];
1299                Object JavaDoc value = component.getPropertyDefault(propertyId);
1300                if (value != null) {
1301                    // Do not overwrite values already set on the configuration.
1302
if (!fProperties.containsKey(propertyId)) {
1303                        fProperties.put(propertyId, value);
1304                        // For newly added components who recognize this property
1305
// but did not offer a default value, we need to make
1306
// sure these components will get an opportunity to read
1307
// the value before parsing begins.
1308
fConfigUpdated = true;
1309                    }
1310                }
1311            }
1312        }
1313    }
1314
1315    private void initXML11Components() {
1316        if (!f11Initialized) {
1317
1318            // create datatype factory
1319
fXML11DatatypeFactory = DTDDVFactory.getInstance(XML11_DATATYPE_VALIDATOR_FACTORY);
1320
1321            // setup XML 1.1 DTD pipeline
1322
fXML11DTDScanner = new XML11DTDScannerImpl();
1323            addXML11Component(fXML11DTDScanner);
1324            fXML11DTDProcessor = new XML11DTDProcessor();
1325            addXML11Component(fXML11DTDProcessor);
1326
1327            // setup XML 1.1. document pipeline - namespace aware
1328
fXML11NSDocScanner = new XML11NSDocumentScannerImpl();
1329            addXML11Component(fXML11NSDocScanner);
1330            fXML11NSDTDValidator = new XML11NSDTDValidator();
1331            addXML11Component(fXML11NSDTDValidator);
1332                
1333            f11Initialized = true;
1334        }
1335    }
1336
1337} // class XML11DTDConfiguration
1338
Popular Tags