KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > dom > DOMConfigurationImpl


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001-2004 The Apache Software Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Xerces" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 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 com.sun.org.apache.xerces.internal.dom;
59
60 import java.io.IOException JavaDoc;
61 import java.util.ArrayList JavaDoc;
62 import java.util.HashMap JavaDoc;
63 import java.util.Locale JavaDoc;
64 import java.util.Vector JavaDoc;
65
66 import org.w3c.dom.DOMConfiguration JavaDoc;
67 import org.w3c.dom.DOMErrorHandler JavaDoc;
68 import org.w3c.dom.DOMStringList JavaDoc;
69
70 import com.sun.org.apache.xerces.internal.impl.Constants;
71 import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;
72 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
73 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
74 import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
75 import com.sun.org.apache.xerces.internal.util.DOMEntityResolverWrapper;
76 import com.sun.org.apache.xerces.internal.util.DOMErrorHandlerWrapper;
77 import com.sun.org.apache.xerces.internal.util.MessageFormatter;
78 import com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings;
79 import com.sun.org.apache.xerces.internal.util.SymbolTable;
80 import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler;
81 import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler;
82 import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler;
83 import com.sun.org.apache.xerces.internal.xni.XNIException;
84 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;
85 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;
86 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
87 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
88 import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver;
89 import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler;
90 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
91 import com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration;
92 import org.w3c.dom.DOMException JavaDoc;
93 import org.w3c.dom.ls.LSResourceResolver JavaDoc;
94 import com.sun.org.apache.xerces.internal.impl.dv.DTDDVFactory;
95
96
97 /**
98  * Xerces implementation of DOMConfiguration that maintains a table of recognized parameters.
99  *
100  * @author Elena Litani, IBM
101  * @author Neeraj Bajaj, Sun Microsystems.
102  * @version $Id: DOMConfigurationImpl.java,v 1.28 2004/04/14 15:54:06 mrglavas Exp $
103  */

104 public class DOMConfigurationImpl extends ParserConfigurationSettings
105     implements XMLParserConfiguration, DOMConfiguration JavaDoc {
106
107     //
108
// Constants
109
//
110

111     // feature identifiers
112

113     /** Feature identifier: validation. */
114     protected static final String JavaDoc XERCES_VALIDATION =
115         Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;
116
117     /** Feature identifier: namespaces. */
118     protected static final String JavaDoc XERCES_NAMESPACES =
119         Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;
120
121     protected static final String JavaDoc SCHEMA =
122         Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE;
123
124     protected static final String JavaDoc DYNAMIC_VALIDATION =
125         Constants.XERCES_FEATURE_PREFIX + Constants.DYNAMIC_VALIDATION_FEATURE;
126
127     protected static final String JavaDoc NORMALIZE_DATA =
128         Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE;
129     protected static final String JavaDoc DATATYPE_VALIDATOR_FACTORY =
130         Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY;
131
132     /** sending psvi in the pipeline */
133     protected static final String JavaDoc SEND_PSVI =
134         Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI;
135
136
137     // property identifiers
138

139     /** Property identifier: entity manager. */
140     protected static final String JavaDoc ENTITY_MANAGER =
141         Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;
142
143     /** Property identifier: error reporter. */
144     protected static final String JavaDoc ERROR_REPORTER =
145         Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
146
147     /** Property identifier: xml string. */
148     protected static final String JavaDoc XML_STRING =
149         Constants.SAX_PROPERTY_PREFIX + Constants.XML_STRING_PROPERTY;
150
151     /** Property identifier: symbol table. */
152     protected static final String JavaDoc SYMBOL_TABLE =
153         Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY;
154
155     /** Property id: Grammar pool*/
156     protected static final String JavaDoc GRAMMAR_POOL =
157     Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY;
158
159     /** Property identifier: error handler. */
160     protected static final String JavaDoc ERROR_HANDLER =
161         Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY;
162
163     /** Property identifier: entity resolver. */
164     protected static final String JavaDoc ENTITY_RESOLVER =
165         Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
166
167     /** Property identifier: JAXP schema language / DOM schema-type. */
168     protected static final String JavaDoc JAXP_SCHEMA_LANGUAGE =
169     Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE;
170
171     /** Property identifier: JAXP schema source/ DOM schema-location. */
172     protected static final String JavaDoc JAXP_SCHEMA_SOURCE =
173     Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE;
174
175     protected static final String JavaDoc VALIDATION_MANAGER =
176         Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
177     //
178
// Data
179
//
180
XMLDocumentHandler fDocumentHandler;
181
182     /** Normalization features*/
183     protected short features = 0;
184
185     protected final static short NAMESPACES = 0x1<<0;
186     protected final static short DTNORMALIZATION = 0x1<<1;
187     protected final static short ENTITIES = 0x1<<2;
188     protected final static short CDATA = 0x1<<3;
189     protected final static short SPLITCDATA = 0x1<<4;
190     protected final static short COMMENTS = 0x1<<5;
191     protected final static short VALIDATE = 0x1<<6;
192     protected final static short PSVI = 0x1<<7;
193     protected final static short WELLFORMED = 0x1<<8;
194
195     protected final static short INFOSET_TRUE_PARAMS = NAMESPACES | COMMENTS | WELLFORMED;
196     protected final static short INFOSET_FALSE_PARAMS = ENTITIES | DTNORMALIZATION | CDATA;
197     protected final static short INFOSET_MASK = INFOSET_TRUE_PARAMS | INFOSET_FALSE_PARAMS;
198
199     // components
200

201     /** Symbol table. */
202     protected SymbolTable fSymbolTable;
203
204     protected DTDDVFactory fDatatypeValidatorFactory;
205     /** Components. */
206     protected ArrayList JavaDoc fComponents;
207
208     protected ValidationManager fValidationManager;
209
210     /** Locale. */
211     protected Locale JavaDoc fLocale;
212
213     /** Error reporter */
214     protected XMLErrorReporter fErrorReporter;
215
216     protected final DOMErrorHandlerWrapper fErrorHandlerWrapper =
217                 new DOMErrorHandlerWrapper();
218
219     // private data
220

221     private DOMStringList JavaDoc fRecognizedParameters;
222
223
224     //
225
// Constructors
226
//
227

228     /** Default Constructor. */
229     protected DOMConfigurationImpl() {
230         this(null, null);
231     } // <init>()
232

233     /**
234      * Constructs a parser configuration using the specified symbol table.
235      *
236      * @param symbolTable The symbol table to use.
237      */

238     protected DOMConfigurationImpl(SymbolTable symbolTable) {
239         this(symbolTable, null);
240     } // <init>(SymbolTable)
241

242     /**
243      * Constructs a parser configuration using the specified symbol table
244      * and parent settings.
245      *
246      * @param symbolTable The symbol table to use.
247      * @param parentSettings The parent settings.
248      */

249     protected DOMConfigurationImpl(SymbolTable symbolTable,
250                                     XMLComponentManager parentSettings) {
251         super(parentSettings);
252
253         // create storage for recognized features and properties
254
fRecognizedFeatures = new ArrayList JavaDoc();
255         fRecognizedProperties = new ArrayList JavaDoc();
256
257         // create table for features and properties
258
fFeatures = new HashMap JavaDoc();
259         fProperties = new HashMap JavaDoc();
260
261         // add default recognized features
262
final String JavaDoc[] recognizedFeatures = {
263             XERCES_VALIDATION,
264             XERCES_NAMESPACES,
265             SCHEMA,
266             DYNAMIC_VALIDATION,
267             NORMALIZE_DATA,
268             SEND_PSVI,
269         };
270         addRecognizedFeatures(recognizedFeatures);
271
272         // set state for default features
273
setFeature(XERCES_VALIDATION, false);
274         setFeature(SCHEMA, false);
275         setFeature(DYNAMIC_VALIDATION, false);
276         setFeature(NORMALIZE_DATA, false);
277         setFeature(XERCES_NAMESPACES, true);
278         setFeature(SEND_PSVI, true);
279
280         // add default recognized properties
281
final String JavaDoc[] recognizedProperties = {
282             XML_STRING,
283             SYMBOL_TABLE,
284             ERROR_HANDLER,
285             ENTITY_RESOLVER,
286             ERROR_REPORTER,
287             ENTITY_MANAGER,
288             VALIDATION_MANAGER,
289             DATATYPE_VALIDATOR_FACTORY,
290             GRAMMAR_POOL,
291             JAXP_SCHEMA_SOURCE,
292             JAXP_SCHEMA_LANGUAGE
293         };
294         addRecognizedProperties(recognizedProperties);
295
296         // set default values for normalization features
297
features |= NAMESPACES;
298         features |= ENTITIES;
299         features |= COMMENTS;
300         features |= CDATA;
301         features |= SPLITCDATA;
302         features |= WELLFORMED;
303
304         if (symbolTable == null) {
305             symbolTable = new SymbolTable();
306         }
307         fSymbolTable = symbolTable;
308
309         fComponents = new ArrayList JavaDoc();
310
311         setProperty(SYMBOL_TABLE, fSymbolTable);
312         fErrorReporter = new XMLErrorReporter();
313         setProperty(ERROR_REPORTER, fErrorReporter);
314         addComponent(fErrorReporter);
315
316         XMLEntityManager manager = new XMLEntityManager();
317         setProperty(ENTITY_MANAGER, manager);
318         addComponent(manager);
319
320         fValidationManager = createValidationManager();
321         setProperty(VALIDATION_MANAGER, fValidationManager);
322
323         fDatatypeValidatorFactory = createDatatypeValidatorFactory();
324         if (fDatatypeValidatorFactory != null) {
325             setProperty(DATATYPE_VALIDATOR_FACTORY,
326                         fDatatypeValidatorFactory);
327         }
328
329         // add message formatters
330
if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
331             XMLMessageFormatter xmft = new XMLMessageFormatter();
332             fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
333             fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
334         }
335
336         // REVISIT: try to include XML Schema formatter.
337
// This is a hack to allow DTD configuration to be build.
338
//
339
if (fErrorReporter.getMessageFormatter("http://www.w3.org/TR/xml-schema-1") == null) {
340             MessageFormatter xmft = null;
341             try {
342                xmft = (MessageFormatter)(
343                     ObjectFactory.newInstance("com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter",
344                     ObjectFactory.findClassLoader(), true));
345             } catch (Exception JavaDoc exception){
346             }
347
348              if (xmft != null) {
349                  fErrorReporter.putMessageFormatter("http://www.w3.org/TR/xml-schema-1", xmft);
350              }
351         }
352
353
354         // set locale
355
try {
356             setLocale(Locale.getDefault());
357         }
358         catch (XNIException e) {
359             // do nothing
360
// REVISIT: What is the right thing to do? -Ac
361
}
362
363
364     } // <init>(SymbolTable)
365

366
367     //
368
// XMLParserConfiguration methods
369
//
370

371     /**
372      * Parse an XML document.
373      * <p>
374      * The parser can use this method to instruct this configuration
375      * to begin parsing an XML document from any valid input source
376      * (a character stream, a byte stream, or a URI).
377      * <p>
378      * Parsers may not invoke this method while a parse is in progress.
379      * Once a parse is complete, the parser may then parse another XML
380      * document.
381      * <p>
382      * This method is synchronous: it will not return until parsing
383      * has ended. If a client application wants to terminate
384      * parsing early, it should throw an exception.
385      *
386      * @param source The input source for the top-level of the
387      * XML document.
388      *
389      * @exception XNIException Any XNI exception, possibly wrapping
390      * another exception.
391      * @exception IOException An IO exception from the parser, possibly
392      * from a byte stream or character stream
393      * supplied by the parser.
394      */

395     public void parse(XMLInputSource inputSource)
396         throws XNIException, IOException JavaDoc{
397         // no-op
398
}
399
400     /**
401      * Sets the document handler on the last component in the pipeline
402      * to receive information about the document.
403      *
404      * @param documentHandler The document handler.
405      */

406     public void setDocumentHandler(XMLDocumentHandler documentHandler) {
407         fDocumentHandler = documentHandler;
408     } // setDocumentHandler(XMLDocumentHandler)
409

410     /** Returns the registered document handler. */
411     public XMLDocumentHandler getDocumentHandler() {
412         return fDocumentHandler;
413     } // getDocumentHandler():XMLDocumentHandler
414

415     /**
416      * Sets the DTD handler.
417      *
418      * @param dtdHandler The DTD handler.
419      */

420     public void setDTDHandler(XMLDTDHandler dtdHandler) {
421         //no-op
422
} // setDTDHandler(XMLDTDHandler)
423

424     /** Returns the registered DTD handler. */
425     public XMLDTDHandler getDTDHandler() {
426         return null;
427     } // getDTDHandler():XMLDTDHandler
428

429     /**
430      * Sets the DTD content model handler.
431      *
432      * @param handler The DTD content model handler.
433      */

434     public void setDTDContentModelHandler(XMLDTDContentModelHandler handler) {
435         //no-op
436

437     } // setDTDContentModelHandler(XMLDTDContentModelHandler)
438

439     /** Returns the registered DTD content model handler. */
440     public XMLDTDContentModelHandler getDTDContentModelHandler() {
441         return null;
442     } // getDTDContentModelHandler():XMLDTDContentModelHandler
443

444     /**
445      * Sets the resolver used to resolve external entities. The EntityResolver
446      * interface supports resolution of public and system identifiers.
447      *
448      * @param resolver The new entity resolver. Passing a null value will
449      * uninstall the currently installed resolver.
450      */

451     public void setEntityResolver(XMLEntityResolver resolver) {
452         if (resolver !=null) {
453             fProperties.put(ENTITY_RESOLVER, resolver);
454         }
455     } // setEntityResolver(XMLEntityResolver)
456

457     /**
458      * Return the current entity resolver.
459      *
460      * @return The current entity resolver, or null if none
461      * has been registered.
462      * @see #setEntityResolver
463      */

464     public XMLEntityResolver getEntityResolver() {
465         return (XMLEntityResolver)fProperties.get(ENTITY_RESOLVER);
466     } // getEntityResolver():XMLEntityResolver
467

468     /**
469      * Allow an application to register an error event handler.
470      *
471      * <p>If the application does not register an error handler, all
472      * error events reported by the SAX parser will be silently
473      * ignored; however, normal processing may not continue. It is
474      * highly recommended that all SAX applications implement an
475      * error handler to avoid unexpected bugs.</p>
476      *
477      * <p>Applications may register a new or different handler in the
478      * middle of a parse, and the SAX parser must begin using the new
479      * handler immediately.</p>
480      *
481      * @param errorHandler The error handler.
482      * @exception java.lang.NullPointerException If the handler
483      * argument is null.
484      * @see #getErrorHandler
485      */

486     public void setErrorHandler(XMLErrorHandler errorHandler) {
487         if (errorHandler != null) {
488             fProperties.put(ERROR_HANDLER, errorHandler);
489         }
490     } // setErrorHandler(XMLErrorHandler)
491

492     /**
493      * Return the current error handler.
494      *
495      * @return The current error handler, or null if none
496      * has been registered.
497      * @see #setErrorHandler
498      */

499     public XMLErrorHandler getErrorHandler() {
500         return (XMLErrorHandler)fProperties.get(ERROR_HANDLER);
501     } // getErrorHandler():XMLErrorHandler
502

503     /**
504      * Set the state of a feature.
505      *
506      * Set the state of any feature in a SAX2 parser. The parser
507      * might not recognize the feature, and if it does recognize
508      * it, it might not be able to fulfill the request.
509      *
510      * @param featureId The unique identifier (URI) of the feature.
511      * @param state The requested state of the feature (true or false).
512      *
513      * @exception com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException If the
514      * requested feature is not known.
515      */

516     public void setFeature(String JavaDoc featureId, boolean state)
517         throws XMLConfigurationException {
518
519         // save state if noone "objects"
520
super.setFeature(featureId, state);
521
522     } // setFeature(String,boolean)
523

524     /**
525      * setProperty
526      *
527      * @param propertyId
528      * @param value
529      */

530     public void setProperty(String JavaDoc propertyId, Object JavaDoc value)
531         throws XMLConfigurationException {
532
533         // store value if noone "objects"
534
super.setProperty(propertyId, value);
535
536     } // setProperty(String,Object)
537

538     /**
539      * Set the locale to use for messages.
540      *
541      * @param locale The locale object to use for localization of messages.
542      *
543      * @exception XNIException Thrown if the parser does not support the
544      * specified locale.
545      */

546     public void setLocale(Locale JavaDoc locale) throws XNIException {
547         fLocale = locale;
548         fErrorReporter.setLocale(locale);
549
550     } // setLocale(Locale)
551

552     /** Returns the locale. */
553     public Locale JavaDoc getLocale() {
554         return fLocale;
555     } // getLocale():Locale
556

557     /**
558      * DOM Level 3 WD - Experimental.
559      * setParameter
560      */

561     public void setParameter(String JavaDoc name, Object JavaDoc value) throws DOMException JavaDoc {
562
563         // REVISIT: Recognizes DOM L3 default features only.
564
// Does not yet recognize Xerces features.
565
if(value instanceof Boolean JavaDoc){
566             boolean state = ((Boolean JavaDoc)value).booleanValue();
567
568             if (name.equalsIgnoreCase(Constants.DOM_COMMENTS)) {
569                 features = (short) (state ? features | COMMENTS : features & ~COMMENTS);
570             }
571             else if (name.equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION)) {
572                 setFeature(NORMALIZE_DATA, state);
573                 features =
574                     (short) (state ? features | DTNORMALIZATION : features & ~DTNORMALIZATION);
575                 if (state) {
576                     features = (short) (features | VALIDATE);
577                 }
578             }
579             else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACES)) {
580                 features = (short) (state ? features | NAMESPACES : features & ~NAMESPACES);
581             }
582             else if (name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)) {
583                 features = (short) (state ? features | CDATA : features & ~CDATA);
584             }
585             else if (name.equalsIgnoreCase(Constants.DOM_ENTITIES)) {
586                 features = (short) (state ? features | ENTITIES : features & ~ENTITIES);
587             }
588             else if (name.equalsIgnoreCase(Constants.DOM_SPLIT_CDATA)) {
589                 features = (short) (state ? features | SPLITCDATA : features & ~SPLITCDATA);
590             }
591             else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE)) {
592                 features = (short) (state ? features | VALIDATE : features & ~VALIDATE);
593             }
594             else if (name.equalsIgnoreCase(Constants.DOM_WELLFORMED)) {
595                 features = (short) (state ? features | WELLFORMED : features & ~WELLFORMED );
596             }
597             else if (name.equalsIgnoreCase(Constants.DOM_INFOSET)) {
598                 // Setting to false has no effect.
599
if (state) {
600                     features = (short) (features | INFOSET_TRUE_PARAMS);
601                     features = (short) (features & ~INFOSET_FALSE_PARAMS);
602                     setFeature(NORMALIZE_DATA, false);
603                 }
604             }
605             else if (name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS)
606                     || name.equalsIgnoreCase(Constants.DOM_CANONICAL_FORM)
607                     || name.equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA)
608                     || name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION)
609                     ) {
610                 if (state) { // true is not supported
611
String JavaDoc msg =
612                         DOMMessageFormatter.formatMessage(
613                             DOMMessageFormatter.DOM_DOMAIN,
614                             "FEATURE_NOT_SUPPORTED",
615                             new Object JavaDoc[] { name });
616                     throw new DOMException JavaDoc(DOMException.NOT_SUPPORTED_ERR, msg);
617                 }
618             }
619             else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS)
620                     || name.equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE)) {
621                 if (!state) { // false is not supported
622
String JavaDoc msg =
623                         DOMMessageFormatter.formatMessage(
624                             DOMMessageFormatter.DOM_DOMAIN,
625                             "FEATURE_NOT_SUPPORTED",
626                             new Object JavaDoc[] { name });
627                    throw new DOMException JavaDoc(DOMException.NOT_SUPPORTED_ERR, msg);
628                 }
629
630             }
631             else if (name.equalsIgnoreCase(SEND_PSVI) ){
632                 // REVISIT: turning augmentation of PSVI is not support,
633
// because in this case we won't be able to retrieve element
634
// default value.
635
if (!state) { // false is not supported
636
String JavaDoc msg =
637                         DOMMessageFormatter.formatMessage(
638                             DOMMessageFormatter.DOM_DOMAIN,
639                             "FEATURE_NOT_SUPPORTED",
640                             new Object JavaDoc[] { name });
641                     throw new DOMException JavaDoc(DOMException.NOT_SUPPORTED_ERR, msg);
642                 }
643             }
644             else if (name.equalsIgnoreCase(Constants.DOM_PSVI)){
645                   features = (short) (state ? features | PSVI : features & ~PSVI);
646             }
647             else {
648                 String JavaDoc msg =
649                     DOMMessageFormatter.formatMessage(
650                         DOMMessageFormatter.DOM_DOMAIN,
651                         "FEATURE_NOT_FOUND",
652                         new Object JavaDoc[] { name });
653                 throw new DOMException JavaDoc(DOMException.NOT_FOUND_ERR, msg);
654             }
655         }
656         else { // set properties
657
if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) {
658                 if (value instanceof DOMErrorHandler JavaDoc || value == null) {
659                     fErrorHandlerWrapper.setErrorHandler((DOMErrorHandler JavaDoc)value);
660                     setErrorHandler(fErrorHandlerWrapper);
661                 }
662
663                 else {
664                     // REVISIT: type mismatch
665
String JavaDoc msg =
666                         DOMMessageFormatter.formatMessage(
667                             DOMMessageFormatter.DOM_DOMAIN,
668                             "TYPE_MISMATCH_ERR",
669                             new Object JavaDoc[] { name });
670                     throw new DOMException JavaDoc(DOMException.NOT_SUPPORTED_ERR, msg);
671                 }
672             }
673             else if (name.equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) {
674                 if (value instanceof LSResourceResolver JavaDoc || value == null) {
675                     try {
676                         setEntityResolver(new DOMEntityResolverWrapper((LSResourceResolver JavaDoc) value));
677                     }
678                     catch (XMLConfigurationException e) {}
679                 }
680                 else {
681                     // REVISIT: type mismatch
682
String JavaDoc msg =
683                         DOMMessageFormatter.formatMessage(
684                             DOMMessageFormatter.DOM_DOMAIN,
685                             "TYPE_MISMATCH_ERR",
686                             new Object JavaDoc[] { name });
687                     throw new DOMException JavaDoc(DOMException.NOT_SUPPORTED_ERR, msg);
688                 }
689
690             }
691             else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) {
692                 if (value instanceof String JavaDoc || value == null) {
693                     try {
694                         String JavaDoc schemaType = (String JavaDoc) getProperty(
695                         Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE);
696                         if (schemaType == Constants.NS_XMLSCHEMA || value == null) {
697                             // map DOM schema-location to JAXP schemaSource property
698
setProperty(
699                                 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE,
700                                 value);
701                         }
702                         else {
703                             // schemaType must not be null.
704
// REVISIT: allow pre-parsing DTD grammars
705
String JavaDoc msg =
706                                 DOMMessageFormatter.formatMessage(
707                                     DOMMessageFormatter.DOM_DOMAIN,
708                                     "FEATURE_NOT_SUPPORTED",
709                                     new Object JavaDoc[] { name });
710                             throw new DOMException JavaDoc(DOMException.NOT_SUPPORTED_ERR, msg);
711                         }
712
713                     }
714                     catch (XMLConfigurationException e) {}
715                 }
716                 else {
717                     // REVISIT: type mismatch
718
String JavaDoc msg =
719                         DOMMessageFormatter.formatMessage(
720                             DOMMessageFormatter.DOM_DOMAIN,
721                             "TYPE_MISMATCH_ERR",
722                             new Object JavaDoc[] { name });
723                     throw new DOMException JavaDoc(DOMException.NOT_SUPPORTED_ERR, msg);
724                 }
725
726             }
727             else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) {
728                 if (value instanceof String JavaDoc || value == null) {
729                     try {
730                         if (value == null) {
731                             setProperty(
732                                 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE,
733                                 null);
734                         }
735                         else if (value.equals(Constants.NS_XMLSCHEMA)) {
736                             // REVISIT: when add support to DTD validation
737
setProperty(
738                                 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE,
739                                 Constants.NS_XMLSCHEMA);
740                         }
741                         else if (value.equals(Constants.NS_DTD)) {
742                             // REVISIT: revalidation against DTDs is not supported
743
String JavaDoc msg = DOMMessageFormatter.formatMessage(
744                             DOMMessageFormatter.DOM_DOMAIN,
745                             "FEATURE_NOT_SUPPORTED",
746                             new Object JavaDoc[] { name });
747                             throw new DOMException JavaDoc(DOMException.NOT_SUPPORTED_ERR, msg);
748                         }
749                     }
750                     catch (XMLConfigurationException e) {}
751                 }
752                 else {
753                     String JavaDoc msg =
754                         DOMMessageFormatter.formatMessage(
755                             DOMMessageFormatter.DOM_DOMAIN,
756                             "TYPE_MISMATCH_ERR",
757                             new Object JavaDoc[] { name });
758                     throw new DOMException JavaDoc(DOMException.NOT_SUPPORTED_ERR, msg);
759                 }
760
761             }
762             else if (name.equalsIgnoreCase(SYMBOL_TABLE)){
763                 // Xerces Symbol Table
764
if (value instanceof SymbolTable){
765                     setProperty(SYMBOL_TABLE, value);
766                 }
767                 else {
768                     // REVISIT: type mismatch
769
String JavaDoc msg =
770                         DOMMessageFormatter.formatMessage(
771                             DOMMessageFormatter.DOM_DOMAIN,
772                             "TYPE_MISMATCH_ERR",
773                             new Object JavaDoc[] { name });
774                     throw new DOMException JavaDoc(DOMException.NOT_SUPPORTED_ERR, msg);
775                 }
776             }
777             else if (name.equalsIgnoreCase (GRAMMAR_POOL)){
778                 if (value instanceof XMLGrammarPool){
779                     setProperty(GRAMMAR_POOL, value);
780                 }
781                 else {
782                     // REVISIT: type mismatch
783
String JavaDoc msg =
784                         DOMMessageFormatter.formatMessage(
785                             DOMMessageFormatter.DOM_DOMAIN,
786                             "TYPE_MISMATCH_ERR",
787                             new Object JavaDoc[] { name });
788                     throw new DOMException JavaDoc(DOMException.NOT_SUPPORTED_ERR, msg);
789                 }
790
791             }
792             else {
793                 // REVISIT: check if this is a boolean parameter -- type mismatch should be thrown.
794
//parameter is not recognized
795
String JavaDoc msg =
796                     DOMMessageFormatter.formatMessage(
797                         DOMMessageFormatter.DOM_DOMAIN,
798                         "FEATURE_NOT_FOUND",
799                         new Object JavaDoc[] { name });
800                 throw new DOMException JavaDoc(DOMException.NOT_FOUND_ERR, msg);
801             }
802         }
803
804     }
805
806
807     /**
808      * DOM Level 3 WD - Experimental.
809      * getParameter
810      */

811     public Object JavaDoc getParameter(String JavaDoc name) throws DOMException JavaDoc {
812
813         // REVISIT: Recognizes DOM L3 default features only.
814
// Does not yet recognize Xerces features.
815

816         if (name.equalsIgnoreCase(Constants.DOM_COMMENTS)) {
817             return ((features & COMMENTS) != 0) ? Boolean.TRUE : Boolean.FALSE;
818         }
819         else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACES)) {
820             return (features & NAMESPACES) != 0 ? Boolean.TRUE : Boolean.FALSE;
821         }
822         else if (name.equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION)) {
823             // REVISIT: datatype-normalization only takes effect if validation is on
824
return (features & DTNORMALIZATION) != 0 ? Boolean.TRUE : Boolean.FALSE;
825         }
826         else if (name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)) {
827             return (features & CDATA) != 0 ? Boolean.TRUE : Boolean.FALSE;
828         }
829         else if (name.equalsIgnoreCase(Constants.DOM_ENTITIES)) {
830             return (features & ENTITIES) != 0 ? Boolean.TRUE : Boolean.FALSE;
831         }
832         else if (name.equalsIgnoreCase(Constants.DOM_SPLIT_CDATA)) {
833             return (features & SPLITCDATA) != 0 ? Boolean.TRUE : Boolean.FALSE;
834         }
835         else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE)) {
836             return (features & VALIDATE) != 0 ? Boolean.TRUE : Boolean.FALSE;
837         }
838         else if (name.equalsIgnoreCase(Constants.DOM_WELLFORMED)) {
839             return (features & WELLFORMED) != 0 ? Boolean.TRUE : Boolean.FALSE;
840         }
841         else if (name.equalsIgnoreCase(Constants.DOM_INFOSET)) {
842             return (features & INFOSET_MASK) == INFOSET_TRUE_PARAMS ? Boolean.TRUE : Boolean.FALSE;
843         }
844         else if (name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS)
845                 || name.equalsIgnoreCase(Constants.DOM_CANONICAL_FORM)
846                 || name.equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA)
847                 || name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION)
848                 ) {
849             return Boolean.FALSE;
850         }
851         else if (name.equalsIgnoreCase(SEND_PSVI)) {
852             return Boolean.TRUE;
853         }
854         else if (name.equalsIgnoreCase(Constants.DOM_PSVI)) {
855             return (features & PSVI) != 0 ? Boolean.TRUE : Boolean.FALSE;
856         }
857         else if (
858             name.equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS)
859                 || name.equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE)) {
860             return Boolean.TRUE;
861         }
862         else if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) {
863             return fErrorHandlerWrapper.getErrorHandler();
864         }
865         else if (name.equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) {
866             XMLEntityResolver entityResolver = getEntityResolver();
867             if (entityResolver != null && entityResolver instanceof DOMEntityResolverWrapper) {
868                 return ((DOMEntityResolverWrapper) entityResolver).getEntityResolver();
869             }
870             return null;
871         }
872         else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) {
873             return getProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE);
874         }
875         else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) {
876             return getProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE);
877         }
878         else if (name.equalsIgnoreCase(SYMBOL_TABLE)){
879             return getProperty(SYMBOL_TABLE);
880         }
881         else if (name.equalsIgnoreCase(GRAMMAR_POOL)){
882             return getProperty(GRAMMAR_POOL);
883         }
884         else {
885             String JavaDoc msg =
886                 DOMMessageFormatter.formatMessage(
887                     DOMMessageFormatter.DOM_DOMAIN,
888                     "FEATURE_NOT_FOUND",
889                     new Object JavaDoc[] { name });
890             throw new DOMException JavaDoc(DOMException.NOT_FOUND_ERR, msg);
891         }
892
893     }
894
895     /**
896      * DOM Level 3 WD - Experimental.
897      * Check if setting a parameter to a specific value is supported.
898      *
899      * @param name The name of the parameter to check.
900      *
901      * @param value An object. if null, the returned value is true.
902      *
903      * @return true if the parameter could be successfully set to the
904      * specified value, or false if the parameter is not recognized or
905      * the requested value is not supported. This does not change the
906      * current value of the parameter itself.
907      */

908     public boolean canSetParameter(String JavaDoc name, Object JavaDoc value) {
909
910         if (value == null){
911             //if null, the returned value is true.
912
//REVISIT: I dont like this --- even for unrecognized parameter it would
913
//return 'true'. I think it should return false in that case.
914
// Application will be surprised to find that setParameter throws not
915
//recognized exception when canSetParameter returns 'true' Then what is the use
916
//of having canSetParameter ??? - nb.
917
return true ;
918         }
919         if( value instanceof Boolean JavaDoc ){
920             //features whose parameter value can be set either 'true' or 'false'
921
// or they accept any boolean value -- so we just need to check that
922
// its a boolean value..
923
if (name.equalsIgnoreCase(Constants.DOM_COMMENTS)
924                 || name.equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION)
925                 || name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)
926                 || name.equalsIgnoreCase(Constants.DOM_ENTITIES)
927                 || name.equalsIgnoreCase(Constants.DOM_SPLIT_CDATA)
928                 || name.equalsIgnoreCase(Constants.DOM_NAMESPACES)
929                 || name.equalsIgnoreCase(Constants.DOM_VALIDATE)
930                 || name.equalsIgnoreCase(Constants.DOM_WELLFORMED)
931                 || name.equalsIgnoreCase(Constants.DOM_INFOSET)
932                 ) {
933                 return true ;
934             }//features whose parameter value can not be set to 'true'
935
else if (
936                 name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS)
937                     || name.equalsIgnoreCase(Constants.DOM_CANONICAL_FORM)
938                     || name.equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA)
939                     || name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION)
940                     ) {
941                     return (value.equals(Boolean.TRUE)) ? false : true;
942             }//features whose parameter value can not be set to 'false'
943
else if( name.equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS)
944                     || name.equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE)
945                     || name.equalsIgnoreCase(SEND_PSVI)
946                     ) {
947                     return (value.equals(Boolean.TRUE)) ? true : false;
948             }// if name is not among the above listed above -- its not recognized. return false
949
else {
950                 return false ;
951             }
952         }
953         else if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) {
954             return (value instanceof DOMErrorHandler JavaDoc) ? true : false ;
955         }
956         else if (name.equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) {
957             return (value instanceof LSResourceResolver JavaDoc) ? true : false ;
958         }
959         else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) {
960             return (value instanceof String JavaDoc) ? true : false ;
961         }
962         else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) {
963             // REVISIT: should null value be supported?
964
//as of now we are only supporting W3C XML Schema
965
return ( (value instanceof String JavaDoc) && value.equals(Constants.NS_XMLSCHEMA) ) ? true : false ;
966         }
967         else if (name.equalsIgnoreCase(SYMBOL_TABLE)){
968             // Xerces Symbol Table
969
return (value instanceof SymbolTable) ? true : false ;
970         }
971         else if (name.equalsIgnoreCase (GRAMMAR_POOL)){
972             return (value instanceof XMLGrammarPool) ? true : false ;
973         }
974         else {
975             //false if the parameter is not recognized or the requested value is not supported.
976
return false ;
977         }
978
979     } //canSetParameter
980

981     /**
982      * DOM Level 3 CR - Experimental.
983      *
984      * The list of the parameters supported by this
985      * <code>DOMConfiguration</code> object and for which at least one value
986      * can be set by the application. Note that this list can also contain
987      * parameter names defined outside this specification.
988      */

989     public DOMStringList JavaDoc getParameterNames() {
990         if (fRecognizedParameters == null){
991             Vector JavaDoc parameters = new Vector JavaDoc();
992
993             //Add DOM recognized parameters
994
//REVISIT: Would have been nice to have a list of
995
//recognized paramters.
996
parameters.add(Constants.DOM_COMMENTS);
997             parameters.add(Constants.DOM_DATATYPE_NORMALIZATION);
998             parameters.add(Constants.DOM_CDATA_SECTIONS);
999             parameters.add(Constants.DOM_ENTITIES);
1000            parameters.add(Constants.DOM_SPLIT_CDATA);
1001            parameters.add(Constants.DOM_NAMESPACES);
1002            parameters.add(Constants.DOM_VALIDATE);
1003
1004            parameters.add(Constants.DOM_INFOSET);
1005            parameters.add(Constants.DOM_NORMALIZE_CHARACTERS);
1006            parameters.add(Constants.DOM_CANONICAL_FORM);
1007            parameters.add(Constants.DOM_VALIDATE_IF_SCHEMA);
1008            parameters.add(Constants.DOM_CHECK_CHAR_NORMALIZATION);
1009            parameters.add(Constants.DOM_WELLFORMED);
1010
1011            parameters.add(Constants.DOM_NAMESPACE_DECLARATIONS);
1012            parameters.add(Constants.DOM_ELEMENT_CONTENT_WHITESPACE);
1013
1014            parameters.add(Constants.DOM_ERROR_HANDLER);
1015            parameters.add(Constants.DOM_SCHEMA_TYPE);
1016            parameters.add(Constants.DOM_SCHEMA_LOCATION);
1017            parameters.add(Constants.DOM_RESOURCE_RESOLVER);
1018            parameters.add(GRAMMAR_POOL);
1019            parameters.add(SYMBOL_TABLE);
1020            parameters.add(SEND_PSVI);
1021
1022
1023            fRecognizedParameters = new DOMStringListImpl(parameters);
1024
1025        }
1026
1027        return fRecognizedParameters;
1028    }//getParameterNames
1029

1030    //
1031
// Protected methods
1032
//
1033

1034    /**
1035     * reset all components before parsing
1036     */

1037    protected void reset() throws XNIException {
1038
1039        if (fValidationManager != null)
1040            fValidationManager.reset();
1041
1042        int count = fComponents.size();
1043        for (int i = 0; i < count; i++) {
1044            XMLComponent c = (XMLComponent) fComponents.get(i);
1045            c.reset(this);
1046        }
1047
1048    } // reset()
1049

1050    /**
1051     * Check a property. If the property is known and supported, this method
1052     * simply returns. Otherwise, the appropriate exception is thrown.
1053     *
1054     * @param propertyId The unique identifier (URI) of the property
1055     * being set.
1056     * @exception com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException If the
1057     * requested feature is not known or supported.
1058     */

1059    protected void checkProperty(String JavaDoc propertyId)
1060        throws XMLConfigurationException {
1061
1062        // special cases
1063
if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) {
1064            final int suffixLength = propertyId.length() - Constants.SAX_PROPERTY_PREFIX.length();
1065
1066            //
1067
// http://xml.org/sax/properties/xml-string
1068
// Value type: String
1069
// Access: read-only
1070
// Get the literal string of characters associated with the
1071
// current event. If the parser recognises and supports this
1072
// property but is not currently parsing text, it should return
1073
// null (this is a good way to check for availability before the
1074
// parse begins).
1075
//
1076
if (suffixLength == Constants.XML_STRING_PROPERTY.length() &&
1077                propertyId.endsWith(Constants.XML_STRING_PROPERTY)) {
1078                // REVISIT - we should probably ask xml-dev for a precise
1079
// definition of what this is actually supposed to return, and
1080
// in exactly which circumstances.
1081
short type = XMLConfigurationException.NOT_SUPPORTED;
1082                throw new XMLConfigurationException(type, propertyId);
1083            }
1084        }
1085
1086        // check property
1087
super.checkProperty(propertyId);
1088
1089    } // checkProperty(String)
1090

1091
1092    protected void addComponent(XMLComponent component) {
1093
1094        // don't add a component more than once
1095
if (fComponents.contains(component)) {
1096            return;
1097        }
1098        fComponents.add(component);
1099
1100        // register component's recognized features
1101
String JavaDoc[] recognizedFeatures = component.getRecognizedFeatures();
1102        addRecognizedFeatures(recognizedFeatures);
1103
1104        // register component's recognized properties
1105
String JavaDoc[] recognizedProperties = component.getRecognizedProperties();
1106        addRecognizedProperties(recognizedProperties);
1107
1108    } // addComponent(XMLComponent)
1109

1110    protected ValidationManager createValidationManager(){
1111        return new ValidationManager();
1112    }
1113    protected DTDDVFactory createDatatypeValidatorFactory() {
1114        return DTDDVFactory.getInstance();
1115    } // createDatatypeValidatorFactory():DatatypeValidatorFactory
1116

1117} // class XMLParser
1118
Popular Tags