KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2001-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.Locale JavaDoc;
21
22 import org.apache.xerces.impl.Constants;
23 import org.apache.xerces.impl.XMLDTDScannerImpl;
24 import org.apache.xerces.impl.XMLDocumentScannerImpl;
25 import org.apache.xerces.impl.XMLEntityManager;
26 import org.apache.xerces.impl.XMLErrorReporter;
27 import org.apache.xerces.impl.XMLNSDocumentScannerImpl;
28 import org.apache.xerces.impl.dv.DTDDVFactory;
29 import org.apache.xerces.impl.msg.XMLMessageFormatter;
30 import org.apache.xerces.impl.validation.ValidationManager;
31 import org.apache.xerces.util.SymbolTable;
32 import org.apache.xerces.xni.XMLLocator;
33 import org.apache.xerces.xni.XNIException;
34 import org.apache.xerces.xni.grammars.XMLGrammarPool;
35 import org.apache.xerces.xni.parser.XMLComponent;
36 import org.apache.xerces.xni.parser.XMLComponentManager;
37 import org.apache.xerces.xni.parser.XMLConfigurationException;
38 import org.apache.xerces.xni.parser.XMLDTDScanner;
39 import org.apache.xerces.xni.parser.XMLDocumentScanner;
40 import org.apache.xerces.xni.parser.XMLInputSource;
41 import org.apache.xerces.xni.parser.XMLPullParserConfiguration;
42
43 /**
44  * This is the non validating parser configuration. It extends the basic
45  * configuration with the set of following parser components:
46  * Document scanner, DTD scanner, namespace binder, document handler.
47  * <p>
48  * Xerces parser that uses this configuration is <strong>not</strong> <a HREF="http://www.w3.org/TR/REC-xml#sec-conformance">conformant</a>
49  * non-validating XML processor, since conformant non-validating processor is required
50  * to process "all the declarations they read in the internal DTD subset ... must use the information in those declarations to normalize attribute values,
51  * include the replacement text of internal entities, and supply default attribute values".
52  *
53  * @author Elena Litani, IBM
54  * @version $Id: NonValidatingConfiguration.java,v 1.13 2004/02/24 23:15:57 mrglavas Exp $
55  */

56 public class NonValidatingConfiguration
57     extends BasicParserConfiguration
58     implements XMLPullParserConfiguration {
59
60     //
61
// Constants
62
//
63

64     // feature identifiers
65

66     /** Feature identifier: warn on duplicate attribute definition. */
67     protected static final String JavaDoc WARN_ON_DUPLICATE_ATTDEF =
68         Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE;
69
70     /** Feature identifier: warn on duplicate entity definition. */
71     protected static final String JavaDoc WARN_ON_DUPLICATE_ENTITYDEF =
72         Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ENTITYDEF_FEATURE;
73     
74     /** Feature identifier: warn on undeclared element definition. */
75     protected static final String JavaDoc WARN_ON_UNDECLARED_ELEMDEF =
76         Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_UNDECLARED_ELEMDEF_FEATURE;
77     
78     /** Feature identifier: allow Java encodings. */
79     protected static final String JavaDoc ALLOW_JAVA_ENCODINGS =
80         Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE;
81     
82     /** Feature identifier: continue after fatal error. */
83     protected static final String JavaDoc CONTINUE_AFTER_FATAL_ERROR =
84         Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE;
85
86     /** Feature identifier: load external DTD. */
87     protected static final String JavaDoc LOAD_EXTERNAL_DTD =
88         Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE;
89
90     /** Feature identifier: notify built-in refereces. */
91     protected static final String JavaDoc NOTIFY_BUILTIN_REFS =
92         Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_BUILTIN_REFS_FEATURE;
93     
94     /** Feature identifier: notify character refereces. */
95     protected static final String JavaDoc NOTIFY_CHAR_REFS =
96         Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_CHAR_REFS_FEATURE;
97     
98
99     /** Feature identifier: expose schema normalized value */
100     protected static final String JavaDoc NORMALIZE_DATA =
101     Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE;
102
103
104     /** Feature identifier: send element default value via characters() */
105     protected static final String JavaDoc SCHEMA_ELEMENT_DEFAULT =
106     Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_ELEMENT_DEFAULT;
107
108     // property identifiers
109

110     /** Property identifier: error reporter. */
111     protected static final String JavaDoc ERROR_REPORTER =
112         Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
113
114     /** Property identifier: entity manager. */
115     protected static final String JavaDoc ENTITY_MANAGER =
116         Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;
117     
118     /** Property identifier document scanner: */
119     protected static final String JavaDoc DOCUMENT_SCANNER =
120         Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_SCANNER_PROPERTY;
121
122     /** Property identifier: DTD scanner. */
123     protected static final String JavaDoc DTD_SCANNER =
124         Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY;
125
126     /** Property identifier: grammar pool. */
127     protected static final String JavaDoc XMLGRAMMAR_POOL =
128         Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY;
129     
130     /** Property identifier: DTD validator. */
131     protected static final String JavaDoc DTD_VALIDATOR =
132         Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_VALIDATOR_PROPERTY;
133
134     /** Property identifier: namespace binder. */
135     protected static final String JavaDoc NAMESPACE_BINDER =
136         Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_BINDER_PROPERTY;
137
138     /** Property identifier: datatype validator factory. */
139     protected static final String JavaDoc DATATYPE_VALIDATOR_FACTORY =
140         Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY;
141
142     protected static final String JavaDoc VALIDATION_MANAGER =
143         Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
144
145     /** Property identifier: XML Schema validator. */
146     protected static final String JavaDoc SCHEMA_VALIDATOR =
147         Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_VALIDATOR_PROPERTY;
148
149
150     // debugging
151

152     /** Set to true and recompile to print exception stack trace. */
153     private static final boolean PRINT_EXCEPTION_STACK_TRACE = false;
154
155     //
156
// Data
157
//
158

159     // components (non-configurable)
160

161     /** Grammar pool. */
162     protected XMLGrammarPool fGrammarPool;
163
164     /** Datatype validator factory. */
165     protected DTDDVFactory fDatatypeValidatorFactory;
166
167     // components (configurable)
168

169     /** Error reporter. */
170     protected XMLErrorReporter fErrorReporter;
171
172     /** Entity manager. */
173     protected XMLEntityManager fEntityManager;
174
175     /** Document scanner. */
176     protected XMLDocumentScanner fScanner;
177
178     /** Input Source */
179     protected XMLInputSource fInputSource;
180
181     /** DTD scanner. */
182     protected XMLDTDScanner fDTDScanner;
183
184
185     protected ValidationManager fValidationManager;
186
187     // private data
188

189     /** Document scanner that does namespace binding. */
190     private XMLNSDocumentScannerImpl fNamespaceScanner;
191
192     /** Default Xerces implementation of scanner*/
193     private XMLDocumentScannerImpl fNonNSScanner;
194     
195     
196     /** fConfigUpdated is set to true if there has been any change to the configuration settings,
197      * i.e a feature or a property was changed.
198      */

199     protected boolean fConfigUpdated = false;
200
201
202     // state
203

204     /** Locator */
205     protected XMLLocator fLocator;
206
207     /**
208      * True if a parse is in progress. This state is needed because
209      * some features/properties cannot be set while parsing (e.g.
210      * validation and namespaces).
211      */

212     protected boolean fParseInProgress = false;
213
214     //
215
// Constructors
216
//
217

218     /** Default constructor. */
219     public NonValidatingConfiguration() {
220         this(null, null, null);
221     } // <init>()
222

223     /**
224      * Constructs a parser configuration using the specified symbol table.
225      *
226      * @param symbolTable The symbol table to use.
227      */

228     public NonValidatingConfiguration(SymbolTable symbolTable) {
229         this(symbolTable, null, null);
230     } // <init>(SymbolTable)
231

232     /**
233      * Constructs a parser configuration using the specified symbol table and
234      * grammar pool.
235      * <p>
236      * <strong>REVISIT:</strong>
237      * Grammar pool will be updated when the new validation engine is
238      * implemented.
239      *
240      * @param symbolTable The symbol table to use.
241      * @param grammarPool The grammar pool to use.
242      */

243     public NonValidatingConfiguration(SymbolTable symbolTable,
244                                        XMLGrammarPool grammarPool) {
245         this(symbolTable, grammarPool, null);
246     } // <init>(SymbolTable,XMLGrammarPool)
247

248     /**
249      * Constructs a parser configuration using the specified symbol table,
250      * grammar pool, and parent settings.
251      * <p>
252      * <strong>REVISIT:</strong>
253      * Grammar pool will be updated when the new validation engine is
254      * implemented.
255      *
256      * @param symbolTable The symbol table to use.
257      * @param grammarPool The grammar pool to use.
258      * @param parentSettings The parent settings.
259      */

260     public NonValidatingConfiguration(SymbolTable symbolTable,
261                                        XMLGrammarPool grammarPool,
262                                        XMLComponentManager parentSettings) {
263         super(symbolTable, parentSettings);
264
265         // add default recognized features
266
final String JavaDoc[] recognizedFeatures = {
267             PARSER_SETTINGS,
268             NAMESPACES,
269             //WARN_ON_DUPLICATE_ATTDEF, // from XMLDTDScannerImpl
270
//WARN_ON_UNDECLARED_ELEMDEF, // from XMLDTDScannerImpl
271
//ALLOW_JAVA_ENCODINGS, // from XMLEntityManager
272
CONTINUE_AFTER_FATAL_ERROR,
273             //LOAD_EXTERNAL_DTD, // from XMLDTDScannerImpl
274
//NOTIFY_BUILTIN_REFS, // from XMLDocumentFragmentScannerImpl
275
//NOTIFY_CHAR_REFS, // from XMLDocumentFragmentScannerImpl
276
//WARN_ON_DUPLICATE_ENTITYDEF // from XMLEntityManager
277
};
278         addRecognizedFeatures(recognizedFeatures);
279
280         // set state for default features
281
//setFeature(WARN_ON_DUPLICATE_ATTDEF, false); // from XMLDTDScannerImpl
282
//setFeature(WARN_ON_UNDECLARED_ELEMDEF, false); // from XMLDTDScannerImpl
283
//setFeature(ALLOW_JAVA_ENCODINGS, false); // from XMLEntityManager
284
fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE);
285         fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);
286         fFeatures.put(NAMESPACES, Boolean.TRUE);
287         //setFeature(LOAD_EXTERNAL_DTD, true); // from XMLDTDScannerImpl
288
//setFeature(NOTIFY_BUILTIN_REFS, false); // from XMLDocumentFragmentScannerImpl
289
//setFeature(NOTIFY_CHAR_REFS, false); // from XMLDocumentFragmentScannerImpl
290
//setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false); // from XMLEntityManager
291

292         // add default recognized properties
293
final String JavaDoc[] recognizedProperties = {
294             ERROR_REPORTER,
295             ENTITY_MANAGER,
296             DOCUMENT_SCANNER,
297             DTD_SCANNER,
298             DTD_VALIDATOR,
299             NAMESPACE_BINDER,
300             XMLGRAMMAR_POOL,
301             DATATYPE_VALIDATOR_FACTORY,
302             VALIDATION_MANAGER
303         };
304         addRecognizedProperties(recognizedProperties);
305     
306         fGrammarPool = grammarPool;
307         if(fGrammarPool != null){
308             fProperties.put(XMLGRAMMAR_POOL, fGrammarPool);
309         }
310
311         fEntityManager = createEntityManager();
312         fProperties.put(ENTITY_MANAGER, fEntityManager);
313         addComponent(fEntityManager);
314
315         fErrorReporter = createErrorReporter();
316         fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());
317         fProperties.put(ERROR_REPORTER, fErrorReporter);
318         addComponent(fErrorReporter);
319
320         // this configuration delays creation of the scanner
321
// till it is known if namespace processing should be performed
322

323         fDTDScanner = createDTDScanner();
324         if (fDTDScanner != null) {
325             fProperties.put(DTD_SCANNER, fDTDScanner);
326             if (fDTDScanner instanceof XMLComponent) {
327                 addComponent((XMLComponent)fDTDScanner);
328             }
329         }
330
331         fDatatypeValidatorFactory = createDatatypeValidatorFactory();
332         if (fDatatypeValidatorFactory != null) {
333             fProperties.put(DATATYPE_VALIDATOR_FACTORY,
334                         fDatatypeValidatorFactory);
335         }
336         fValidationManager = createValidationManager();
337
338         if (fValidationManager != null) {
339             fProperties.put(VALIDATION_MANAGER, fValidationManager);
340         }
341         // add message formatters
342
if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
343             XMLMessageFormatter xmft = new XMLMessageFormatter();
344             fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
345             fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
346         }
347         
348         fConfigUpdated = false;
349
350         // set locale
351
try {
352             setLocale(Locale.getDefault());
353         }
354         catch (XNIException e) {
355             // do nothing
356
// REVISIT: What is the right thing to do? -Ac
357
}
358
359     } // <init>(SymbolTable,XMLGrammarPool)
360

361     //
362
// Public methods
363
//
364
public void setFeature(String JavaDoc featureId, boolean state)
365         throws XMLConfigurationException {
366         fConfigUpdated = true;
367         super.setFeature(featureId, state);
368     }
369     
370     public void setProperty(String JavaDoc propertyId, Object JavaDoc value)
371         throws XMLConfigurationException {
372         fConfigUpdated = true;
373         super.setProperty(propertyId, value);
374         }
375     /**
376      * Set the locale to use for messages.
377      *
378      * @param locale The locale object to use for localization of messages.
379      *
380      * @exception XNIException Thrown if the parser does not support the
381      * specified locale.
382      */

383     public void setLocale(Locale JavaDoc locale) throws XNIException {
384         super.setLocale(locale);
385         fErrorReporter.setLocale(locale);
386     } // setLocale(Locale)
387

388     public boolean getFeature(String JavaDoc featureId)
389         throws XMLConfigurationException {
390             // make this feature special
391
if (featureId.equals(PARSER_SETTINGS)){
392             return fConfigUpdated;
393         }
394         return super.getFeature(featureId);
395
396     } // getFeature(String):boolean
397
//
398
// XMLPullParserConfiguration methods
399
//
400

401     // parsing
402

403     /**
404      * Sets the input source for the document to parse.
405      *
406      * @param inputSource The document's input source.
407      *
408      * @exception XMLConfigurationException Thrown if there is a
409      * configuration error when initializing the
410      * parser.
411      * @exception IOException Thrown on I/O error.
412      *
413      * @see #parse(boolean)
414      */

415     public void setInputSource(XMLInputSource inputSource)
416         throws XMLConfigurationException, IOException JavaDoc {
417         
418         // REVISIT: this method used to reset all the components and
419
// construct the pipeline. Now reset() is called
420
// in parse (boolean) just before we parse the document
421
// Should this method still throw exceptions..?
422

423         fInputSource = inputSource;
424         
425     } // setInputSource(XMLInputSource)
426

427     /**
428      * Parses the document in a pull parsing fashion.
429      *
430      * @param complete True if the pull parser should parse the
431      * remaining document completely.
432      *
433      * @return True if there is more document to parse.
434      *
435      * @exception XNIException Any XNI exception, possibly wrapping
436      * another exception.
437      * @exception IOException An IO exception from the parser, possibly
438      * from a byte stream or character stream
439      * supplied by the parser.
440      *
441      * @see #setInputSource
442      */

443     public boolean parse(boolean complete) throws XNIException, IOException JavaDoc {
444         //
445
// reset and configure pipeline and set InputSource.
446
if (fInputSource !=null) {
447             try {
448                 // resets and sets the pipeline.
449
reset();
450                 fScanner.setInputSource(fInputSource);
451                 fInputSource = null;
452             }
453             catch (XNIException ex) {
454                 if (PRINT_EXCEPTION_STACK_TRACE)
455                     ex.printStackTrace();
456                 throw ex;
457             }
458             catch (IOException JavaDoc ex) {
459                 if (PRINT_EXCEPTION_STACK_TRACE)
460                     ex.printStackTrace();
461                 throw ex;
462             }
463             catch (RuntimeException JavaDoc ex) {
464                 if (PRINT_EXCEPTION_STACK_TRACE)
465                     ex.printStackTrace();
466                 throw ex;
467             }
468             catch (Exception JavaDoc ex) {
469                 if (PRINT_EXCEPTION_STACK_TRACE)
470                     ex.printStackTrace();
471                 throw new XNIException(ex);
472             }
473         }
474
475         try {
476             return fScanner.scanDocument(complete);
477         }
478         catch (XNIException ex) {
479             if (PRINT_EXCEPTION_STACK_TRACE)
480                 ex.printStackTrace();
481             throw ex;
482         }
483         catch (IOException JavaDoc ex) {
484             if (PRINT_EXCEPTION_STACK_TRACE)
485                 ex.printStackTrace();
486             throw ex;
487         }
488         catch (RuntimeException JavaDoc ex) {
489             if (PRINT_EXCEPTION_STACK_TRACE)
490                 ex.printStackTrace();
491             throw ex;
492         }
493         catch (Exception JavaDoc ex) {
494             if (PRINT_EXCEPTION_STACK_TRACE)
495                 ex.printStackTrace();
496             throw new XNIException(ex);
497         }
498
499     } // parse(boolean):boolean
500

501     /**
502      * If the application decides to terminate parsing before the xml document
503      * is fully parsed, the application should call this method to free any
504      * resource allocated during parsing. For example, close all opened streams.
505      */

506     public void cleanup() {
507         fEntityManager.closeReaders();
508     }
509     
510     //
511
// XMLParserConfiguration methods
512
//
513

514     /**
515      * Parses the specified input source.
516      *
517      * @param source The input source.
518      *
519      * @exception XNIException Throws exception on XNI error.
520      * @exception java.io.IOException Throws exception on i/o error.
521      */

522     public void parse(XMLInputSource source) throws XNIException, IOException JavaDoc {
523
524         if (fParseInProgress) {
525             // REVISIT - need to add new error message
526
throw new XNIException("FWK005 parse may not be called while parsing.");
527         }
528         fParseInProgress = true;
529
530         try {
531             setInputSource(source);
532             parse(true);
533         }
534         catch (XNIException ex) {
535             if (PRINT_EXCEPTION_STACK_TRACE)
536                 ex.printStackTrace();
537             throw ex;
538         }
539         catch (IOException JavaDoc ex) {
540             if (PRINT_EXCEPTION_STACK_TRACE)
541                 ex.printStackTrace();
542             throw ex;
543         }
544         catch (RuntimeException JavaDoc ex) {
545             if (PRINT_EXCEPTION_STACK_TRACE)
546                 ex.printStackTrace();
547             throw ex;
548         }
549         catch (Exception JavaDoc ex) {
550             if (PRINT_EXCEPTION_STACK_TRACE)
551                 ex.printStackTrace();
552             throw new XNIException(ex);
553         }
554         finally {
555             fParseInProgress = false;
556             // close all streams opened by xerces
557
this.cleanup();
558         }
559
560     } // parse(InputSource)
561

562     //
563
// Protected methods
564
//
565

566     /**
567      * Reset all components before parsing.
568      *
569      * @throws XNIException Thrown if an error occurs during initialization.
570      */

571     protected void reset() throws XNIException {
572
573         if (fValidationManager != null)
574             fValidationManager.reset();
575         // configure the pipeline and initialize the components
576
configurePipeline();
577         super.reset();
578
579     } // reset()
580

581     /** Configures the pipeline. */
582     protected void configurePipeline() {
583         // create appropriate scanner
584
// and register it as one of the components.
585
if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
586             if (fNamespaceScanner == null) {
587                 fNamespaceScanner = new XMLNSDocumentScannerImpl();
588                 addComponent((XMLComponent)fNamespaceScanner);
589             }
590             fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner);
591             fNamespaceScanner.setDTDValidator(null);
592             fScanner = fNamespaceScanner;
593         }
594         else {
595             if (fNonNSScanner == null) {
596                 fNonNSScanner = new XMLDocumentScannerImpl();
597                 addComponent((XMLComponent)fNonNSScanner);
598             }
599             fProperties.put(DOCUMENT_SCANNER, fNonNSScanner);
600             fScanner = fNonNSScanner;
601         }
602
603         fScanner.setDocumentHandler(fDocumentHandler);
604         fLastComponent = fScanner;
605         // setup dtd pipeline
606
if (fDTDScanner != null) {
607                 fDTDScanner.setDTDHandler(fDTDHandler);
608                 fDTDScanner.setDTDContentModelHandler(fDTDContentModelHandler);
609         }
610
611
612     } // configurePipeline()
613

614     // features and properties
615

616     /**
617      * Check a feature. If feature is know and supported, this method simply
618      * returns. Otherwise, the appropriate exception is thrown.
619      *
620      * @param featureId The unique identifier (URI) of the feature.
621      *
622      * @throws XMLConfigurationException Thrown for configuration error.
623      * In general, components should
624      * only throw this exception if
625      * it is <strong>really</strong>
626      * a critical error.
627      */

628     protected void checkFeature(String JavaDoc featureId)
629         throws XMLConfigurationException {
630
631         //
632
// Xerces Features
633
//
634

635         if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) {
636             final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length();
637             
638             //
639
// http://apache.org/xml/features/validation/dynamic
640
// Allows the parser to validate a document only when it
641
// contains a grammar. Validation is turned on/off based
642
// on each document instance, automatically.
643
//
644
if (suffixLength == Constants.DYNAMIC_VALIDATION_FEATURE.length() &&
645                 featureId.endsWith(Constants.DYNAMIC_VALIDATION_FEATURE)) {
646                 return;
647             }
648             //
649
// http://apache.org/xml/features/validation/default-attribute-values
650
//
651
if (suffixLength == Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE.length() &&
652                 featureId.endsWith(Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE)) {
653                 // REVISIT
654
short type = XMLConfigurationException.NOT_SUPPORTED;
655                 throw new XMLConfigurationException(type, featureId);
656             }
657             //
658
// http://apache.org/xml/features/validation/default-attribute-values
659
//
660
if (suffixLength == Constants.VALIDATE_CONTENT_MODELS_FEATURE.length() &&
661                 featureId.endsWith(Constants.VALIDATE_CONTENT_MODELS_FEATURE)) {
662                 // REVISIT
663
short type = XMLConfigurationException.NOT_SUPPORTED;
664                 throw new XMLConfigurationException(type, featureId);
665             }
666             //
667
// http://apache.org/xml/features/validation/nonvalidating/load-dtd-grammar
668
//
669
if (suffixLength == Constants.LOAD_DTD_GRAMMAR_FEATURE.length() &&
670                 featureId.endsWith(Constants.LOAD_DTD_GRAMMAR_FEATURE)) {
671                 return;
672             }
673             //
674
// http://apache.org/xml/features/validation/nonvalidating/load-external-dtd
675
//
676
if (suffixLength == Constants.LOAD_EXTERNAL_DTD_FEATURE.length() &&
677                 featureId.endsWith(Constants.LOAD_EXTERNAL_DTD_FEATURE)) {
678                 return;
679             }
680
681             //
682
// http://apache.org/xml/features/validation/default-attribute-values
683
//
684
if (suffixLength == Constants.VALIDATE_DATATYPES_FEATURE.length() &&
685                 featureId.endsWith(Constants.VALIDATE_DATATYPES_FEATURE)) {
686                 short type = XMLConfigurationException.NOT_SUPPORTED;
687                 throw new XMLConfigurationException(type, featureId);
688             }
689         }
690
691         //
692
// Not recognized
693
//
694

695         super.checkFeature(featureId);
696
697     } // checkFeature(String)
698

699     /**
700      * Check a property. If the property is know and supported, this method
701      * simply returns. Otherwise, the appropriate exception is thrown.
702      *
703      * @param propertyId The unique identifier (URI) of the property
704      * being set.
705      *
706      * @throws XMLConfigurationException Thrown for configuration error.
707      * In general, components should
708      * only throw this exception if
709      * it is <strong>really</strong>
710      * a critical error.
711      */

712     protected void checkProperty(String JavaDoc propertyId)
713         throws XMLConfigurationException {
714
715         //
716
// Xerces Properties
717
//
718

719         if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
720             final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length();
721             
722             if (suffixLength == Constants.DTD_SCANNER_PROPERTY.length() &&
723                 propertyId.endsWith(Constants.DTD_SCANNER_PROPERTY)) {
724                 return;
725             }
726         }
727
728         if (propertyId.startsWith(Constants.JAXP_PROPERTY_PREFIX)) {
729             final int suffixLength = propertyId.length() - Constants.JAXP_PROPERTY_PREFIX.length();
730
731             if (suffixLength == Constants.SCHEMA_SOURCE.length() &&
732                 propertyId.endsWith(Constants.SCHEMA_SOURCE)) {
733                 return;
734             }
735         }
736
737         //
738
// Not recognized
739
//
740

741         super.checkProperty(propertyId);
742
743     } // checkProperty(String)
744

745     // factory methods
746

747     /** Creates an entity manager. */
748     protected XMLEntityManager createEntityManager() {
749         return new XMLEntityManager();
750     } // createEntityManager():XMLEntityManager
751

752     /** Creates an error reporter. */
753     protected XMLErrorReporter createErrorReporter() {
754         return new XMLErrorReporter();
755     } // createErrorReporter():XMLErrorReporter
756

757     /** Create a document scanner. */
758     protected XMLDocumentScanner createDocumentScanner() {
759         return null;
760     } // createDocumentScanner():XMLDocumentScanner
761

762     /** Create a DTD scanner. */
763     protected XMLDTDScanner createDTDScanner() {
764         return new XMLDTDScannerImpl();
765     } // createDTDScanner():XMLDTDScanner
766

767     /** Create a datatype validator factory. */
768     protected DTDDVFactory createDatatypeValidatorFactory() {
769         return DTDDVFactory.getInstance();
770     } // createDatatypeValidatorFactory():DatatypeValidatorFactory
771
protected ValidationManager createValidationManager(){
772         return new ValidationManager();
773     }
774
775 } // class NonValidatingConfiguration
776
Popular Tags