KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > apache > xerces > framework > XMLParser


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
6  * 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) 1999, 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 package org.enhydra.apache.xerces.framework;
59
60 import java.io.IOException JavaDoc;
61 import java.io.InputStream JavaDoc;
62 import java.io.Reader JavaDoc;
63 import java.util.Locale JavaDoc;
64
65 import org.enhydra.apache.xerces.readers.DefaultEntityHandler;
66 import org.enhydra.apache.xerces.readers.XMLDeclRecognizer;
67 import org.enhydra.apache.xerces.readers.XMLEntityReaderFactory;
68 import org.enhydra.apache.xerces.utils.ChunkyCharArray;
69 import org.enhydra.apache.xerces.utils.ImplementationMessages;
70 import org.enhydra.apache.xerces.utils.StringPool;
71 import org.enhydra.apache.xerces.utils.XMLMessageProvider;
72 import org.enhydra.apache.xerces.utils.XMLMessages;
73 import org.enhydra.apache.xerces.validators.common.GrammarResolver;
74 import org.enhydra.apache.xerces.validators.common.GrammarResolverImpl;
75 import org.enhydra.apache.xerces.validators.common.XMLValidator;
76 import org.enhydra.apache.xerces.validators.datatype.DatatypeMessageProvider;
77 import org.enhydra.apache.xerces.validators.schema.SchemaMessageProvider;
78 import org.xml.sax.EntityResolver JavaDoc;
79 import org.xml.sax.ErrorHandler JavaDoc;
80 import org.xml.sax.InputSource JavaDoc;
81 import org.xml.sax.Locator JavaDoc;
82 import org.xml.sax.SAXException JavaDoc;
83 import org.xml.sax.SAXNotRecognizedException JavaDoc;
84 import org.xml.sax.SAXNotSupportedException JavaDoc;
85 import org.xml.sax.SAXParseException JavaDoc;
86
87 /**
88  * This is the base class of all standard parsers.
89  *
90  * @version $Id: XMLParser.java,v 1.2 2005/01/26 08:28:44 jkjome Exp $
91  */

92 public abstract class XMLParser
93     implements XMLErrorReporter, XMLDocumentHandler.DTDHandler {
94
95     //
96
// Constants
97
//
98

99     // protected
100

101     /** SAX2 features prefix (http://xml.org/sax/features/). */
102     protected static final String JavaDoc SAX2_FEATURES_PREFIX = "http://xml.org/sax/features/";
103
104     /** SAX2 properties prefix (http://xml.org/sax/properties/). */
105     protected static final String JavaDoc SAX2_PROPERTIES_PREFIX = "http://xml.org/sax/properties/";
106
107     /** Xerces features prefix (http://apache.org/xml/features/). */
108     protected static final String JavaDoc XERCES_FEATURES_PREFIX = "http://apache.org/xml/features/";
109
110     /** Xerces properties prefix (http://apache.org/xml/properties/). */
111     protected static final String JavaDoc XERCES_PROPERTIES_PREFIX = "http://apache.org/xml/properties/";
112
113     // private
114

115     /** Features recognized by this parser. */
116     private static final String JavaDoc RECOGNIZED_FEATURES[] = {
117         // SAX2 core
118
"http://xml.org/sax/features/validation",
119         "http://xml.org/sax/features/external-general-entities",
120         "http://xml.org/sax/features/external-parameter-entities",
121         "http://xml.org/sax/features/namespaces",
122         // Xerces
123
"http://apache.org/xml/features/validation/schema",
124         // "http://apache.org/xml/features/schema/expose-normalized-values",
125
"http://apache.org/xml/features/validation/schema-full-checking",
126         "http://apache.org/xml/features/validation/dynamic",
127         "http://apache.org/xml/features/validation/default-attribute-values",
128         
129         "http://apache.org/xml/features/validation/validate-content-models",
130         "http://apache.org/xml/features/validation/validate-datatypes",
131         "http://apache.org/xml/features/validation/warn-on-duplicate-attdef",
132         "http://apache.org/xml/features/validation/warn-on-undeclared-elemdef",
133         "http://apache.org/xml/features/allow-java-encodings",
134         "http://apache.org/xml/features/continue-after-fatal-error",
135         "http://apache.org/xml/features/nonvalidating/load-dtd-grammar",
136         "http://apache.org/xml/features/nonvalidating/load-external-dtd"
137     };
138
139     /** Properties recognized by this parser. */
140     private static final String JavaDoc RECOGNIZED_PROPERTIES[] = {
141         // SAX2 core
142
"http://xml.org/sax/properties/xml-string",
143         // Xerces
144
"http://apache.org/xml/properties/schema/external-schemaLocation",
145         "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation"
146     };
147
148     // debugging
149

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

157     protected GrammarResolver fGrammarResolver = null;
158
159     // state
160

161     protected boolean fParseInProgress = false;
162     private boolean fNeedReset = false;
163
164     // features
165

166     /** Continue after fatal error. */
167     private boolean fContinueAfterFatalError = false;
168
169     // properties
170

171     /** Error handler. */
172     private ErrorHandler JavaDoc fErrorHandler = null;
173
174     // other
175

176     private Locale JavaDoc fLocale = null;
177
178     // error information
179

180     private static XMLMessageProvider fgXMLMessages = new XMLMessages();
181     private static XMLMessageProvider fgImplementationMessages = new ImplementationMessages();
182     private static XMLMessageProvider fgSchemaMessages = new SchemaMessageProvider();
183     private static XMLMessageProvider fgDatatypeMessages= new DatatypeMessageProvider();
184
185     //
186
//
187
//
188
protected StringPool fStringPool = null;
189     protected XMLErrorReporter fErrorReporter = null;
190     protected DefaultEntityHandler fEntityHandler = null;
191     protected XMLDocumentScanner fScanner = null;
192     protected XMLValidator fValidator = null;
193
194     //
195
// Constructors
196
//
197

198     /**
199      * Constructor
200      */

201     protected XMLParser() {
202         this(new StringPool());
203     }
204
205     protected XMLParser(StringPool stringPool) {
206         fStringPool = stringPool;
207         fErrorReporter = this;
208         fEntityHandler = new DefaultEntityHandler(fStringPool, fErrorReporter);
209         fScanner = new XMLDocumentScanner(fStringPool, fErrorReporter, fEntityHandler, new ChunkyCharArray(fStringPool));
210         fValidator = new XMLValidator(fStringPool, fErrorReporter, fEntityHandler, fScanner);
211         fGrammarResolver = new GrammarResolverImpl();
212         fScanner.setGrammarResolver(fGrammarResolver);
213         fValidator.setGrammarResolver(fGrammarResolver);
214         try {
215             //JR-defect 48 fix - turn on Namespaces
216
setNamespaces(true);
217         }
218         catch (Exception JavaDoc e) {
219             // ignore
220
}
221     }
222
223     /**
224      * Set char data processing preference and handlers.
225      */

226     protected void initHandlers(boolean sendCharDataAsCharArray,
227                                 XMLDocumentHandler docHandler,
228                                 XMLDocumentHandler.DTDHandler dtdHandler)
229     {
230         fValidator.initHandlers(sendCharDataAsCharArray, docHandler, dtdHandler);
231         fScanner.setDTDHandler(this);
232     }
233
234     //
235
// Public methods
236
//
237

238     // features and properties
239

240     /**
241      * Returns a list of features that this parser recognizes.
242      * This method will never return null; if no features are
243      * recognized, this method will return a zero length array.
244      *
245      * @see #isFeatureRecognized
246      * @see #setFeature
247      * @see #getFeature
248      */

249     public String JavaDoc[] getFeaturesRecognized() {
250         return RECOGNIZED_FEATURES;
251     }
252
253     /**
254      * Returns true if the specified feature is recognized.
255      *
256      * @see #getFeaturesRecognized
257      * @see #setFeature
258      * @see #getFeature
259      */

260     public boolean isFeatureRecognized(String JavaDoc featureId) {
261         String JavaDoc[] recognizedFeatures = getFeaturesRecognized();
262         for (int i = 0; i < recognizedFeatures.length; i++) {
263             if (featureId.equals(recognizedFeatures[i]))
264                 return true;
265         }
266         return false;
267     }
268
269     /**
270      * Returns a list of properties that this parser recognizes.
271      * This method will never return null; if no properties are
272      * recognized, this method will return a zero length array.
273      *
274      * @see #isPropertyRecognized
275      * @see #setProperty
276      * @see #getProperty
277      */

278     public String JavaDoc[] getPropertiesRecognized() {
279         return RECOGNIZED_PROPERTIES;
280     }
281
282     /**
283      * Returns true if the specified property is recognized.
284      *
285      * @see #getPropertiesRecognized
286      * @see #setProperty
287      * @see #getProperty
288      */

289     public boolean isPropertyRecognized(String JavaDoc propertyId) {
290         String JavaDoc[] recognizedProperties = getPropertiesRecognized();
291         for (int i = 0; i < recognizedProperties.length; i++) {
292             if (propertyId.equals(recognizedProperties[i]))
293                 return true;
294         }
295         return false;
296     }
297
298     // initialization
299

300     /**
301      * Setup for application-driven parsing.
302      *
303      * @param source the input source to be parsed.
304      * @see #parseSome
305      */

306     public boolean parseSomeSetup(InputSource JavaDoc source) throws Exception JavaDoc {
307         if (fNeedReset)
308             resetOrCopy();
309         fParseInProgress = true;
310         fNeedReset = true;
311         return fEntityHandler.startReadingFromDocument(source);
312     }
313
314     /**
315      * Application-driven parsing.
316      *
317      * @see #parseSomeSetup
318      */

319     public boolean parseSome() throws Exception JavaDoc {
320         if (!fScanner.parseSome(false)) {
321             fParseInProgress = false;
322             return false;
323         }
324         return true;
325     }
326
327     // resetting
328

329     /** Reset parser instance so that it can be reused. */
330     public void reset() throws Exception JavaDoc {
331         fGrammarResolver.clearGrammarResolver();
332         fStringPool.reset();
333         fEntityHandler.reset(fStringPool);
334         fScanner.reset(fStringPool, new ChunkyCharArray(fStringPool));
335         fValidator.reset(fStringPool);
336         fNeedReset = false;
337     }
338
339     // properties (the normal kind)
340

341     /**
342      * return the locator being used by the parser
343      *
344      * @return the parser's active locator
345      */

346     public final Locator JavaDoc getLocator() {
347         return fEntityHandler;
348     }
349
350
351     /**
352      * return the locale
353      *
354      * @return the locale
355      */

356     public final Locale JavaDoc getfLocale() {
357         return fLocale;
358     }
359
360     /**
361      * return the XML Messages object
362      *
363      * @return the parser's messages object
364      */

365     public final XMLMessageProvider getfgXMLMessages() {
366         return fgXMLMessages;
367     }
368
369     /**
370      * return the Implementation Messages object
371      *
372      * @return the parser's implementation messages
373      */

374     public final XMLMessageProvider getfgImplementationMessages() {
375         return fgImplementationMessages;
376     }
377
378     /**
379      * return the Schema Messages object
380      *
381      * @return the parser's schema messages
382      */

383     public final XMLMessageProvider getfgSchemaMessages() {
384         return fgSchemaMessages;
385     }
386
387     /**
388      * return the Datatypes Messages object
389      *
390      * @return the parser's datatypes messages
391      */

392     public final XMLMessageProvider getfgDatatypeMessages() {
393         return fgDatatypeMessages;
394     }
395
396     /**
397      * Set the reader factory.
398      */

399     public void setReaderFactory(XMLEntityReaderFactory readerFactory) {
400         fEntityHandler.setReaderFactory(readerFactory);
401     }
402
403     /**
404      * Adds a recognizer.
405      *
406      * @param recognizer The XML recognizer to add.
407      */

408     public void addRecognizer(XMLDeclRecognizer recognizer) {
409         fEntityHandler.addRecognizer(recognizer);
410     }
411
412     //
413
// Protected methods
414
//
415

416     // SAX2 core features
417

418     /**
419      * Sets whether the parser validates.
420      * <p>
421      * This method is the equivalent to the feature:
422      * <pre>
423      * http://xml.org/sax/features/validation
424      * </pre>
425      *
426      * @param validate True to validate; false to not validate.
427      *
428      * @see #getValidation
429      * @see #setFeature
430      */

431     protected void setValidation(boolean validate)
432         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
433         if (fParseInProgress) {
434             throw new SAXNotSupportedException JavaDoc("PAR004 Cannot setFeature(http://xml.org/sax/features/validation): parse is in progress.\n"+
435                                                "http://xml.org/sax/features/validation");
436         }
437         try {
438             // REVISIT: [Q] Should the scanner tell the validator that
439
// validation is on? -Ac
440
fScanner.setValidationEnabled(validate);
441             fValidator.setValidationEnabled(validate);
442         }
443         catch (Exception JavaDoc ex) {
444             throw new SAXNotSupportedException JavaDoc(ex.getMessage());
445         }
446     }
447
448     /**
449      * Returns true if validation is turned on.
450      *
451      * @see #setValidation
452      */

453     protected boolean getValidation()
454         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
455         return fValidator.getValidationEnabled();
456     }
457
458     /**
459      * <b>Note: Currently, this parser always expands external general
460      * entities.</b> Setting this feature to false will throw a
461      * SAXNotSupportedException.
462      * <p>
463      * Sets whether external general entities are expanded.
464      * <p>
465      * This method is the equivalent to the feature:
466      * <pre>
467      * http://xml.org/sax/features/external-general-entities
468      * </pre>
469      *
470      * @param expand True to expand external general entities; false
471      * to not expand.
472      *
473      * @see #getExternalGeneralEntities
474      * @see #setFeature
475      */

476     protected void setExternalGeneralEntities(boolean expand)
477         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
478         if (fParseInProgress) {
479             throw new SAXNotSupportedException JavaDoc("PAR004 Cannot setFeature(http://xml.org/sax/features/external-general-entities): parse is in progress.\n"+
480                                                "http://xml.org/sax/features/external-general-entities");
481         }
482         if (!expand) {
483             throw new SAXNotSupportedException JavaDoc("http://xml.org/sax/features/external-general-entities");
484         }
485     }
486
487     /**
488      * <b>Note: This feature is always true.</b>
489      * <p>
490      * Returns true if external general entities are expanded.
491      *
492      * @see #setExternalGeneralEntities
493      */

494     protected boolean getExternalGeneralEntities()
495         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
496         return true;
497     }
498
499     /**
500      * <b>Note: Currently, this parser always expands external parameter
501      * entities.</b> Setting this feature to false will throw a
502      * SAXNotSupportedException.
503      * <p>
504      * Sets whether external parameter entities are expanded.
505      * <p>
506      * This method is the equivalent to the feature:
507      * <pre>
508      * http://xml.org/sax/features/external-parameter-entities
509      * </pre>
510      *
511      * @param expand True to expand external parameter entities; false
512      * to not expand.
513      *
514      * @see #getExternalParameterEntities
515      * @see #setFeature
516      */

517     protected void setExternalParameterEntities(boolean expand)
518         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
519         if (fParseInProgress) {
520             throw new SAXNotSupportedException JavaDoc("PAR004 Cannot setFeature(http://xml.org/sax/features/external-general-entities): parse is in progress.\n"+
521                                                "http://xml.org/sax/features/external-general-entities");
522         }
523         if (!expand) {
524             throw new SAXNotSupportedException JavaDoc("http://xml.org/sax/features/external-parameter-entities");
525         }
526     }
527
528     /**
529      * <b>Note: This feature is always true.</b>
530      * <p>
531      * Returns true if external parameter entities are expanded.
532      *
533      * @see #setExternalParameterEntities
534      */

535     protected boolean getExternalParameterEntities()
536         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
537         return true;
538     }
539
540     /**
541      * Sets whether the parser preprocesses namespaces.
542      * <p>
543      * This method is the equivalent to the feature:
544      * <pre>
545      * http://xml.org/sax/features/namespaces
546      * <pre>
547      *
548      * @param process True to process namespaces; false to not process.
549      *
550      * @see #getNamespaces
551      * @see #setFeature
552      */

553     protected void setNamespaces(boolean process)
554         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
555         if (fParseInProgress) {
556             throw new SAXNotSupportedException JavaDoc("PAR004 Cannot setFeature(http://xml.org/sax/features/namespaces): parse is in progress.\n"+
557                                                "http://xml.org/sax/features/namespaces");
558         }
559         fScanner.setNamespacesEnabled(process);
560         // REVISIT: [Q] Should the scanner tell the validator that namespace
561
// processing is on? -Ac
562
fValidator.setNamespacesEnabled(process);
563     }
564
565     /**
566      * Returns true if the parser preprocesses namespaces.
567      *
568      * @see #setNamespaces
569      */

570     protected boolean getNamespaces()
571         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
572         return fValidator.getNamespacesEnabled();
573     }
574
575     // Xerces features
576

577     /**
578      * Allows the user to turn Schema support on/off.
579      * <p>
580      * This method is equivalent to the feature:
581      * <pre>
582      * http://apache.org/xml/features/validation/schema
583      * </pre>
584      *
585      * @param schema True to turn on Schema support; false to turn it off.
586      *
587      * @see #getValidationSchema
588      * @see #setFeature
589      */

590     protected void setValidationSchema(boolean schema)
591         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
592         if (fParseInProgress) {
593             // REVISIT: Localize message
594
throw new SAXNotSupportedException JavaDoc("http://apache.org/xml/features/validation/schema: parse is in progress");
595         }
596         fValidator.setSchemaValidationEnabled(schema);
597     }
598
599     /**
600      * Returns true if Schema support is turned on.
601      *
602      * @see #setValidationSchema
603      */

604     protected boolean getValidationSchema()
605         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
606         return fValidator.getSchemaValidationEnabled();
607     }
608
609     /**
610      * Allows the user to turn full Schema constraint checking on/off.
611      * Only takes effect if Schema validation is enabled.
612      * If this feature is off, partial constraint checking is done.
613      * <p>
614      * This method is equivalent to the feature:
615      * <pre>
616      * http://apache.org/xml/features/validation/schema-full-checking
617      * </pre>
618      *
619      * @param schemaFullChecking True to turn on full schema constraint checking.
620      *
621      * @see #getValidationSchemaFullChecking
622      * @see #setFeature
623      */

624     protected void setValidationSchemaFullChecking(boolean schemaFullChecking)
625         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
626         if (fParseInProgress) {
627             // REVISIT: Localize message
628
throw new SAXNotSupportedException JavaDoc("http://apache.org/xml/features/validation/schema-full-checking: parse is in progress");
629         }
630         fValidator.setSchemaFullCheckingEnabled(schemaFullChecking);
631     }
632
633
634     /**
635      * Normalization of element content is controlled by this feature.
636      * If this feature is set to true, DOM and SAX APIs will expose element content
637      * that is normalized according to XML Schema REC.
638      * Otherwise, element content will be exposed as required by the infoset.
639      *
640      * @param normalize
641      */

642     protected void setNormalizeContents(boolean normalize) {
643         fValidator.setNormalizeContents(normalize);
644     }
645     protected boolean getNormalizeContents() {
646         return fValidator.getNormalizeConents();
647     }
648
649     /**
650      * Allows the user to set a list of external XML Schemas (ex."http://example.com schema.xsd")
651      * to be used by the parser.
652      * If two schemas with the same targetNamespace appear in both
653      * the list and a document, the one from the list will be picked up.
654      * See XML Schema REC: http://www.w3.org/TR/xmlschema-1/#schema-loc
655      * <P>
656      * This method is equivalent to the property:
657      * <PRE>http://apache.org/xml/properties/schema/external-schemaLocation</PRE>
658      *
659      * @param value The list of schemas.
660      * @exception SAXNotRecognizedException
661      * @exception SAXNotSupportedException
662      */

663     protected void setExternalSchemaLocation(Object JavaDoc value)
664         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
665         if (fParseInProgress) {
666             // REVISIT: Localize message
667
throw new SAXNotSupportedException JavaDoc("http://apache.org/xml/properties/validation/schema/external-schemaLocation: parse is in progress");
668         }
669         fValidator.setExternalSchemas(value);
670     }
671
672     /**
673      * Allows the user to set external XML Schema with no target Namespace.
674      * This value overwrites the value on the _noNamespaceSchemaLocation_.
675      * See XML Schema REC: http://www.w3.org/TR/xmlschema-1/#schema-loc
676      * <P>
677      * This method is equivalent to the property:
678      * <PRE>http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation</PRE>
679      *
680      * @param value An XML Schema file name
681      * @exception SAXNotRecognizedException
682      * @exception SAXNotSupportedException
683      */

684     protected void setExternalNoNamespaceSchemaLocation(Object JavaDoc value)
685         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
686         if (fParseInProgress) {
687             // REVISIT: Localize message
688
throw new SAXNotSupportedException JavaDoc("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation: parse is in progress");
689         }
690         fValidator.setExternalNoNamespaceSchema(value);
691     }
692
693     /**
694      * Returns true if Schema support is turned on.
695      *
696      * @see #setValidationSchemaFullChecking
697      */

698     protected boolean getValidationSchemaFullChecking()
699         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
700         return fValidator.getSchemaFullCheckingEnabled();
701     }
702
703
704     /**
705      * Allows the parser to validate a document only when it contains a
706      * grammar. Validation is turned on/off based on each document
707      * instance, automatically.
708      * <p>
709      * This method is the equivalent to the feature:
710      * <pre>
711      * http://apache.org/xml/features/validation/dynamic
712      * </pre>
713      *
714      * @param dynamic True to dynamically validate documents; false to
715      * validate based on the validation feature.
716      *
717      * @see #getValidationDynamic
718      * @see #setFeature
719      */

720     protected void setValidationDynamic(boolean dynamic)
721         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
722         if (fParseInProgress) {
723             // REVISIT: Localize message
724
throw new SAXNotSupportedException JavaDoc("http://apache.org/xml/features/validation/dynamic: parse is in progress");
725         }
726         try {
727             fValidator.setDynamicValidationEnabled(dynamic);
728         }
729         catch (Exception JavaDoc ex) {
730             throw new SAXNotSupportedException JavaDoc(ex.getMessage());
731         }
732     }
733
734     /**
735      * Returns true if validation is based on whether a document
736      * contains a grammar.
737      *
738      * @see #setValidationDynamic
739      */

740     protected boolean getValidationDynamic()
741         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
742         return fValidator.getDynamicValidationEnabled();
743     }
744
745     /**
746      *
747      */

748     protected void setNormalizeAttributeValues(boolean normalize) {
749         fValidator.setNormalizeAttributeValues(normalize);
750     }
751
752     /**
753      * Allows the parser to have the choice to load DTD grammar when
754      * validation is off.
755      * <p>
756      * This method is the equivalent to the feature:
757      * <pre>
758      * http://apache.org/xml/features/nonvalidating/load-dtd-grammar
759      * </pre>
760      *
761      * @param loadDTDGrammar True to turn on the feature; false to
762      * turn off the feature.
763      *
764      * @see #getLoadDTDGrammar
765      * @see #setFeature
766      */

767     protected void setLoadDTDGrammar(boolean loadDTDGrammar)
768         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
769         if (fParseInProgress) {
770             // REVISIT: Localize message
771
throw new SAXNotSupportedException JavaDoc("http://apache.org/xml/features/nonvalidating/load-dtd-grammar: parse is in progress");
772         }
773         try {
774             fValidator.setLoadDTDGrammar(loadDTDGrammar);
775         }
776         catch (Exception JavaDoc ex) {
777             throw new SAXNotSupportedException JavaDoc(ex.getMessage());
778         }
779     }
780
781     /**
782      * Returns true if load DTD grammar is turned on in the XMLValiator.
783      *
784      * @see #setLoadDTDGrammar
785      */

786     protected boolean getLoadDTDGrammar()
787         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
788         return fValidator.getLoadDTDGrammar();
789     }
790
791     /**
792      * Allows the parser to have the choice to load the external DTD when
793      * validation is off.
794      * <p>
795      * This method is the equivalent to the feature:
796      * <pre>
797      * http://apache.org/xml/features/nonvalidating/load-external-dtd
798      * </pre>
799      *
800      * @param loadExternalDTD True to turn on the feature; false to
801      * turn off the feature.
802      *
803      * @see #getLoadExternalDTD
804      * @see #setFeature
805      */

806     protected void setLoadExternalDTD(boolean loadExternalDTD)
807         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
808         if (fParseInProgress) {
809             // REVISIT: Localize message
810
throw new SAXNotSupportedException JavaDoc("http://apache.org/xml/features/nonvalidating/load-external-dtd: parse is in progress");
811         }
812         try {
813             fScanner.setLoadExternalDTD(loadExternalDTD);
814         }
815         catch (Exception JavaDoc ex) {
816             throw new SAXNotSupportedException JavaDoc(ex.getMessage());
817         }
818     }
819
820     /**
821      * Returns true if loading of the external DTD is on.
822      *
823      * @see #setLoadExternalDTD
824      */

825     protected boolean getLoadExternalDTD()
826         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
827         return fScanner.getLoadExternalDTD();
828     }
829
830     /**
831      * Sets whether an error is emitted when an attribute is redefined
832      * in the grammar.
833      * <p>
834      * This method is the equivalent to the feature:
835      * <pre>
836      * http://apache.org/xml/features/validation/warn-on-duplicate-attdef
837      * </pre>
838      *
839      * @param warn True to warn; false to not warn.
840      *
841      * @see #getValidationWarnOnDuplicateAttdef
842      * @see #setFeature
843      */

844     protected void setValidationWarnOnDuplicateAttdef(boolean warn)
845         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
846         fValidator.setWarningOnDuplicateAttDef(warn);
847     }
848
849     /**
850      * Returns true if an error is emitted when an attribute is redefined
851      * in the grammar.
852      *
853      * @see #setValidationWarnOnDuplicateAttdef
854      */

855     protected boolean getValidationWarnOnDuplicateAttdef()
856         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
857         return fValidator.getWarningOnDuplicateAttDef();
858     }
859
860     /**
861      * Sets whether the parser emits an error when an element's content
862      * model references an element by name that is not declared in the
863      * grammar.
864      * <p>
865      * This method is the equivalent to the feature:
866      * <pre>
867      * http://apache.org/xml/features/validation/warn-on-undeclared-elemdef
868      * </pre>
869      *
870      * @param warn True to warn; false to not warn.
871      *
872      * @see #getValidationWarnOnUndeclaredElemdef
873      * @see #setFeature
874      */

875     protected void setValidationWarnOnUndeclaredElemdef(boolean warn)
876         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
877         fValidator.setWarningOnUndeclaredElements(warn);
878     }
879
880     /**
881      * Returns true if the parser emits an error when an undeclared
882      * element is referenced in the grammar.
883      *
884      * @see #setValidationWarnOnUndeclaredElemdef
885      */

886     protected boolean getValidationWarnOnUndeclaredElemdef()
887         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
888         return fValidator.getWarningOnUndeclaredElements();
889     }
890
891     /**
892      * Allows the use of Java encoding names in the XMLDecl and TextDecl
893      * lines in an XML document.
894      * <p>
895      * This method is the equivalent to the feature:
896      * <pre>
897      * http://apache.org/xml/features/allow-java-encodings
898      * </pre>
899      *
900      * @param allow True to allow Java encoding names; false to disallow.
901      *
902      * @see #getAllowJavaEncodings
903      * @see #setFeature
904      */

905     protected void setAllowJavaEncodings(boolean allow)
906         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
907         fEntityHandler.setAllowJavaEncodings(allow);
908     }
909
910     /**
911      * Returns true if Java encoding names are allowed in the XML document.
912      *
913      * @see #setAllowJavaEncodings
914      */

915     protected boolean getAllowJavaEncodings()
916         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
917         return fEntityHandler.getAllowJavaEncodings();
918     }
919
920     /**
921      * Allows the parser to continue after a fatal error. Normally, a
922      * fatal error would stop the parse.
923      * <p>
924      * This method is the equivalent to the feature:
925      * <pre>
926      * http://apache.org/xml/features/continue-after-fatal-error
927      * </pre>
928      *
929      * @param continueAfterFatalError True to continue; false to stop on
930      * fatal error.
931      *
932      * @see #getContinueAfterFatalError
933      * @see #setFeature
934      */

935     protected void setContinueAfterFatalError(boolean continueAfterFatalError)
936         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
937         fContinueAfterFatalError = continueAfterFatalError;
938     }
939
940     /**
941      * Returns true if the parser continues after a fatal error.
942      *
943      * @see #setContinueAfterFatalError
944      */

945     protected boolean getContinueAfterFatalError()
946         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
947         return fContinueAfterFatalError;
948     }
949
950     // SAX2 core properties
951

952     /**
953      * Set the separator to be used between the URI part of a name and the
954      * local part of a name when namespace processing is being performed
955      * (see the http://xml.org/sax/features/namespaces feature). By default,
956      * the separator is a single space.
957      * <p>
958      * This property may not be set while a parse is in progress (throws a
959      * SAXNotSupportedException).
960      * <p>
961      * This method is the equivalent to the property:
962      * <pre>
963      * http://xml.org/sax/properties/namespace-sep
964      * </pre>
965      *
966      * @param separator The new namespace separator.
967      *
968      * @see #getNamespaceSep
969      * @see #setProperty
970      */

971     /***
972     protected void setNamespaceSep(String separator)
973         throws SAXNotRecognizedException, SAXNotSupportedException {
974         // REVISIT: Ask someone what it could possibly hurt to allow
975         // the application to change this in mid-parse.
976         if (fParseInProgress) {
977             throw new SAXNotSupportedException("http://xml.org/sax/properties/namespace-sep: parse is in progress");
978         }
979         fNamespaceSep = separator;
980     }
981     /***/

982
983     /**
984      * Returns the namespace separator.
985      *
986      * @see #setNamespaceSep
987      */

988     /***
989     protected String getNamespaceSep()
990         throws SAXNotRecognizedException, SAXNotSupportedException {
991         return fNamespaceSep;
992     }
993     /***/

994
995     /**
996      * This method is the equivalent to the property:
997      * <pre>
998      * http://xml.org/sax/properties/xml-string
999      * </pre>
1000     *
1001     * @see #getProperty
1002     */

1003    protected String JavaDoc getXMLString()
1004        throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
1005        throw new SAXNotSupportedException JavaDoc("http://xml.org/sax/properties/xml-string");
1006    }
1007
1008    // resetting
1009

1010    /**
1011     * Reset or copy parser
1012     * Allows parser instance reuse
1013     */

1014    protected void resetOrCopy() throws Exception JavaDoc {
1015        fStringPool = new StringPool();
1016        fEntityHandler.reset(fStringPool);
1017        fScanner.reset(fStringPool, new ChunkyCharArray(fStringPool));
1018        fValidator.resetOrCopy(fStringPool);
1019        fNeedReset = false;
1020        // REVISIT: why did we do it?
1021
//fGrammarResolver = new GrammarResolverImpl();
1022
fGrammarResolver.clearGrammarResolver();
1023        fScanner.setGrammarResolver(fGrammarResolver);
1024        fValidator.setGrammarResolver(fGrammarResolver);
1025    }
1026
1027    //
1028
// Parser/XMLReader methods
1029
//
1030
// NOTE: This class does *not* implement the org.xml.sax.Parser
1031
// interface but it does share some common methods. -Ac
1032

1033    // handlers
1034

1035    /**
1036     * Sets the resolver used to resolve external entities. The EntityResolver
1037     * interface supports resolution of public and system identifiers.
1038     *
1039     * @param resolver The new entity resolver. Passing a null value will
1040     * uninstall the currently installed resolver.
1041     */

1042    public void setEntityResolver(EntityResolver JavaDoc resolver) {
1043        fEntityHandler.setEntityResolver(resolver);
1044    }
1045
1046    /**
1047     * Return the current entity resolver.
1048     *
1049     * @return The current entity resolver, or null if none
1050     * has been registered.
1051     * @see #setEntityResolver
1052     */

1053    public EntityResolver JavaDoc getEntityResolver() {
1054        return fEntityHandler.getEntityResolver();
1055    }
1056
1057    /**
1058     * Sets the error handler.
1059     *
1060     * @param handler The new error handler.
1061     */

1062    public void setErrorHandler(ErrorHandler JavaDoc handler) {
1063        fErrorHandler = handler;
1064    }
1065
1066    /**
1067     * Return the current error handler.
1068     *
1069     * @return The current error handler, or null if none
1070     * has been registered.
1071     * @see #setErrorHandler
1072     */

1073    public ErrorHandler JavaDoc getErrorHandler() {
1074        return fErrorHandler;
1075    }
1076
1077    // parsing
1078

1079    /**
1080     * Parses the specified input source.
1081     *
1082     * @param source The input source.
1083     *
1084     * @exception org.xml.sax.SAXException Throws exception on SAX error.
1085     * @exception java.io.IOException Throws exception on i/o error.
1086     */

1087    public void parse(InputSource JavaDoc source)
1088        throws SAXException JavaDoc, IOException JavaDoc {
1089        if (fParseInProgress) {
1090            throw new org.xml.sax.SAXException JavaDoc("FWK005 parse may not be called while parsing."); // REVISIT - need to add new error message
1091
}
1092
1093        try {
1094            if (parseSomeSetup(source)) {
1095                fScanner.parseSome(true);
1096            }
1097        } catch (org.xml.sax.SAXException JavaDoc ex) {
1098            if (PRINT_EXCEPTION_STACK_TRACE)
1099                ex.printStackTrace();
1100            throw ex;
1101        } catch (IOException JavaDoc ex) {
1102            if (PRINT_EXCEPTION_STACK_TRACE)
1103                ex.printStackTrace();
1104            throw ex;
1105        } catch (Exception JavaDoc ex) {
1106            if (PRINT_EXCEPTION_STACK_TRACE)
1107                ex.printStackTrace();
1108            throw new org.xml.sax.SAXException JavaDoc(ex);
1109        }
1110        finally {
1111            fParseInProgress = false;
1112        }
1113
1114    } // parse(InputSource)
1115

1116    /**
1117     * Parses the input source specified by the given system identifier.
1118     * <p>
1119     * This method is <em>almost</em> equivalent to the following:
1120     * <pre>
1121     * parse(new InputSource(systemId));
1122     * </pre>
1123     * The only difference is that this method will attempt to close
1124     * the stream that was opened.
1125     *
1126     * @param source The input source.
1127     *
1128     * @exception org.xml.sax.SAXException Throws exception on SAX error.
1129     * @exception java.io.IOException Throws exception on i/o error.
1130     */

1131    public void parse(String JavaDoc systemId)
1132        throws SAXException JavaDoc, IOException JavaDoc {
1133
1134        InputSource JavaDoc source = new InputSource JavaDoc(systemId);
1135        try {
1136            parse(source);
1137        }
1138        finally {
1139            // NOTE: Changed code to attempt to close the stream
1140
// even after parsing failure. -Ac
1141
try {
1142                Reader JavaDoc reader = source.getCharacterStream();
1143                if (reader != null) {
1144                    reader.close();
1145                }
1146                else {
1147                    InputStream JavaDoc is = source.getByteStream();
1148                    if (is != null) {
1149                        is.close();
1150                    }
1151                }
1152            }
1153            catch (IOException JavaDoc e) {
1154                // ignore
1155
}
1156        }
1157
1158    } // parse(String)
1159

1160    // locale
1161

1162    /**
1163     * Set the locale to use for messages.
1164     *
1165     * @param locale The locale object to use for localization of messages.
1166     *
1167     * @exception SAXException An exception thrown if the parser does not
1168     * support the specified locale.
1169     *
1170     * @see org.xml.sax.Parser
1171     */

1172    public void setLocale(Locale JavaDoc locale) throws SAXException JavaDoc {
1173
1174        if (fParseInProgress) {
1175            throw new org.xml.sax.SAXException JavaDoc("FWK006 setLocale may not be called while parsing"); // REVISIT - need to add new error message
1176
}
1177
1178        fLocale = locale;
1179        fgXMLMessages.setLocale(locale);
1180        fgImplementationMessages.setLocale(locale);
1181
1182    } // setLocale(Locale)
1183

1184    //
1185
// XMLErrorReporter methods
1186
//
1187

1188    /**
1189     * Report an error.
1190     *
1191     * @param locator Location of error.
1192     * @param errorDomain The error domain.
1193     * @param majorCode The major code of the error.
1194     * @param minorCode The minor code of the error.
1195     * @param args Arguments for replacement text.
1196     * @param errorType The type of the error.
1197     *
1198     * @exception Exception Thrown on error.
1199     *
1200     * @see XMLErrorReporter#ERRORTYPE_WARNING
1201     * @see XMLErrorReporter#ERRORTYPE_FATAL_ERROR
1202     */

1203    public void reportError(Locator JavaDoc locator, String JavaDoc errorDomain,
1204                            int majorCode, int minorCode, Object JavaDoc args[],
1205                            int errorType) throws Exception JavaDoc {
1206
1207        // create the appropriate message
1208
SAXParseException JavaDoc spe;
1209        if (errorDomain.equals(XMLMessages.XML_DOMAIN)) {
1210            spe = new SAXParseException JavaDoc(fgXMLMessages.createMessage(fLocale, majorCode, minorCode, args), locator);
1211        }
1212        else if (errorDomain.equals(XMLMessages.XMLNS_DOMAIN)) {
1213            spe = new SAXParseException JavaDoc(fgXMLMessages.createMessage(fLocale, majorCode, minorCode, args), locator);
1214        }
1215        else if (errorDomain.equals(ImplementationMessages.XERCES_IMPLEMENTATION_DOMAIN)) {
1216            spe = new SAXParseException JavaDoc(fgImplementationMessages.createMessage(fLocale, majorCode, minorCode, args), locator);
1217        } else if (errorDomain.equals(SchemaMessageProvider.SCHEMA_DOMAIN)) {
1218            spe = new SAXParseException JavaDoc(fgSchemaMessages.createMessage(fLocale, majorCode, minorCode, args), locator);
1219        } else if (errorDomain.equals(DatatypeMessageProvider.DATATYPE_DOMAIN)) {
1220            spe = new SAXParseException JavaDoc(fgDatatypeMessages.createMessage(fLocale, majorCode, minorCode, args), locator);
1221        } else {
1222            throw new RuntimeException JavaDoc("FWK007 Unknown error domain \"" + errorDomain + "\"."+"\n"+errorDomain);
1223        }
1224
1225        // default error handling
1226
if (fErrorHandler == null) {
1227            if (errorType == XMLErrorReporter.ERRORTYPE_FATAL_ERROR &&
1228                !fContinueAfterFatalError) {
1229                throw spe;
1230            }
1231            return;
1232        }
1233
1234        // make appropriate callback
1235
if (errorType == XMLErrorReporter.ERRORTYPE_WARNING) {
1236            fErrorHandler.warning(spe);
1237        }
1238        else if (errorType == XMLErrorReporter.ERRORTYPE_FATAL_ERROR) {
1239            fErrorHandler.fatalError(spe);
1240            if (!fContinueAfterFatalError) {
1241                Object JavaDoc[] fatalArgs = { spe.getMessage() };
1242                throw new SAXException JavaDoc(fgImplementationMessages.createMessage(fLocale, ImplementationMessages.FATAL_ERROR, 0, fatalArgs));
1243            }
1244        }
1245        else {
1246            fErrorHandler.error(spe);
1247        }
1248
1249    } // reportError(Locator,String,int,int,Object[],int)
1250

1251    //
1252
// XMLReader methods
1253
//
1254

1255    /**
1256     * Set the state of a feature.
1257     *
1258     * Set the state of any feature in a SAX2 parser. The parser
1259     * might not recognize the feature, and if it does recognize
1260     * it, it might not be able to fulfill the request.
1261     *
1262     * @param featureId The unique identifier (URI) of the feature.
1263     * @param state The requested state of the feature (true or false).
1264     *
1265     * @exception org.xml.sax.SAXNotRecognizedException If the
1266     * requested feature is not known.
1267     * @exception org.xml.sax.SAXNotSupportedException If the
1268     * requested feature is known, but the requested
1269     * state is not supported.
1270     * @exception org.xml.sax.SAXException If there is any other
1271     * problem fulfilling the request.
1272     */

1273    public void setFeature(String JavaDoc featureId, boolean state)
1274        throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
1275
1276        //
1277
// SAX2 Features
1278
//
1279

1280        if (featureId.startsWith(SAX2_FEATURES_PREFIX)) {
1281            String JavaDoc feature = featureId.substring(SAX2_FEATURES_PREFIX.length());
1282            //
1283
// http://xml.org/sax/features/validation
1284
// Validate (true) or don't validate (false).
1285
//
1286
if (feature.equals("validation")) {
1287                setValidation(state);
1288                return;
1289            }
1290            //
1291
// http://xml.org/sax/features/external-general-entities
1292
// Expand external general entities (true) or don't expand (false).
1293
//
1294
if (feature.equals("external-general-entities")) {
1295                setExternalGeneralEntities(state);
1296                return;
1297            }
1298            //
1299
// http://xml.org/sax/features/external-parameter-entities
1300
// Expand external parameter entities (true) or don't expand (false).
1301
//
1302
if (feature.equals("external-parameter-entities")) {
1303                setExternalParameterEntities(state);
1304                return;
1305            }
1306            //
1307
// http://xml.org/sax/features/namespaces
1308
// Preprocess namespaces (true) or don't preprocess (false). See also
1309
// the http://xml.org/sax/properties/namespace-sep property.
1310
//
1311
if (feature.equals("namespaces")) {
1312                setNamespaces(state);
1313                return;
1314            }
1315            //
1316
// Not recognized
1317
//
1318
}
1319
1320        //
1321
// Xerces Features
1322
//
1323

1324        else if (featureId.startsWith(XERCES_FEATURES_PREFIX)) {
1325            String JavaDoc feature = featureId.substring(XERCES_FEATURES_PREFIX.length());
1326            //
1327
// http://apache.org/xml/features/validation/schema
1328
// Lets the user turn Schema validation support on/off.
1329
//
1330
if (feature.equals("validation/schema")) {
1331                setValidationSchema(state);
1332                return;
1333            }
1334            //
1335
// http://apache.org/xml/features/validation/schema-full-checking
1336
// Lets the user turn Schema full constraint checking on/off.
1337
//
1338
if (feature.equals("validation/schema-full-checking")) {
1339                setValidationSchemaFullChecking(state);
1340                return;
1341            }
1342
1343            //
1344
// http://apache.org/xml/features/validation/dynamic
1345
// Allows the parser to validate a document only when it
1346
// contains a grammar. Validation is turned on/off based
1347
// on each document instance, automatically.
1348
//
1349
if (feature.equals("validation/dynamic")) {
1350                setValidationDynamic(state);
1351                return;
1352            }
1353            //
1354
// http://apache.org/xml/features/validation/default-attribute-values
1355
//
1356
if (feature.equals("validation/default-attribute-values")) {
1357                // REVISIT
1358
throw new SAXNotSupportedException JavaDoc(featureId);
1359            }
1360
1361            if (feature.equals("schema/expose-normalized-values")) {
1362                setNormalizeContents(state);
1363                return;
1364             }
1365            //
1366
// http://apache.org/xml/features/validation/normalize-attribute-values
1367
//
1368
if (feature.equals("validation/normalize-attribute-values")) {
1369                setNormalizeAttributeValues(state);
1370            }
1371            //
1372
// http://apache.org/xml/features/validation/validate-content-models
1373
//
1374
if (feature.equals("validation/validate-content-models")) {
1375                // REVISIT
1376
throw new SAXNotSupportedException JavaDoc(featureId);
1377            }
1378            //
1379
// http://apache.org/xml/features/validation/nonvalidating/load-dtd-grammar
1380
//
1381
if (feature.equals("nonvalidating/load-dtd-grammar")) {
1382                setLoadDTDGrammar(state);
1383                return;
1384            }
1385            //
1386
// http://apache.org/xml/features/validation/nonvalidating/load-external-dtd
1387
//
1388
if (feature.equals("nonvalidating/load-external-dtd")) {
1389                setLoadExternalDTD(state);
1390                return;
1391            }
1392
1393            //
1394
// http://apache.org/xml/features/validation/default-attribute-values
1395
//
1396
if (feature.equals("validation/validate-datatypes")) {
1397                // REVISIT
1398
throw new SAXNotSupportedException JavaDoc(featureId);
1399            }
1400            //
1401
// http://apache.org/xml/features/validation/warn-on-duplicate-attdef
1402
// Emits an error when an attribute is redefined.
1403
//
1404
if (feature.equals("validation/warn-on-duplicate-attdef")) {
1405                setValidationWarnOnDuplicateAttdef(state);
1406                return;
1407            }
1408            //
1409
// http://apache.org/xml/features/validation/warn-on-undeclared-elemdef
1410
// Emits an error when an element's content model
1411
// references an element, by name, that is not declared
1412
// in the grammar.
1413
//
1414
if (feature.equals("validation/warn-on-undeclared-elemdef")) {
1415                setValidationWarnOnUndeclaredElemdef(state);
1416                return;
1417            }
1418            //
1419
// http://apache.org/xml/features/allow-java-encodings
1420
// Allows the use of Java encoding names in the XML
1421
// and TextDecl lines.
1422
//
1423
if (feature.equals("allow-java-encodings")) {
1424                setAllowJavaEncodings(state);
1425                return;
1426            }
1427            //
1428
// http://apache.org/xml/features/continue-after-fatal-error
1429
// Allows the parser to continue after a fatal error.
1430
// Normally, a fatal error would stop the parse.
1431
//
1432
if (feature.equals("continue-after-fatal-error")) {
1433                setContinueAfterFatalError(state);
1434                return;
1435            }
1436            //
1437
// Not recognized
1438
//
1439
}
1440
1441        //
1442
// Not recognized
1443
//
1444

1445        throw new SAXNotRecognizedException JavaDoc(featureId);
1446
1447    } // setFeature(String,boolean)
1448

1449    /**
1450     * Query the state of a feature.
1451     *
1452     * Query the current state of any feature in a SAX2 parser. The
1453     * parser might not recognize the feature.
1454     *
1455     * @param featureId The unique identifier (URI) of the feature
1456     * being set.
1457     * @return The current state of the feature.
1458     * @exception org.xml.sax.SAXNotRecognizedException If the
1459     * requested feature is not known.
1460     * @exception org.xml.sax.SAXException If there is any other
1461     * problem fulfilling the request.
1462     */

1463    public boolean getFeature(String JavaDoc featureId)
1464        throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
1465
1466        //
1467
// SAX2 Features
1468
//
1469

1470        if (featureId.startsWith(SAX2_FEATURES_PREFIX)) {
1471            String JavaDoc feature = featureId.substring(SAX2_FEATURES_PREFIX.length());
1472            //
1473
// http://xml.org/sax/features/validation
1474
// Validate (true) or don't validate (false).
1475
//
1476
if (feature.equals("validation")) {
1477                return getValidation();
1478            }
1479            //
1480
// http://xml.org/sax/features/external-general-entities
1481
// Expand external general entities (true) or don't expand (false).
1482
//
1483
if (feature.equals("external-general-entities")) {
1484                return getExternalGeneralEntities();
1485            }
1486            //
1487
// http://xml.org/sax/features/external-parameter-entities
1488
// Expand external parameter entities (true) or don't expand (false).
1489
//
1490
if (feature.equals("external-parameter-entities")) {
1491                return getExternalParameterEntities();
1492            }
1493            //
1494
// http://xml.org/sax/features/namespaces
1495
// Preprocess namespaces (true) or don't preprocess (false). See also
1496
// the http://xml.org/sax/properties/namespace-sep property.
1497
//
1498
if (feature.equals("namespaces")) {
1499                return getNamespaces();
1500            }
1501            //
1502
// Not recognized
1503
//
1504
}
1505
1506        //
1507
// Xerces Features
1508
//
1509

1510        else if (featureId.startsWith(XERCES_FEATURES_PREFIX)) {
1511            String JavaDoc feature = featureId.substring(XERCES_FEATURES_PREFIX.length());
1512            //
1513
// http://apache.org/xml/features/validation/schema
1514
// Lets the user turn Schema validation support on/off.
1515
//
1516
if (feature.equals("validation/schema")) {
1517                return getValidationSchema();
1518            }
1519            // http://apache.org/xml/features/validation/schema-full-checking
1520
// Lets the user turn Schema full constraint checking on/off.
1521
//
1522
if (feature.equals("validation/schema-full-checking")) {
1523                return getValidationSchemaFullChecking();
1524            }
1525            //
1526
//
1527
// http://apache.org/xml/features/validation/dynamic
1528
// Allows the parser to validate a document only when it
1529
// contains a grammar. Validation is turned on/off based
1530
// on each document instance, automatically.
1531
//
1532
if (feature.equals("validation/dynamic")) {
1533                return getValidationDynamic();
1534            }
1535            //
1536
// http://apache.org/xml/features/validation/default-attribute-values
1537
//
1538
if (feature.equals("validation/default-attribute-values")) {
1539                // REVISIT
1540
throw new SAXNotRecognizedException JavaDoc(featureId);
1541            }
1542            if (feature.equals("validation/normalize-element-contents")) {
1543                return getNormalizeContents();
1544            }
1545            //
1546
// http://apache.org/xml/features/validation/validate-content-models
1547
//
1548
if (feature.equals("validation/validate-content-models")) {
1549                // REVISIT
1550
throw new SAXNotRecognizedException JavaDoc(featureId);
1551            }
1552            //
1553
// http://apache.org/xml/features/nonvalidating/load-dtd-grammar
1554
//
1555
if (feature.equals("nonvalidating/load-dtd-grammar")) {
1556                return getLoadDTDGrammar();
1557            }
1558            //
1559
// http://apache.org/xml/features/nonvalidating/load-external-dtd
1560
//
1561
if (feature.equals("nonvalidating/load-external-dtd")) {
1562                return getLoadExternalDTD();
1563            }
1564            //
1565
// http://apache.org/xml/features/validation/validate-datatypes
1566
//
1567
if (feature.equals("validation/validate-datatypes")) {
1568                // REVISIT
1569
throw new SAXNotRecognizedException JavaDoc(featureId);
1570            }
1571            //
1572
// http://apache.org/xml/features/validation/warn-on-duplicate-attdef
1573
// Emits an error when an attribute is redefined.
1574
//
1575
if (feature.equals("validation/warn-on-duplicate-attdef")) {
1576                return getValidationWarnOnDuplicateAttdef();
1577            }
1578            //
1579
// http://apache.org/xml/features/validation/warn-on-undeclared-elemdef
1580
// Emits an error when an element's content model
1581
// references an element, by name, that is not declared
1582
// in the grammar.
1583
//
1584
if (feature.equals("validation/warn-on-undeclared-elemdef")) {
1585                return getValidationWarnOnUndeclaredElemdef();
1586            }
1587            //
1588
// http://apache.org/xml/features/allow-java-encodings
1589
// Allows the use of Java encoding names in the XML
1590
// and TextDecl lines.
1591
//
1592
if (feature.equals("allow-java-encodings")) {
1593                return getAllowJavaEncodings();
1594            }
1595            //
1596
// http://apache.org/xml/features/continue-after-fatal-error
1597
// Allows the parser to continue after a fatal error.
1598
// Normally, a fatal error would stop the parse.
1599
//
1600
if (feature.equals("continue-after-fatal-error")) {
1601                return getContinueAfterFatalError();
1602            }
1603            //
1604
// Not recognized
1605
//
1606
}
1607
1608        //
1609
// Not recognized
1610
//
1611

1612        throw new SAXNotRecognizedException JavaDoc(featureId);
1613
1614    } // getFeature(String):boolean
1615

1616    /**
1617     * Set the value of a property.
1618     *
1619     * Set the value of any property in a SAX2 parser. The parser
1620     * might not recognize the property, and if it does recognize
1621     * it, it might not support the requested value.
1622     *
1623     * @param propertyId The unique identifier (URI) of the property
1624     * being set.
1625     * @param Object The value to which the property is being set.
1626     * @exception org.xml.sax.SAXNotRecognizedException If the
1627     * requested property is not known.
1628     * @exception org.xml.sax.SAXNotSupportedException If the
1629     * requested property is known, but the requested
1630     * value is not supported.
1631     * @exception org.xml.sax.SAXException If there is any other
1632     * problem fulfilling the request.
1633     */

1634    public void setProperty(String JavaDoc propertyId, Object JavaDoc value)
1635        throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
1636
1637        //
1638
// SAX2 Properties
1639
//
1640
String JavaDoc property;
1641        if (propertyId.startsWith(SAX2_PROPERTIES_PREFIX)) {
1642            property = propertyId.substring(SAX2_PROPERTIES_PREFIX.length());
1643
1644            //
1645
// http://xml.org/sax/properties/namespace-sep
1646
// Value type: String
1647
// Access: read/write, pre-parse only
1648
// Set the separator to be used between the URI part of a name and the
1649
// local part of a name when namespace processing is being performed
1650
// (see the http://xml.org/sax/features/namespaces feature). By
1651
// default, the separator is a single space. This property may not be
1652
// set while a parse is in progress (throws a SAXNotSupportedException).
1653
//
1654
/***
1655            if (property.equals("namespace-sep")) {
1656                try {
1657                    setNamespaceSep((String)value);
1658                }
1659                catch (ClassCastException e) {
1660                    throw new SAXNotSupportedException(propertyId);
1661                }
1662                return;
1663            }
1664            /***/

1665
1666            //
1667
// http://xml.org/sax/properties/xml-string
1668
// Value type: String
1669
// Access: read-only
1670
// Get the literal string of characters associated with the current
1671
// event. If the parser recognises and supports this property but is
1672
// not currently parsing text, it should return null (this is a good
1673
// way to check for availability before the parse begins).
1674
//
1675
if (property.equals("xml-string")) {
1676                // REVISIT - we should probably ask xml-dev for a precise definition
1677
// of what this is actually supposed to return, and in exactly which
1678
// circumstances.
1679
throw new SAXNotSupportedException JavaDoc(propertyId);
1680            }
1681            //
1682
// Not recognized
1683
//
1684
}
1685
1686        //
1687
// Xerces Properties
1688
//
1689

1690
1691        if (propertyId.startsWith(XERCES_PROPERTIES_PREFIX)) {
1692            property = propertyId.substring(XERCES_PROPERTIES_PREFIX.length());
1693
1694            if (property.equals("schema/external-schemaLocation")) {
1695                setExternalSchemaLocation(value);
1696                return;
1697            }
1698            else if (property.equals("schema/external-noNamespaceSchemaLocation")) {
1699                setExternalNoNamespaceSchemaLocation(value);
1700                return;
1701            }
1702
1703
1704        }
1705
1706
1707        //
1708
// Not recognized
1709
//
1710

1711        throw new SAXNotRecognizedException JavaDoc(propertyId);
1712
1713    } // setProperty(String,Object)
1714

1715    /**
1716     * Query the value of a property.
1717     *
1718     * Return the current value of a property in a SAX2 parser.
1719     * The parser might not recognize the property.
1720     *
1721     * @param propertyId The unique identifier (URI) of the property
1722     * being set.
1723     * @return The current value of the property.
1724     * @exception org.xml.sax.SAXNotRecognizedException If the
1725     * requested property is not known.
1726     * @exception org.xml.sax.SAXException If there is any other
1727     * problem fulfilling the request.
1728     * @see org.xml.sax.XMLReader#getProperty
1729     */

1730    public Object JavaDoc getProperty(String JavaDoc propertyId)
1731        throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
1732
1733        //
1734
// SAX2 Properties
1735
//
1736

1737        if (propertyId.startsWith(SAX2_PROPERTIES_PREFIX)) {
1738            String JavaDoc property = propertyId.substring(SAX2_PROPERTIES_PREFIX.length());
1739            //
1740
// http://xml.org/sax/properties/namespace-sep
1741
// Value type: String
1742
// Access: read/write, pre-parse only
1743
// Set the separator to be used between the URI part of a name and the
1744
// local part of a name when namespace processing is being performed
1745
// (see the http://xml.org/sax/features/namespaces feature). By
1746
// default, the separator is a single space. This property may not be
1747
// set while a parse is in progress (throws a SAXNotSupportedException).
1748
//
1749
/***
1750            if (property.equals("namespace-sep")) {
1751                return getNamespaceSep();
1752            }
1753            /***/

1754            //
1755
// http://xml.org/sax/properties/xml-string
1756
// Value type: String
1757
// Access: read-only
1758
// Get the literal string of characters associated with the current
1759
// event. If the parser recognises and supports this property but is
1760
// not currently parsing text, it should return null (this is a good
1761
// way to check for availability before the parse begins).
1762
//
1763
if (property.equals("xml-string")) {
1764                return getXMLString();
1765            }
1766            //
1767
// Not recognized
1768
//
1769
}
1770
1771        //
1772
// Xerces Properties
1773
//
1774

1775
1776        else if (propertyId.startsWith(XERCES_PROPERTIES_PREFIX)) {
1777            //
1778
// No properties defined yet that are common to all parsers.
1779
//
1780

1781            String JavaDoc property = propertyId.substring(XERCES_PROPERTIES_PREFIX.length());
1782            //
1783
// http://apache.org/xml/features/validation/schema
1784
// Lets the user turn Schema validation support on/off.
1785
//
1786
if (property.equals("schema/external-schemaLocation")) {
1787                return fValidator.getExternalSchemas();
1788            }
1789            if (property.equals("schema/external-noNamespaceSchemaLocation")) {
1790                return fValidator.getExternalNoNamespaceSchema();
1791            }
1792        }
1793
1794
1795        //
1796
// Not recognized
1797
//
1798

1799        throw new SAXNotRecognizedException JavaDoc(propertyId);
1800
1801    } // getProperty(String):Object
1802

1803}
1804
Popular Tags