KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > parsers > XML11Configuration


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001-2004 The Apache Software Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Xerces" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 2002, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58
59 package com.sun.org.apache.xerces.internal.parsers;
60
61 import java.io.IOException JavaDoc;
62 import java.util.ArrayList JavaDoc;
63 import java.util.HashMap JavaDoc;
64 import java.util.Locale JavaDoc;
65
66 import com.sun.org.apache.xerces.internal.impl.Constants;
67 import com.sun.org.apache.xerces.internal.impl.XML11DTDScannerImpl;
68 import com.sun.org.apache.xerces.internal.impl.XML11DocumentScannerImpl;
69 import com.sun.org.apache.xerces.internal.impl.XML11NSDocumentScannerImpl;
70 import com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl;
71 import com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl;
72 import com.sun.org.apache.xerces.internal.impl.XMLEntityHandler;
73 import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;
74 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
75 import com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl;
76 import com.sun.org.apache.xerces.internal.impl.XMLVersionDetector;
77 import com.sun.org.apache.xerces.internal.impl.dtd.XML11DTDProcessor;
78 import com.sun.org.apache.xerces.internal.impl.dtd.XML11DTDValidator;
79 import com.sun.org.apache.xerces.internal.impl.dtd.XML11NSDTDValidator;
80 import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDProcessor;
81 import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator;
82 import com.sun.org.apache.xerces.internal.impl.dtd.XMLNSDTDValidator;
83 import com.sun.org.apache.xerces.internal.impl.dv.DTDDVFactory;
84 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
85 import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
86 import com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator;
87 import com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter;
88 import com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings;
89 import com.sun.org.apache.xerces.internal.util.SymbolTable;
90 import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler;
91 import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler;
92 import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler;
93 import com.sun.org.apache.xerces.internal.xni.XMLLocator;
94 import com.sun.org.apache.xerces.internal.xni.XNIException;
95 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;
96 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;
97 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
98 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
99 import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner;
100 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner;
101 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource;
102 import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver;
103 import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler;
104 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
105 import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration;
106
107 /**
108  * This class is the configuration used to parse XML 1.0 and XML 1.1 documents.
109  * This is the default Xerces configuration.
110  *
111  * @author Elena Litani, IBM
112  * @author Neil Graham, IBM
113  * @author Michael Glavassevich, IBM
114  *
115  * @version $Id: XML11Configuration.java,v 1.17 2004/04/12 21:56:02 mrglavas Exp $
116  */

117 public class XML11Configuration extends ParserConfigurationSettings
118 implements XMLPullParserConfiguration {
119     
120     //
121
// Constants
122
//
123
protected final static String JavaDoc XML11_DATATYPE_VALIDATOR_FACTORY =
124     "com.sun.org.apache.xerces.internal.impl.dv.dtd.XML11DTDDVFactoryImpl";
125     
126     // feature identifiers
127

128     /** Feature identifier: warn on duplicate attribute definition. */
129     protected static final String JavaDoc WARN_ON_DUPLICATE_ATTDEF =
130     Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE;
131     
132     /** Feature identifier: warn on duplicate entity definition. */
133     protected static final String JavaDoc WARN_ON_DUPLICATE_ENTITYDEF =
134     Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ENTITYDEF_FEATURE;
135     
136     /** Feature identifier: warn on undeclared element definition. */
137     protected static final String JavaDoc WARN_ON_UNDECLARED_ELEMDEF =
138     Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_UNDECLARED_ELEMDEF_FEATURE;
139     
140     /** Feature identifier: allow Java encodings. */
141     protected static final String JavaDoc ALLOW_JAVA_ENCODINGS =
142     Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE;
143     
144     /** Feature identifier: continue after fatal error. */
145     protected static final String JavaDoc CONTINUE_AFTER_FATAL_ERROR =
146     Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE;
147     
148     /** Feature identifier: load external DTD. */
149     protected static final String JavaDoc LOAD_EXTERNAL_DTD =
150     Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE;
151     
152     /** Feature identifier: notify built-in refereces. */
153     protected static final String JavaDoc NOTIFY_BUILTIN_REFS =
154     Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_BUILTIN_REFS_FEATURE;
155     
156     /** Feature identifier: notify character refereces. */
157     protected static final String JavaDoc NOTIFY_CHAR_REFS =
158     Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_CHAR_REFS_FEATURE;
159     
160     /** Feature identifier: expose schema normalized value */
161     protected static final String JavaDoc NORMALIZE_DATA =
162     Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE;
163     
164     /** Feature identifier: send element default value via characters() */
165     protected static final String JavaDoc SCHEMA_ELEMENT_DEFAULT =
166     Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_ELEMENT_DEFAULT;
167     
168     /** Feature identifier: augment PSVI */
169     protected static final String JavaDoc SCHEMA_AUGMENT_PSVI =
170     Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI;
171     
172     /** feature identifier: XML Schema validation */
173     protected static final String JavaDoc XMLSCHEMA_VALIDATION =
174     Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE;
175     
176     /** feature identifier: XML Schema validation -- full checking */
177     protected static final String JavaDoc XMLSCHEMA_FULL_CHECKING =
178     Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_FULL_CHECKING;
179     
180     // feature identifiers
181

182     /** Feature identifier: validation. */
183     protected static final String JavaDoc VALIDATION =
184     Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;
185     
186     /** Feature identifier: namespaces. */
187     protected static final String JavaDoc NAMESPACES =
188     Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;
189     
190     /** Feature identifier: external general entities. */
191     protected static final String JavaDoc EXTERNAL_GENERAL_ENTITIES =
192     Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE;
193     
194     /** Feature identifier: external parameter entities. */
195     protected static final String JavaDoc EXTERNAL_PARAMETER_ENTITIES =
196     Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE;
197     
198     protected static final String JavaDoc EXPAND_URIS = Constants.SAX_FEATURE_PREFIX + Constants.RESOLVE_DTD_URIS_FEATURE;
199     protected static final String JavaDoc XML_VERSION_SUPPORT = Constants.SAX_FEATURE_PREFIX + Constants.XML_11_FEATURE;
200     protected static final String JavaDoc NORMALIZAION_CHECKS = Constants.SAX_FEATURE_PREFIX + Constants.UNICODE_NORMALIZATION_CHECKING_FEATURE;
201     
202     // property identifiers
203

204     
205     /** Property identifier: xml string. */
206     protected static final String JavaDoc XML_STRING =
207     Constants.SAX_PROPERTY_PREFIX + Constants.XML_STRING_PROPERTY;
208     
209     /** Property identifier: symbol table. */
210     protected static final String JavaDoc SYMBOL_TABLE =
211     Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY;
212     
213     /** Property identifier: error handler. */
214     protected static final String JavaDoc ERROR_HANDLER =
215     Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY;
216     
217     /** Property identifier: entity resolver. */
218     protected static final String JavaDoc ENTITY_RESOLVER =
219     Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
220     
221     
222     /** Property identifier: XML Schema validator. */
223     protected static final String JavaDoc SCHEMA_VALIDATOR =
224     Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_VALIDATOR_PROPERTY;
225     
226     /** Property identifier: schema location. */
227     protected static final String JavaDoc SCHEMA_LOCATION =
228     Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_LOCATION;
229     
230     /** Property identifier: no namespace schema location. */
231     protected static final String JavaDoc SCHEMA_NONS_LOCATION =
232     Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_NONS_LOCATION;
233     
234     // property identifiers
235

236     /** Property identifier: error reporter. */
237     protected static final String JavaDoc ERROR_REPORTER =
238     Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
239     
240     /** Property identifier: entity manager. */
241     protected static final String JavaDoc ENTITY_MANAGER =
242     Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;
243     
244     /** Property identifier document scanner: */
245     protected static final String JavaDoc DOCUMENT_SCANNER =
246     Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_SCANNER_PROPERTY;
247     
248     /** Property identifier: DTD scanner. */
249     protected static final String JavaDoc DTD_SCANNER =
250     Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY;
251     
252     /** Property identifier: grammar pool. */
253     protected static final String JavaDoc XMLGRAMMAR_POOL =
254     Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY;
255     
256     /** Property identifier: DTD loader. */
257     protected static final String JavaDoc DTD_PROCESSOR =
258     Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_PROCESSOR_PROPERTY;
259     
260     /** Property identifier: DTD validator. */
261     protected static final String JavaDoc DTD_VALIDATOR =
262     Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_VALIDATOR_PROPERTY;
263     
264     /** Property identifier: namespace binder. */
265     protected static final String JavaDoc NAMESPACE_BINDER =
266     Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_BINDER_PROPERTY;
267     
268     /** Property identifier: datatype validator factory. */
269     protected static final String JavaDoc DATATYPE_VALIDATOR_FACTORY =
270     Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY;
271     
272     protected static final String JavaDoc VALIDATION_MANAGER =
273     Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
274     
275     /** Property identifier: JAXP schema language / DOM schema-type. */
276     protected static final String JavaDoc JAXP_SCHEMA_LANGUAGE =
277     Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE;
278     
279     /** Property identifier: JAXP schema source/ DOM schema-location. */
280     protected static final String JavaDoc JAXP_SCHEMA_SOURCE =
281     Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE;
282     
283     
284     // debugging
285

286     /** Set to true and recompile to print exception stack trace. */
287     protected static final boolean PRINT_EXCEPTION_STACK_TRACE = false;
288     
289     //
290
// Data
291
//
292

293     protected SymbolTable fSymbolTable;
294     protected XMLInputSource fInputSource;
295     protected ValidationManager fValidationManager;
296     protected XMLVersionDetector fVersionDetector;
297     protected XMLLocator fLocator;
298     protected Locale JavaDoc fLocale;
299     
300     /** XML 1.0 Components. */
301     protected ArrayList JavaDoc fComponents;
302     
303     /** XML 1.1. Components. */
304     protected ArrayList JavaDoc fXML11Components = null;
305     
306     /** Common components: XMLEntityManager, XMLErrorReporter, XMLSchemaValidator */
307     protected ArrayList JavaDoc fCommonComponents = null;
308     
309     /** The document handler. */
310     protected XMLDocumentHandler fDocumentHandler;
311     
312     /** The DTD handler. */
313     protected XMLDTDHandler fDTDHandler;
314     
315     /** The DTD content model handler. */
316     protected XMLDTDContentModelHandler fDTDContentModelHandler;
317     
318     /** Last component in the document pipeline */
319     protected XMLDocumentSource fLastComponent;
320     
321     /**
322      * True if a parse is in progress. This state is needed because
323      * some features/properties cannot be set while parsing (e.g.
324      * validation and namespaces).
325      */

326     protected boolean fParseInProgress = false;
327     
328     /** fConfigUpdated is set to true if there has been any change to the configuration settings,
329      * i.e a feature or a property was changed.
330      */

331     protected boolean fConfigUpdated = false;
332     
333     //
334
// XML 1.0 components
335
//
336

337     /** The XML 1.0 Datatype validator factory. */
338     protected DTDDVFactory fDatatypeValidatorFactory;
339     
340     /** The XML 1.0 Document scanner that does namespace binding. */
341     protected XMLNSDocumentScannerImpl fNamespaceScanner;
342     /** The XML 1.0 Non-namespace implementation of scanner */
343     protected XMLDocumentScannerImpl fNonNSScanner;
344     /** The XML 1.0 DTD Validator: binds namespaces */
345     protected XMLDTDValidator fDTDValidator;
346     /** The XML 1.0 DTD Validator that does not bind namespaces */
347     protected XMLDTDValidator fNonNSDTDValidator;
348     /** The XML 1.0 DTD scanner. */
349     protected XMLDTDScanner fDTDScanner;
350     /** The XML 1.0 DTD Processor . */
351     protected XMLDTDProcessor fDTDProcessor;
352     
353     //
354
// XML 1.1 components
355
//
356

357     /** The XML 1.1 datatype factory. **/
358     protected DTDDVFactory fXML11DatatypeFactory = null;
359     
360     /** The XML 1.1 document scanner that does namespace binding. **/
361     protected XML11NSDocumentScannerImpl fXML11NSDocScanner = null;
362     
363     /** The XML 1.1 document scanner that does not do namespace binding. **/
364     protected XML11DocumentScannerImpl fXML11DocScanner = null;
365     
366     /** The XML 1.1 DTD validator that does namespace binding. **/
367     protected XML11NSDTDValidator fXML11NSDTDValidator = null;
368     
369     /** The XML 1.1 DTD validator that does not do namespace binding. **/
370     protected XML11DTDValidator fXML11DTDValidator = null;
371     
372     /** The XML 1.1 DTD scanner. **/
373     protected XML11DTDScannerImpl fXML11DTDScanner = null;
374     /** The XML 1.1 DTD processor. **/
375     protected XML11DTDProcessor fXML11DTDProcessor = null;
376     
377     //
378
// Common components
379
//
380

381     /** Grammar pool. */
382     protected XMLGrammarPool fGrammarPool;
383     
384     /** Error reporter. */
385     protected XMLErrorReporter fErrorReporter;
386     
387     /** Entity manager. */
388     protected XMLEntityManager fEntityManager;
389     
390     /** XML Schema Validator. */
391     protected XMLSchemaValidator fSchemaValidator;
392     
393     /** Current scanner */
394     protected XMLDocumentScanner fCurrentScanner;
395     /** Current Datatype validator factory. */
396     protected DTDDVFactory fCurrentDVFactory;
397     /** Current DTD scanner. */
398     protected XMLDTDScanner fCurrentDTDScanner;
399     
400     /** Flag indiciating whether XML11 components have been initialized. */
401     private boolean f11Initialized = false;
402     
403     //
404
// Constructors
405
//
406

407     /** Default constructor. */
408     public XML11Configuration() {
409         this(null, null, null);
410     } // <init>()
411

412     /**
413      * Constructs a parser configuration using the specified symbol table.
414      *
415      * @param symbolTable The symbol table to use.
416      */

417     public XML11Configuration(SymbolTable symbolTable) {
418         this(symbolTable, null, null);
419     } // <init>(SymbolTable)
420

421     /**
422      * Constructs a parser configuration using the specified symbol table and
423      * grammar pool.
424      * <p>
425      * <strong>REVISIT:</strong>
426      * Grammar pool will be updated when the new validation engine is
427      * implemented.
428      *
429      * @param symbolTable The symbol table to use.
430      * @param grammarPool The grammar pool to use.
431      */

432     public XML11Configuration(SymbolTable symbolTable, XMLGrammarPool grammarPool) {
433         this(symbolTable, grammarPool, null);
434     } // <init>(SymbolTable,XMLGrammarPool)
435

436     /**
437      * Constructs a parser configuration using the specified symbol table,
438      * grammar pool, and parent settings.
439      * <p>
440      * <strong>REVISIT:</strong>
441      * Grammar pool will be updated when the new validation engine is
442      * implemented.
443      *
444      * @param symbolTable The symbol table to use.
445      * @param grammarPool The grammar pool to use.
446      * @param parentSettings The parent settings.
447      */

448     public XML11Configuration(
449     SymbolTable symbolTable,
450     XMLGrammarPool grammarPool,
451     XMLComponentManager parentSettings) {
452         
453         super(parentSettings);
454         
455         // create a vector to hold all the components in use
456
// XML 1.0 specialized components
457
fComponents = new ArrayList JavaDoc();
458         // XML 1.1 specialized components
459
fXML11Components = new ArrayList JavaDoc();
460         // Common components for XML 1.1. and XML 1.0
461
fCommonComponents = new ArrayList JavaDoc();
462         
463         // create storage for recognized features and properties
464
fRecognizedFeatures = new ArrayList JavaDoc();
465         fRecognizedProperties = new ArrayList JavaDoc();
466         
467         // create table for features and properties
468
fFeatures = new HashMap JavaDoc();
469         fProperties = new HashMap JavaDoc();
470         
471         // add default recognized features
472
final String JavaDoc[] recognizedFeatures = {
473             CONTINUE_AFTER_FATAL_ERROR, LOAD_EXTERNAL_DTD, // from XMLDTDScannerImpl
474
VALIDATION,
475             NAMESPACES,
476             NORMALIZE_DATA, SCHEMA_ELEMENT_DEFAULT, SCHEMA_AUGMENT_PSVI,
477             // NOTE: These shouldn't really be here but since the XML Schema
478
// validator is constructed dynamically, its recognized
479
// features might not have been set and it would cause a
480
// not-recognized exception to be thrown. -Ac
481
XMLSCHEMA_VALIDATION, XMLSCHEMA_FULL_CHECKING,
482             EXTERNAL_GENERAL_ENTITIES,
483             EXTERNAL_PARAMETER_ENTITIES,
484             PARSER_SETTINGS,
485             EXPAND_URIS,
486             XML_VERSION_SUPPORT,
487             NORMALIZAION_CHECKS
488         };
489         addRecognizedFeatures(recognizedFeatures);
490         // set state for default features
491
fFeatures.put(VALIDATION, Boolean.FALSE);
492         fFeatures.put(NAMESPACES, Boolean.TRUE);
493         fFeatures.put(EXTERNAL_GENERAL_ENTITIES, Boolean.TRUE);
494         fFeatures.put(EXTERNAL_PARAMETER_ENTITIES, Boolean.TRUE);
495         fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE);
496         fFeatures.put(LOAD_EXTERNAL_DTD, Boolean.TRUE);
497         fFeatures.put(SCHEMA_ELEMENT_DEFAULT, Boolean.TRUE);
498         fFeatures.put(NORMALIZE_DATA, Boolean.TRUE);
499         fFeatures.put(SCHEMA_AUGMENT_PSVI, Boolean.TRUE);
500         fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);
501         fFeatures.put(EXPAND_URIS, Boolean.TRUE);
502         fFeatures.put(XML_VERSION_SUPPORT, Boolean.TRUE);
503         fFeatures.put(NORMALIZAION_CHECKS, Boolean.FALSE);
504         // add default recognized properties
505
final String JavaDoc[] recognizedProperties = {
506             SYMBOL_TABLE,
507             ERROR_HANDLER,
508             ENTITY_RESOLVER,
509             ERROR_REPORTER,
510             ENTITY_MANAGER,
511             DOCUMENT_SCANNER,
512             DTD_SCANNER,
513             DTD_PROCESSOR,
514             DTD_VALIDATOR,
515             DATATYPE_VALIDATOR_FACTORY,
516             VALIDATION_MANAGER,
517             SCHEMA_VALIDATOR,
518             XML_STRING,
519             XMLGRAMMAR_POOL,
520             JAXP_SCHEMA_SOURCE,
521             JAXP_SCHEMA_LANGUAGE,
522             // NOTE: These shouldn't really be here but since the XML Schema
523
// validator is constructed dynamically, its recognized
524
// properties might not have been set and it would cause a
525
// not-recognized exception to be thrown. -Ac
526
SCHEMA_LOCATION, SCHEMA_NONS_LOCATION, };
527             addRecognizedProperties(recognizedProperties);
528             
529             if (symbolTable == null) {
530                 symbolTable = new SymbolTable();
531             }
532             fSymbolTable = symbolTable;
533             fProperties.put(SYMBOL_TABLE, fSymbolTable);
534             
535             fGrammarPool = grammarPool;
536             if (fGrammarPool != null) {
537                 fProperties.put(XMLGRAMMAR_POOL, fGrammarPool);
538             }
539             
540             fEntityManager = new XMLEntityManager();
541             fProperties.put(ENTITY_MANAGER, fEntityManager);
542             addCommonComponent(fEntityManager);
543             
544             fErrorReporter = new XMLErrorReporter();
545             fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());
546             fProperties.put(ERROR_REPORTER, fErrorReporter);
547             addCommonComponent(fErrorReporter);
548             
549             fNamespaceScanner = new XMLNSDocumentScannerImpl();
550             fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner);
551             addComponent((XMLComponent) fNamespaceScanner);
552             
553             fDTDScanner = new XMLDTDScannerImpl();
554             fProperties.put(DTD_SCANNER, fDTDScanner);
555             addComponent((XMLComponent) fDTDScanner);
556             
557             fDTDProcessor = new XMLDTDProcessor();
558             fProperties.put(DTD_PROCESSOR, fDTDProcessor);
559             addComponent((XMLComponent) fDTDProcessor);
560             
561             fDTDValidator = new XMLNSDTDValidator();
562             fProperties.put(DTD_VALIDATOR, fDTDValidator);
563             addComponent(fDTDValidator);
564             
565             fDatatypeValidatorFactory = DTDDVFactory.getInstance();
566             fProperties.put(DATATYPE_VALIDATOR_FACTORY, fDatatypeValidatorFactory);
567             
568             fValidationManager = new ValidationManager();
569             fProperties.put(VALIDATION_MANAGER, fValidationManager);
570             
571             fVersionDetector = new XMLVersionDetector();
572             
573             // add message formatters
574
if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
575                 XMLMessageFormatter xmft = new XMLMessageFormatter();
576                 fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
577                 fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
578             }
579             
580             // set locale
581
try {
582                 setLocale(Locale.getDefault());
583             } catch (XNIException e) {
584                 // do nothing
585
// REVISIT: What is the right thing to do? -Ac
586
}
587             
588             fConfigUpdated = false;
589             
590     } // <init>(SymbolTable,XMLGrammarPool)
591

592     //
593
// Public methods
594
//
595
/**
596      * Sets the input source for the document to parse.
597      *
598      * @param inputSource The document's input source.
599      *
600      * @exception XMLConfigurationException Thrown if there is a
601      * configuration error when initializing the
602      * parser.
603      * @exception IOException Thrown on I/O error.
604      *
605      * @see #parse(boolean)
606      */

607     public void setInputSource(XMLInputSource inputSource)
608     throws XMLConfigurationException, IOException JavaDoc {
609         
610         // REVISIT: this method used to reset all the components and
611
// construct the pipeline. Now reset() is called
612
// in parse (boolean) just before we parse the document
613
// Should this method still throw exceptions..?
614

615         fInputSource = inputSource;
616         
617     } // setInputSource(XMLInputSource)
618

619     /**
620      * Set the locale to use for messages.
621      *
622      * @param locale The locale object to use for localization of messages.
623      *
624      * @exception XNIException Thrown if the parser does not support the
625      * specified locale.
626      */

627     public void setLocale(Locale JavaDoc locale) throws XNIException {
628         fLocale = locale;
629         fErrorReporter.setLocale(locale);
630     } // setLocale(Locale)
631
/**
632      * Sets the document handler on the last component in the pipeline
633      * to receive information about the document.
634      *
635      * @param documentHandler The document handler.
636      */

637     public void setDocumentHandler(XMLDocumentHandler documentHandler) {
638         fDocumentHandler = documentHandler;
639         if (fLastComponent != null) {
640             fLastComponent.setDocumentHandler(fDocumentHandler);
641             if (fDocumentHandler !=null){
642                 fDocumentHandler.setDocumentSource(fLastComponent);
643             }
644         }
645     } // setDocumentHandler(XMLDocumentHandler)
646

647     /** Returns the registered document handler. */
648     public XMLDocumentHandler getDocumentHandler() {
649         return fDocumentHandler;
650     } // getDocumentHandler():XMLDocumentHandler
651

652     /**
653      * Sets the DTD handler.
654      *
655      * @param dtdHandler The DTD handler.
656      */

657     public void setDTDHandler(XMLDTDHandler dtdHandler) {
658         fDTDHandler = dtdHandler;
659     } // setDTDHandler(XMLDTDHandler)
660

661     /** Returns the registered DTD handler. */
662     public XMLDTDHandler getDTDHandler() {
663         return fDTDHandler;
664     } // getDTDHandler():XMLDTDHandler
665

666     /**
667      * Sets the DTD content model handler.
668      *
669      * @param handler The DTD content model handler.
670      */

671     public void setDTDContentModelHandler(XMLDTDContentModelHandler handler) {
672         fDTDContentModelHandler = handler;
673     } // setDTDContentModelHandler(XMLDTDContentModelHandler)
674

675     /** Returns the registered DTD content model handler. */
676     public XMLDTDContentModelHandler getDTDContentModelHandler() {
677         return fDTDContentModelHandler;
678     } // getDTDContentModelHandler():XMLDTDContentModelHandler
679

680     /**
681      * Sets the resolver used to resolve external entities. The EntityResolver
682      * interface supports resolution of public and system identifiers.
683      *
684      * @param resolver The new entity resolver. Passing a null value will
685      * uninstall the currently installed resolver.
686      */

687     public void setEntityResolver(XMLEntityResolver resolver) {
688         fProperties.put(ENTITY_RESOLVER, resolver);
689     } // setEntityResolver(XMLEntityResolver)
690

691     /**
692      * Return the current entity resolver.
693      *
694      * @return The current entity resolver, or null if none
695      * has been registered.
696      * @see #setEntityResolver
697      */

698     public XMLEntityResolver getEntityResolver() {
699         return (XMLEntityResolver)fProperties.get(ENTITY_RESOLVER);
700     } // getEntityResolver():XMLEntityResolver
701

702     /**
703      * Allow an application to register an error event handler.
704      *
705      * <p>If the application does not register an error handler, all
706      * error events reported by the SAX parser will be silently
707      * ignored; however, normal processing may not continue. It is
708      * highly recommended that all SAX applications implement an
709      * error handler to avoid unexpected bugs.</p>
710      *
711      * <p>Applications may register a new or different handler in the
712      * middle of a parse, and the SAX parser must begin using the new
713      * handler immediately.</p>
714      *
715      * @param errorHandler The error handler.
716      * @exception java.lang.NullPointerException If the handler
717      * argument is null.
718      * @see #getErrorHandler
719      */

720     public void setErrorHandler(XMLErrorHandler errorHandler) {
721         fProperties.put(ERROR_HANDLER, errorHandler);
722     } // setErrorHandler(XMLErrorHandler)
723

724     /**
725      * Return the current error handler.
726      *
727      * @return The current error handler, or null if none
728      * has been registered.
729      * @see #setErrorHandler
730      */

731     public XMLErrorHandler getErrorHandler() {
732         // REVISIT: Should this be a property?
733
return (XMLErrorHandler)fProperties.get(ERROR_HANDLER);
734     } // getErrorHandler():XMLErrorHandler
735

736     
737     /**
738      * If the application decides to terminate parsing before the xml document
739      * is fully parsed, the application should call this method to free any
740      * resource allocated during parsing. For example, close all opened streams.
741      */

742     public void cleanup() {
743         fEntityManager.closeReaders();
744     }
745     
746     /**
747      * Parses the specified input source.
748      *
749      * @param source The input source.
750      *
751      * @exception XNIException Throws exception on XNI error.
752      * @exception java.io.IOException Throws exception on i/o error.
753      */

754     public void parse(XMLInputSource source) throws XNIException, IOException JavaDoc {
755         
756         if (fParseInProgress) {
757             // REVISIT - need to add new error message
758
throw new XNIException("FWK005 parse may not be called while parsing.");
759         }
760         fParseInProgress = true;
761         
762         try {
763             setInputSource(source);
764             parse(true);
765         } catch (XNIException ex) {
766             if (PRINT_EXCEPTION_STACK_TRACE)
767                 ex.printStackTrace();
768             throw ex;
769         } catch (IOException JavaDoc ex) {
770             if (PRINT_EXCEPTION_STACK_TRACE)
771                 ex.printStackTrace();
772             throw ex;
773         } catch (RuntimeException JavaDoc ex) {
774             if (PRINT_EXCEPTION_STACK_TRACE)
775                 ex.printStackTrace();
776             throw ex;
777         } catch (Exception JavaDoc ex) {
778             if (PRINT_EXCEPTION_STACK_TRACE)
779                 ex.printStackTrace();
780             throw new XNIException(ex);
781         } finally {
782             fParseInProgress = false;
783             // close all streams opened by xerces
784
this.cleanup();
785         }
786         
787     } // parse(InputSource)
788

789     public boolean parse(boolean complete) throws XNIException, IOException JavaDoc {
790         //
791
// reset and configure pipeline and set InputSource.
792
if (fInputSource != null) {
793             try {
794                 fValidationManager.reset();
795                 fVersionDetector.reset(this);
796                 resetCommon();
797                 
798                 short version = fVersionDetector.determineDocVersion(fInputSource);
799                 if (version == Constants.XML_VERSION_1_1) {
800                     initXML11Components();
801                     configureXML11Pipeline();
802                     resetXML11();
803                 } else {
804                     configurePipeline();
805                     reset();
806                 }
807                 
808                 // mark configuration as fixed
809
fConfigUpdated = false;
810                 
811                 // resets and sets the pipeline.
812
fVersionDetector.startDocumentParsing((XMLEntityHandler) fCurrentScanner, version);
813                 fInputSource = null;
814             } catch (XNIException ex) {
815                 if (PRINT_EXCEPTION_STACK_TRACE)
816                     ex.printStackTrace();
817                 throw ex;
818             } catch (IOException JavaDoc ex) {
819                 if (PRINT_EXCEPTION_STACK_TRACE)
820                     ex.printStackTrace();
821                 throw ex;
822             } catch (RuntimeException JavaDoc ex) {
823                 if (PRINT_EXCEPTION_STACK_TRACE)
824                     ex.printStackTrace();
825                 throw ex;
826             } catch (Exception JavaDoc ex) {
827                 if (PRINT_EXCEPTION_STACK_TRACE)
828                     ex.printStackTrace();
829                 throw new XNIException(ex);
830             }
831         }
832         
833         try {
834             return fCurrentScanner.scanDocument(complete);
835         } catch (XNIException ex) {
836             if (PRINT_EXCEPTION_STACK_TRACE)
837                 ex.printStackTrace();
838             throw ex;
839         } catch (IOException JavaDoc ex) {
840             if (PRINT_EXCEPTION_STACK_TRACE)
841                 ex.printStackTrace();
842             throw ex;
843         } catch (RuntimeException JavaDoc ex) {
844             if (PRINT_EXCEPTION_STACK_TRACE)
845                 ex.printStackTrace();
846             throw ex;
847         } catch (Exception JavaDoc ex) {
848             if (PRINT_EXCEPTION_STACK_TRACE)
849                 ex.printStackTrace();
850             throw new XNIException(ex);
851         }
852         
853     } // parse(boolean):boolean
854

855     /**
856      * Returns the state of a feature.
857      *
858      * @param featureId The feature identifier.
859      * @return true if the feature is supported
860      *
861      * @throws XMLConfigurationException Thrown for configuration error.
862      * In general, components should
863      * only throw this exception if
864      * it is <strong>really</strong>
865      * a critical error.
866      */

867     public boolean getFeature(String JavaDoc featureId)
868     throws XMLConfigurationException {
869         // make this feature special
870
if (featureId.equals(PARSER_SETTINGS)){
871             return fConfigUpdated;
872         }
873         return super.getFeature(featureId);
874         
875     } // getFeature(String):boolean
876

877     /**
878      * Set the state of a feature.
879      *
880      * Set the state of any feature in a SAX2 parser. The parser
881      * might not recognize the feature, and if it does recognize
882      * it, it might not be able to fulfill the request.
883      *
884      * @param featureId The unique identifier (URI) of the feature.
885      * @param state The requested state of the feature (true or false).
886      *
887      * @exception com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException If the
888      * requested feature is not known.
889      */

890     public void setFeature(String JavaDoc featureId, boolean state)
891     throws XMLConfigurationException {
892         fConfigUpdated = true;
893         // forward to every XML 1.0 component
894
int count = fComponents.size();
895         for (int i = 0; i < count; i++) {
896             XMLComponent c = (XMLComponent) fComponents.get(i);
897             c.setFeature(featureId, state);
898         }
899         // forward it to common components
900
count = fCommonComponents.size();
901         for (int i = 0; i < count; i++) {
902             XMLComponent c = (XMLComponent) fCommonComponents.get(i);
903             c.setFeature(featureId, state);
904         }
905         
906         // forward to every XML 1.1 component
907
count = fXML11Components.size();
908         for (int i = 0; i < count; i++) {
909             XMLComponent c = (XMLComponent) fXML11Components.get(i);
910             try{
911                 c.setFeature(featureId, state);
912             }
913             catch (Exception JavaDoc e){
914                 // no op
915
}
916         }
917         // save state if noone "objects"
918
super.setFeature(featureId, state);
919         
920     } // setFeature(String,boolean)
921

922     /**
923      * setProperty
924      *
925      * @param propertyId
926      * @param value
927      */

928     public void setProperty(String JavaDoc propertyId, Object JavaDoc value)
929     throws XMLConfigurationException {
930         fConfigUpdated = true;
931         // forward to every XML 1.0 component
932
int count = fComponents.size();
933         for (int i = 0; i < count; i++) {
934             XMLComponent c = (XMLComponent) fComponents.get(i);
935             c.setProperty(propertyId, value);
936         }
937         // forward it to every common Component
938
count = fCommonComponents.size();
939         for (int i = 0; i < count; i++) {
940             XMLComponent c = (XMLComponent) fCommonComponents.get(i);
941             c.setProperty(propertyId, value);
942         }
943         // forward it to every XML 1.1 component
944
count = fXML11Components.size();
945         for (int i = 0; i < count; i++) {
946             XMLComponent c = (XMLComponent) fXML11Components.get(i);
947             try{
948                 c.setProperty(propertyId, value);
949             }
950             catch (Exception JavaDoc e){
951                 // ignore it
952
}
953         }
954         
955         // store value if noone "objects"
956
super.setProperty(propertyId, value);
957         
958     } // setProperty(String,Object)
959

960     
961     /** Returns the locale. */
962     public Locale JavaDoc getLocale() {
963         return fLocale;
964     } // getLocale():Locale
965

966     /**
967      * reset all XML 1.0 components before parsing and namespace context
968      */

969     protected void reset() throws XNIException {
970         int count = fComponents.size();
971         for (int i = 0; i < count; i++) {
972             XMLComponent c = (XMLComponent) fComponents.get(i);
973             c.reset(this);
974         }
975         
976     } // reset()
977

978     /**
979      * reset all common components before parsing
980      */

981     protected void resetCommon() throws XNIException {
982         // reset common components
983
int count = fCommonComponents.size();
984         for (int i = 0; i < count; i++) {
985             XMLComponent c = (XMLComponent) fCommonComponents.get(i);
986             c.reset(this);
987         }
988         
989     } // resetCommon()
990

991     
992     /**
993      * reset all components before parsing and namespace context
994      */

995     protected void resetXML11() throws XNIException {
996         // reset every component
997
int count = fXML11Components.size();
998         for (int i = 0; i < count; i++) {
999             XMLComponent c = (XMLComponent) fXML11Components.get(i);
1000            c.reset(this);
1001        }
1002        
1003    } // resetXML11()
1004

1005    
1006    /**
1007     * Configures the XML 1.1 pipeline.
1008     * Note: this method also resets the new XML11 components.
1009     */

1010    protected void configureXML11Pipeline() {
1011        if (fCurrentDVFactory != fXML11DatatypeFactory) {
1012            fCurrentDVFactory = fXML11DatatypeFactory;
1013            setProperty(DATATYPE_VALIDATOR_FACTORY, fCurrentDVFactory);
1014        }
1015        if (fCurrentDTDScanner != fXML11DTDScanner) {
1016            fCurrentDTDScanner = fXML11DTDScanner;
1017            setProperty(DTD_SCANNER, fCurrentDTDScanner);
1018            setProperty(DTD_PROCESSOR, fXML11DTDProcessor);
1019        }
1020        
1021        fXML11DTDScanner.setDTDHandler(fXML11DTDProcessor);
1022        fXML11DTDProcessor.setDTDSource(fXML11DTDScanner);
1023        fXML11DTDProcessor.setDTDHandler(fDTDHandler);
1024        if (fDTDHandler != null) {
1025            fDTDHandler.setDTDSource(fXML11DTDProcessor);
1026        }
1027        
1028        fXML11DTDScanner.setDTDContentModelHandler(fXML11DTDProcessor);
1029        fXML11DTDProcessor.setDTDContentModelSource(fXML11DTDScanner);
1030        fXML11DTDProcessor.setDTDContentModelHandler(fDTDContentModelHandler);
1031        if (fDTDContentModelHandler != null) {
1032            fDTDContentModelHandler.setDTDContentModelSource(fXML11DTDProcessor);
1033        }
1034        
1035        // setup XML 1.1 document pipeline
1036
if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
1037            if (fCurrentScanner != fXML11NSDocScanner) {
1038                fCurrentScanner = fXML11NSDocScanner;
1039                setProperty(DOCUMENT_SCANNER, fXML11NSDocScanner);
1040                setProperty(DTD_VALIDATOR, fXML11NSDTDValidator);
1041            }
1042            
1043            fXML11NSDocScanner.setDTDValidator(fXML11NSDTDValidator);
1044            fXML11NSDocScanner.setDocumentHandler(fXML11NSDTDValidator);
1045            fXML11NSDTDValidator.setDocumentSource(fXML11NSDocScanner);
1046            fXML11NSDTDValidator.setDocumentHandler(fDocumentHandler);
1047            
1048            if (fDocumentHandler != null) {
1049                fDocumentHandler.setDocumentSource(fXML11NSDTDValidator);
1050            }
1051            fLastComponent = fXML11NSDTDValidator;
1052            
1053        } else {
1054            // create components
1055
if (fXML11DocScanner == null) {
1056                // non namespace document pipeline
1057
fXML11DocScanner = new XML11DocumentScannerImpl();
1058                addXML11Component(fXML11DocScanner);
1059                fXML11DTDValidator = new XML11DTDValidator();
1060                addXML11Component(fXML11DTDValidator);
1061            }
1062            if (fCurrentScanner != fXML11DocScanner) {
1063                fCurrentScanner = fXML11DocScanner;
1064                setProperty(DOCUMENT_SCANNER, fXML11DocScanner);
1065                setProperty(DTD_VALIDATOR, fXML11DTDValidator);
1066            }
1067            fXML11DocScanner.setDocumentHandler(fXML11DTDValidator);
1068            fXML11DTDValidator.setDocumentSource(fXML11DocScanner);
1069            fXML11DTDValidator.setDocumentHandler(fDocumentHandler);
1070            
1071            if (fDocumentHandler != null) {
1072                fDocumentHandler.setDocumentSource(fXML11DTDValidator);
1073            }
1074            fLastComponent = fXML11DTDValidator;
1075        }
1076        
1077        // setup document pipeline
1078
if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) {
1079            // If schema validator was not in the pipeline insert it.
1080
if (fSchemaValidator == null) {
1081                fSchemaValidator = new XMLSchemaValidator();
1082                // add schema component
1083
setProperty(SCHEMA_VALIDATOR, fSchemaValidator);
1084                addCommonComponent(fSchemaValidator);
1085                fSchemaValidator.reset(this);
1086                // add schema message formatter
1087
if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {
1088                    XSMessageFormatter xmft = new XSMessageFormatter();
1089                    fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft);
1090                }
1091            }
1092            
1093            fLastComponent.setDocumentHandler(fSchemaValidator);
1094            fSchemaValidator.setDocumentSource(fLastComponent);
1095            fSchemaValidator.setDocumentHandler(fDocumentHandler);
1096            if (fDocumentHandler != null) {
1097                fDocumentHandler.setDocumentSource(fSchemaValidator);
1098            }
1099            fLastComponent = fSchemaValidator;
1100        }
1101        
1102    } // configureXML11Pipeline()
1103

1104    /** Configures the pipeline. */
1105    protected void configurePipeline() {
1106        if (fCurrentDVFactory != fDatatypeValidatorFactory) {
1107            fCurrentDVFactory = fDatatypeValidatorFactory;
1108            // use XML 1.0 datatype library
1109
setProperty(DATATYPE_VALIDATOR_FACTORY, fCurrentDVFactory);
1110        }
1111        
1112        // setup DTD pipeline
1113
if (fCurrentDTDScanner != fDTDScanner) {
1114            fCurrentDTDScanner = fDTDScanner;
1115            setProperty(DTD_SCANNER, fCurrentDTDScanner);
1116            setProperty(DTD_PROCESSOR, fDTDProcessor);
1117        }
1118        fDTDScanner.setDTDHandler(fDTDProcessor);
1119        fDTDProcessor.setDTDSource(fDTDScanner);
1120        fDTDProcessor.setDTDHandler(fDTDHandler);
1121        if (fDTDHandler != null) {
1122            fDTDHandler.setDTDSource(fDTDProcessor);
1123        }
1124        
1125        fDTDScanner.setDTDContentModelHandler(fDTDProcessor);
1126        fDTDProcessor.setDTDContentModelSource(fDTDScanner);
1127        fDTDProcessor.setDTDContentModelHandler(fDTDContentModelHandler);
1128        if (fDTDContentModelHandler != null) {
1129            fDTDContentModelHandler.setDTDContentModelSource(fDTDProcessor);
1130        }
1131        
1132        // setup document pipeline
1133
if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
1134            if (fCurrentScanner != fNamespaceScanner) {
1135                fCurrentScanner = fNamespaceScanner;
1136                setProperty(DOCUMENT_SCANNER, fNamespaceScanner);
1137                setProperty(DTD_VALIDATOR, fDTDValidator);
1138            }
1139            fNamespaceScanner.setDTDValidator(fDTDValidator);
1140            fNamespaceScanner.setDocumentHandler(fDTDValidator);
1141            fDTDValidator.setDocumentSource(fNamespaceScanner);
1142            fDTDValidator.setDocumentHandler(fDocumentHandler);
1143            if (fDocumentHandler != null) {
1144                fDocumentHandler.setDocumentSource(fDTDValidator);
1145            }
1146            fLastComponent = fDTDValidator;
1147        } else {
1148            // create components
1149
if (fNonNSScanner == null) {
1150                fNonNSScanner = new XMLDocumentScannerImpl();
1151                fNonNSDTDValidator = new XMLDTDValidator();
1152                // add components
1153
addComponent((XMLComponent) fNonNSScanner);
1154                addComponent((XMLComponent) fNonNSDTDValidator);
1155            }
1156            if (fCurrentScanner != fNonNSScanner) {
1157                fCurrentScanner = fNonNSScanner;
1158                setProperty(DOCUMENT_SCANNER, fNonNSScanner);
1159                setProperty(DTD_VALIDATOR, fNonNSDTDValidator);
1160            }
1161            
1162            fNonNSScanner.setDocumentHandler(fNonNSDTDValidator);
1163            fNonNSDTDValidator.setDocumentSource(fNonNSScanner);
1164            fNonNSDTDValidator.setDocumentHandler(fDocumentHandler);
1165            if (fDocumentHandler != null) {
1166                fDocumentHandler.setDocumentSource(fNonNSDTDValidator);
1167            }
1168            fLastComponent = fNonNSDTDValidator;
1169        }
1170        
1171        // add XML Schema validator if needed
1172
if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) {
1173            // If schema validator was not in the pipeline insert it.
1174
if (fSchemaValidator == null) {
1175                fSchemaValidator = new XMLSchemaValidator();
1176                // add schema component
1177
setProperty(SCHEMA_VALIDATOR, fSchemaValidator);
1178                addCommonComponent(fSchemaValidator);
1179                fSchemaValidator.reset(this);
1180                // add schema message formatter
1181
if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {
1182                    XSMessageFormatter xmft = new XSMessageFormatter();
1183                    fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft);
1184                }
1185                
1186            }
1187            fLastComponent.setDocumentHandler(fSchemaValidator);
1188            fSchemaValidator.setDocumentSource(fLastComponent);
1189            fSchemaValidator.setDocumentHandler(fDocumentHandler);
1190            if (fDocumentHandler != null) {
1191                fDocumentHandler.setDocumentSource(fSchemaValidator);
1192            }
1193            fLastComponent = fSchemaValidator;
1194        }
1195    } // configurePipeline()
1196

1197    
1198    // features and properties
1199

1200    /**
1201     * Check a feature. If feature is know and supported, this method simply
1202     * returns. Otherwise, the appropriate exception is thrown.
1203     *
1204     * @param featureId The unique identifier (URI) of the feature.
1205     *
1206     * @throws XMLConfigurationException Thrown for configuration error.
1207     * In general, components should
1208     * only throw this exception if
1209     * it is <strong>really</strong>
1210     * a critical error.
1211     */

1212    protected void checkFeature(String JavaDoc featureId) throws XMLConfigurationException {
1213        
1214        //
1215
// Xerces Features
1216
//
1217

1218        if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) {
1219            final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length();
1220            
1221            //
1222
// http://apache.org/xml/features/validation/dynamic
1223
// Allows the parser to validate a document only when it
1224
// contains a grammar. Validation is turned on/off based
1225
// on each document instance, automatically.
1226
//
1227
if (suffixLength == Constants.DYNAMIC_VALIDATION_FEATURE.length() &&
1228            featureId.endsWith(Constants.DYNAMIC_VALIDATION_FEATURE)) {
1229                return;
1230            }
1231            
1232            //
1233
// http://apache.org/xml/features/validation/default-attribute-values
1234
//
1235
if (suffixLength == Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE.length() &&
1236            featureId.endsWith(Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE)) {
1237                // REVISIT
1238
short type = XMLConfigurationException.NOT_SUPPORTED;
1239                throw new XMLConfigurationException(type, featureId);
1240            }
1241            //
1242
// http://apache.org/xml/features/validation/default-attribute-values
1243
//
1244
if (suffixLength == Constants.VALIDATE_CONTENT_MODELS_FEATURE.length() &&
1245            featureId.endsWith(Constants.VALIDATE_CONTENT_MODELS_FEATURE)) {
1246                // REVISIT
1247
short type = XMLConfigurationException.NOT_SUPPORTED;
1248                throw new XMLConfigurationException(type, featureId);
1249            }
1250            //
1251
// http://apache.org/xml/features/validation/nonvalidating/load-dtd-grammar
1252
//
1253
if (suffixLength == Constants.LOAD_DTD_GRAMMAR_FEATURE.length() &&
1254            featureId.endsWith(Constants.LOAD_DTD_GRAMMAR_FEATURE)) {
1255                return;
1256            }
1257            //
1258
// http://apache.org/xml/features/validation/nonvalidating/load-external-dtd
1259
//
1260
if (suffixLength == Constants.LOAD_EXTERNAL_DTD_FEATURE.length() &&
1261            featureId.endsWith(Constants.LOAD_EXTERNAL_DTD_FEATURE)) {
1262                return;
1263            }
1264            
1265            //
1266
// http://apache.org/xml/features/validation/default-attribute-values
1267
//
1268
if (suffixLength == Constants.VALIDATE_DATATYPES_FEATURE.length() &&
1269            featureId.endsWith(Constants.VALIDATE_DATATYPES_FEATURE)) {
1270                short type = XMLConfigurationException.NOT_SUPPORTED;
1271                throw new XMLConfigurationException(type, featureId);
1272            }
1273            
1274            //
1275
// http://apache.org/xml/features/validation/schema
1276
// Lets the user turn Schema validation support on/off.
1277
//
1278
if (suffixLength == Constants.SCHEMA_VALIDATION_FEATURE.length() &&
1279            featureId.endsWith(Constants.SCHEMA_VALIDATION_FEATURE)) {
1280                return;
1281            }
1282            // activate full schema checking
1283
if (suffixLength == Constants.SCHEMA_FULL_CHECKING.length() &&
1284            featureId.endsWith(Constants.SCHEMA_FULL_CHECKING)) {
1285                return;
1286            }
1287            // Feature identifier: expose schema normalized value
1288
// http://apache.org/xml/features/validation/schema/normalized-value
1289
if (suffixLength == Constants.SCHEMA_NORMALIZED_VALUE.length() &&
1290            featureId.endsWith(Constants.SCHEMA_NORMALIZED_VALUE)) {
1291                return;
1292            }
1293            // Feature identifier: send element default value via characters()
1294
// http://apache.org/xml/features/validation/schema/element-default
1295
if (suffixLength == Constants.SCHEMA_ELEMENT_DEFAULT.length() &&
1296            featureId.endsWith(Constants.SCHEMA_ELEMENT_DEFAULT)) {
1297                return;
1298            }
1299            
1300            // special performance feature: only component manager is allowed to set it.
1301
if (suffixLength == Constants.PARSER_SETTINGS.length() &&
1302            featureId.endsWith(Constants.PARSER_SETTINGS)) {
1303                short type = XMLConfigurationException.NOT_SUPPORTED;
1304                throw new XMLConfigurationException(type, featureId);
1305            }
1306            
1307        }
1308        
1309        //
1310
// Not recognized
1311
//
1312

1313        super.checkFeature(featureId);
1314        
1315    } // checkFeature(String)
1316

1317    /**
1318     * Check a property. If the property is know and supported, this method
1319     * simply returns. Otherwise, the appropriate exception is thrown.
1320     *
1321     * @param propertyId The unique identifier (URI) of the property
1322     * being set.
1323     *
1324     * @throws XMLConfigurationException Thrown for configuration error.
1325     * In general, components should
1326     * only throw this exception if
1327     * it is <strong>really</strong>
1328     * a critical error.
1329     */

1330    protected void checkProperty(String JavaDoc propertyId) throws XMLConfigurationException {
1331        
1332        //
1333
// Xerces Properties
1334
//
1335

1336        if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
1337            final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length();
1338            
1339            if (suffixLength == Constants.DTD_SCANNER_PROPERTY.length() &&
1340            propertyId.endsWith(Constants.DTD_SCANNER_PROPERTY)) {
1341                return;
1342            }
1343            if (suffixLength == Constants.SCHEMA_LOCATION.length() &&
1344            propertyId.endsWith(Constants.SCHEMA_LOCATION)) {
1345                return;
1346            }
1347            if (suffixLength == Constants.SCHEMA_NONS_LOCATION.length() &&
1348            propertyId.endsWith(Constants.SCHEMA_NONS_LOCATION)) {
1349                return;
1350            }
1351        }
1352        
1353        if (propertyId.startsWith(Constants.JAXP_PROPERTY_PREFIX)) {
1354            final int suffixLength = propertyId.length() - Constants.JAXP_PROPERTY_PREFIX.length();
1355            
1356            if (suffixLength == Constants.SCHEMA_SOURCE.length() &&
1357            propertyId.endsWith(Constants.SCHEMA_SOURCE)) {
1358                return;
1359            }
1360        }
1361        
1362        // special cases
1363
if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) {
1364            final int suffixLength = propertyId.length() - Constants.SAX_PROPERTY_PREFIX.length();
1365            
1366            //
1367
// http://xml.org/sax/properties/xml-string
1368
// Value type: String
1369
// Access: read-only
1370
// Get the literal string of characters associated with the
1371
// current event. If the parser recognises and supports this
1372
// property but is not currently parsing text, it should return
1373
// null (this is a good way to check for availability before the
1374
// parse begins).
1375
//
1376
if (suffixLength == Constants.XML_STRING_PROPERTY.length() &&
1377            propertyId.endsWith(Constants.XML_STRING_PROPERTY)) {
1378                // REVISIT - we should probably ask xml-dev for a precise
1379
// definition of what this is actually supposed to return, and
1380
// in exactly which circumstances.
1381
short type = XMLConfigurationException.NOT_SUPPORTED;
1382                throw new XMLConfigurationException(type, propertyId);
1383            }
1384        }
1385        
1386        //
1387
// Not recognized
1388
//
1389

1390        super.checkProperty(propertyId);
1391        
1392    } // checkProperty(String)
1393

1394    
1395    /**
1396     * Adds a component to the parser configuration. This method will
1397     * also add all of the component's recognized features and properties
1398     * to the list of default recognized features and properties.
1399     *
1400     * @param component The component to add.
1401     */

1402    protected void addComponent(XMLComponent component) {
1403        
1404        // don't add a component more than once
1405
if (fComponents.contains(component)) {
1406            return;
1407        }
1408        fComponents.add(component);
1409        addRecognizedParamsAndSetDefaults(component);
1410        
1411    } // addComponent(XMLComponent)
1412

1413    /**
1414     * Adds common component to the parser configuration. This method will
1415     * also add all of the component's recognized features and properties
1416     * to the list of default recognized features and properties.
1417     *
1418     * @param component The component to add.
1419     */

1420    protected void addCommonComponent(XMLComponent component) {
1421        
1422        // don't add a component more than once
1423
if (fCommonComponents.contains(component)) {
1424            return;
1425        }
1426        fCommonComponents.add(component);
1427        addRecognizedParamsAndSetDefaults(component);
1428        
1429    } // addCommonComponent(XMLComponent)
1430

1431    /**
1432     * Adds an XML 1.1 component to the parser configuration. This method will
1433     * also add all of the component's recognized features and properties
1434     * to the list of default recognized features and properties.
1435     *
1436     * @param component The component to add.
1437     */

1438    protected void addXML11Component(XMLComponent component) {
1439        
1440        // don't add a component more than once
1441
if (fXML11Components.contains(component)) {
1442            return;
1443        }
1444        fXML11Components.add(component);
1445        addRecognizedParamsAndSetDefaults(component);
1446        
1447    } // addXML11Component(XMLComponent)
1448

1449    /**
1450     * Adds all of the component's recognized features and properties
1451     * to the list of default recognized features and properties, and
1452     * sets default values on the configuration for features and
1453     * properties which were previously absent from the configuration.
1454     *
1455     * @param component The component whose recognized features
1456     * and properties will be added to the configuration
1457     */

1458    protected void addRecognizedParamsAndSetDefaults(XMLComponent component) {
1459        
1460        // register component's recognized features
1461
String JavaDoc[] recognizedFeatures = component.getRecognizedFeatures();
1462        addRecognizedFeatures(recognizedFeatures);
1463        
1464        // register component's recognized properties
1465
String JavaDoc[] recognizedProperties = component.getRecognizedProperties();
1466        addRecognizedProperties(recognizedProperties);
1467        
1468        // set default values
1469
if (recognizedFeatures != null) {
1470            for (int i = 0; i < recognizedFeatures.length; ++i) {
1471                String JavaDoc featureId = recognizedFeatures[i];
1472                Boolean JavaDoc state = component.getFeatureDefault(featureId);
1473                if (state != null) {
1474                    // Do not overwrite values already set on the configuration.
1475
if (!fFeatures.containsKey(featureId)) {
1476                        fFeatures.put(featureId, state);
1477                        // For newly added components who recognize this feature
1478
// but did not offer a default value, we need to make
1479
// sure these components will get an opportunity to read
1480
// the value before parsing begins.
1481
fConfigUpdated = true;
1482                    }
1483                }
1484            }
1485        }
1486        if (recognizedProperties != null) {
1487            for (int i = 0; i < recognizedProperties.length; ++i) {
1488                String JavaDoc propertyId = recognizedProperties[i];
1489                Object JavaDoc value = component.getPropertyDefault(propertyId);
1490                if (value != null) {
1491                    // Do not overwrite values already set on the configuration.
1492
if (!fProperties.containsKey(propertyId)) {
1493                        fProperties.put(propertyId, value);
1494                        // For newly added components who recognize this property
1495
// but did not offer a default value, we need to make
1496
// sure these components will get an opportunity to read
1497
// the value before parsing begins.
1498
fConfigUpdated = true;
1499                    }
1500                }
1501            }
1502        }
1503    }
1504    
1505    private void initXML11Components() {
1506        if (!f11Initialized) {
1507            
1508            // create datatype factory
1509
fXML11DatatypeFactory = DTDDVFactory.getInstance(XML11_DATATYPE_VALIDATOR_FACTORY);
1510            
1511            // setup XML 1.1 DTD pipeline
1512
fXML11DTDScanner = new XML11DTDScannerImpl();
1513            addXML11Component(fXML11DTDScanner);
1514            fXML11DTDProcessor = new XML11DTDProcessor();
1515            addXML11Component(fXML11DTDProcessor);
1516            
1517            // setup XML 1.1. document pipeline - namespace aware
1518
fXML11NSDocScanner = new XML11NSDocumentScannerImpl();
1519            addXML11Component(fXML11NSDocScanner);
1520            fXML11NSDTDValidator = new XML11NSDTDValidator();
1521            addXML11Component(fXML11NSDTDValidator);
1522            
1523            f11Initialized = true;
1524        }
1525    }
1526    
1527} // class XML11Configuration
1528
Popular Tags