KickJava   Java API By Example, From Geeks To Geeks.

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


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.parsers;
59
60 import java.io.IOException JavaDoc;
61 import java.util.Locale JavaDoc;
62
63 import com.sun.org.apache.xerces.internal.impl.Constants;
64 import com.sun.org.apache.xerces.internal.xs.PSVIProvider;
65 import com.sun.org.apache.xerces.internal.util.EntityResolverWrapper;
66 import com.sun.org.apache.xerces.internal.util.EntityResolver2Wrapper;
67 import com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper;
68 import com.sun.org.apache.xerces.internal.util.SAXMessageFormatter;
69 import com.sun.org.apache.xerces.internal.util.SymbolHash;
70 import com.sun.org.apache.xerces.internal.util.XMLSymbols;
71 import com.sun.org.apache.xerces.internal.xni.Augmentations;
72 import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
73 import com.sun.org.apache.xerces.internal.xni.QName;
74 import com.sun.org.apache.xerces.internal.xni.XMLAttributes;
75 import com.sun.org.apache.xerces.internal.xni.XMLLocator;
76 import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
77 import com.sun.org.apache.xerces.internal.xni.XMLString;
78 import com.sun.org.apache.xerces.internal.xni.XNIException;
79 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
80 import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver;
81 import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler;
82 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
83 import com.sun.org.apache.xerces.internal.xni.parser.XMLParseException;
84 import com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration;
85 import com.sun.org.apache.xerces.internal.xs.AttributePSVI;
86 import com.sun.org.apache.xerces.internal.xs.ElementPSVI;
87 import org.xml.sax.AttributeList JavaDoc;
88 import org.xml.sax.Attributes JavaDoc;
89 import org.xml.sax.ext.Attributes2 JavaDoc;
90 import org.xml.sax.ContentHandler JavaDoc;
91 import org.xml.sax.DTDHandler JavaDoc;
92 import org.xml.sax.DocumentHandler JavaDoc;
93 import org.xml.sax.EntityResolver JavaDoc;
94 import org.xml.sax.ErrorHandler JavaDoc;
95 import org.xml.sax.InputSource JavaDoc;
96 import org.xml.sax.Locator JavaDoc;
97 import org.xml.sax.ext.Locator2Impl JavaDoc;
98 import org.xml.sax.ext.Locator2 JavaDoc;
99 import org.xml.sax.Parser JavaDoc;
100 import org.xml.sax.SAXException JavaDoc;
101 import org.xml.sax.SAXNotRecognizedException JavaDoc;
102 import org.xml.sax.SAXNotSupportedException JavaDoc;
103 import org.xml.sax.SAXParseException JavaDoc;
104 import org.xml.sax.XMLReader JavaDoc;
105 import org.xml.sax.ext.DeclHandler JavaDoc;
106 import org.xml.sax.ext.EntityResolver2 JavaDoc;
107 import org.xml.sax.ext.LexicalHandler JavaDoc;
108 import org.xml.sax.helpers.LocatorImpl JavaDoc;
109
110 /**
111  * This is the base class of all SAX parsers. It implements both the
112  * SAX1 and SAX2 parser functionality, while the actual pipeline is
113  * defined in the parser configuration.
114  *
115  * @author Arnaud Le Hors, IBM
116  * @author Andy Clark, IBM
117  *
118  * @version $Id: AbstractSAXParser.java,v 1.54 2004/04/07 15:42:05 mrglavas Exp $
119  */

120 public abstract class AbstractSAXParser
121 extends AbstractXMLDocumentParser
122 implements PSVIProvider, // PSVI
123
Parser JavaDoc, XMLReader JavaDoc // SAX1, SAX2
124
{
125     
126     //
127
// Constants
128
//
129

130     // features
131

132     /** Feature identifier: namespaces. */
133     protected static final String JavaDoc NAMESPACES =
134     Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;
135     
136     /** Feature identifier: namespace prefixes. */
137     protected static final String JavaDoc NAMESPACE_PREFIXES =
138     Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACE_PREFIXES_FEATURE;
139     
140     /** Feature id: string interning. */
141     protected static final String JavaDoc STRING_INTERNING =
142     Constants.SAX_FEATURE_PREFIX + Constants.STRING_INTERNING_FEATURE;
143     
144     
145     /** Feature identifier: allow notation and unparsed entity events to be sent out of order. */
146     // this is not meant to be a recognized feature, but we need it here to use
147
// if it is already a recognized feature for the pipeline
148
protected static final String JavaDoc ALLOW_UE_AND_NOTATION_EVENTS =
149     Constants.SAX_FEATURE_PREFIX + Constants.ALLOW_DTD_EVENTS_AFTER_ENDDTD_FEATURE;
150     
151     /** Recognized features. */
152     private static final String JavaDoc[] RECOGNIZED_FEATURES = {
153         NAMESPACES,
154         NAMESPACE_PREFIXES,
155         STRING_INTERNING,
156     };
157     
158     // properties
159

160     /** Property id: lexical handler. */
161     protected static final String JavaDoc LEXICAL_HANDLER =
162     Constants.SAX_PROPERTY_PREFIX + Constants.LEXICAL_HANDLER_PROPERTY;
163     
164     /** Property id: declaration handler. */
165     protected static final String JavaDoc DECLARATION_HANDLER =
166     Constants.SAX_PROPERTY_PREFIX + Constants.DECLARATION_HANDLER_PROPERTY;
167     
168     /** Property id: DOM node. */
169     protected static final String JavaDoc DOM_NODE =
170     Constants.SAX_PROPERTY_PREFIX + Constants.DOM_NODE_PROPERTY;
171     
172     /** Recognized properties. */
173     private static final String JavaDoc[] RECOGNIZED_PROPERTIES = {
174         LEXICAL_HANDLER,
175         DECLARATION_HANDLER,
176         DOM_NODE,
177     };
178     
179     //
180
// Data
181
//
182

183     // features
184

185     /** Namespaces. */
186     protected boolean fNamespaces;
187     
188     /** Namespace prefixes. */
189     protected boolean fNamespacePrefixes = false;
190     
191     /** Lexical handler parameter entities. */
192     protected boolean fLexicalHandlerParameterEntities = true;
193     
194     // parser handlers
195

196     /** Content handler. */
197     protected ContentHandler JavaDoc fContentHandler;
198     
199     /** Document handler. */
200     protected DocumentHandler JavaDoc fDocumentHandler;
201     
202     /** Namespace context */
203     protected NamespaceContext fNamespaceContext;
204     
205     /** DTD handler. */
206     protected org.xml.sax.DTDHandler JavaDoc fDTDHandler;
207     
208     /** Decl handler. */
209     protected DeclHandler JavaDoc fDeclHandler;
210     
211     /** Lexical handler. */
212     protected LexicalHandler JavaDoc fLexicalHandler;
213     
214     protected QName fQName = new QName();
215     
216     protected boolean resolve_dtd_uris = true;
217     protected boolean startDocumentCalled = false;
218     protected boolean resolverType = true;
219     protected boolean locatorType = false;
220     protected boolean attributeType = true;
221     protected boolean isStandalone = false;
222     // state
223

224     /**
225      * True if a parse is in progress. This state is needed because
226      * some features/properties cannot be set while parsing (e.g.
227      * validation and namespaces).
228      */

229     protected boolean fParseInProgress = false;
230     
231     // track the version of the document being parsed
232
protected String JavaDoc fVersion;
233     
234     // temp vars
235
private final AttributesProxy fAttributesProxy = new AttributesProxy();
236     private Augmentations fAugmentations = null;
237     
238     // temporary buffer for sending normalized values
239
// REVISIT: what should be the size of the buffer?
240
private static final int BUFFER_SIZE = 20;
241     private char[] fCharBuffer = new char[BUFFER_SIZE];
242     
243     // allows us to keep track of whether an attribute has
244
// been declared twice, so that we can avoid exposing the
245
// second declaration to any registered DeclHandler
246
protected SymbolHash fDeclaredAttrs = null;
247     
248     //
249
// Constructors
250
//
251

252     /** Default constructor. */
253     protected AbstractSAXParser(XMLParserConfiguration config) {
254         super(config);
255         
256         config.addRecognizedFeatures(RECOGNIZED_FEATURES);
257         config.addRecognizedProperties(RECOGNIZED_PROPERTIES);
258         
259         try {
260             config.setFeature(ALLOW_UE_AND_NOTATION_EVENTS, false);
261         }
262         catch (XMLConfigurationException e) {
263             // it wasn't a recognized feature, so we don't worry about it
264
}
265     } // <init>(XMLParserConfiguration)
266

267     //
268
// XMLDocumentHandler methods
269
//
270

271     /**
272      * The start of the document.
273      *
274      * @param locator The document locator, or null if the document
275      * location cannot be reported during the parsing
276      * of this document. However, it is <em>strongly</em>
277      * recommended that a locator be supplied that can
278      * at least report the system identifier of the
279      * document.
280      * @param encoding The auto-detected IANA encoding name of the entity
281      * stream. This value will be null in those situations
282      * where the entity encoding is not auto-detected (e.g.
283      * internal entities or a document entity that is
284      * parsed from a java.io.Reader).
285      * @param namespaceContext
286      * The namespace context in effect at the
287      * start of this document.
288      * This object represents the current context.
289      * Implementors of this class are responsible
290      * for copying the namespace bindings from the
291      * the current context (and its parent contexts)
292      * if that information is important.
293      * @param augs Additional information that may include infoset augmentations
294      *
295      * @throws XNIException Thrown by handler to signal an error.
296      */

297     public void startDocument(XMLLocator locator, String JavaDoc encoding,
298     NamespaceContext namespaceContext, Augmentations augs)
299     throws XNIException {
300         
301         fNamespaceContext = namespaceContext;
302         startDocumentCalled = true;
303         try {
304             // SAX1
305
if (fDocumentHandler != null) {
306                 if (locator != null) {
307                     fDocumentHandler.setDocumentLocator(new LocatorProxy(locator));
308                 }
309                 fDocumentHandler.startDocument();
310             }
311             
312             // SAX2
313
if (fContentHandler != null) {
314                 if (locator != null) {
315                     locatorType = true;
316                     fContentHandler.setDocumentLocator(new LocatorProxy(locator));
317                 }
318                 fContentHandler.startDocument();
319             }
320         }
321         catch (SAXException JavaDoc e) {
322             throw new XNIException(e);
323         }
324         
325     } // startDocument(locator,encoding,augs)
326

327     /**
328      * Notifies of the presence of an XMLDecl line in the document. If
329      * present, this method will be called immediately following the
330      * startDocument call.
331      *
332      * @param version The XML version.
333      * @param encoding The IANA encoding name of the document, or null if
334      * not specified.
335      * @param standalone The standalone value, or null if not specified.
336      * @param augs Additional information that may include infoset augmentations
337      *
338      * @throws XNIException Thrown by handler to signal an error.
339      */

340     public void xmlDecl(String JavaDoc version, String JavaDoc encoding, String JavaDoc standalone, Augmentations augs)
341     throws XNIException {
342         
343         // the version need only be set once; if
344
// document's XML 1.0|1.1, that's how it'll stay
345
fVersion = version;
346         if(standalone != null && standalone.equalsIgnoreCase("yes"))
347             isStandalone = true;
348         else
349             isStandalone = false;
350     } // xmlDecl(String,String,String)
351

352     /**
353      * Notifies of the presence of the DOCTYPE line in the document.
354      *
355      * @param rootElement The name of the root element.
356      * @param publicId The public identifier if an external DTD or null
357      * if the external DTD is specified using SYSTEM.
358      * @param systemId The system identifier if an external DTD, null
359      * otherwise.
360      * @param augs Additional information that may include infoset augmentations
361      *
362      * @throws XNIException Thrown by handler to signal an error.
363      */

364     public void doctypeDecl(String JavaDoc rootElement,
365     String JavaDoc publicId, String JavaDoc systemId, Augmentations augs)
366     throws XNIException {
367         fInDTD = true;
368         
369         try {
370             // SAX2 extension
371
if (fLexicalHandler != null) {
372                 fLexicalHandler.startDTD(rootElement, publicId, systemId);
373             }
374         }
375         catch (SAXException JavaDoc e) {
376             throw new XNIException(e);
377         }
378         
379         // is there a DeclHandler?
380
if(fDeclHandler != null) {
381             fDeclaredAttrs = new SymbolHash();
382         }
383         
384     } // doctypeDecl(String,String,String)
385

386     /**
387      * This method notifies of the start of an entity. The DTD has the
388      * pseudo-name of "[dtd]" parameter entity names start with '%'; and
389      * general entity names are just the entity name.
390      * <p>
391      * <strong>Note:</strong> Since the document is an entity, the handler
392      * will be notified of the start of the document entity by calling the
393      * startEntity method with the entity name "[xml]" <em>before</em> calling
394      * the startDocument method. When exposing entity boundaries through the
395      * SAX API, the document entity is never reported, however.
396      * <p>
397      * <strong>Note:</strong> This method is not called for entity references
398      * appearing as part of attribute values.
399      *
400      * @param name The name of the entity.
401      * @param identifier The resource identifier.
402      * @param encoding The auto-detected IANA encoding name of the entity
403      * stream. This value will be null in those situations
404      * where the entity encoding is not auto-detected (e.g.
405      * internal parameter entities).
406      * @param augs Additional information that may include infoset augmentations
407      *
408      * @throws XNIException Thrown by handler to signal an error.
409      */

410     public void startGeneralEntity(String JavaDoc name, XMLResourceIdentifier identifier,
411     String JavaDoc encoding, Augmentations augs)
412     throws XNIException {
413         
414         try {
415             // Only report startEntity if this entity was actually read.
416
if (augs != null && Boolean.TRUE.equals(augs.getItem(Constants.ENTITY_SKIPPED))) {
417                 // report skipped entity to content handler
418
if (fContentHandler != null) {
419                     fContentHandler.skippedEntity(name);
420                 }
421             }
422             else {
423                 // SAX2 extension
424
if (fLexicalHandler != null) {
425                     fLexicalHandler.startEntity(name);
426                 }
427             }
428         }
429         catch (SAXException JavaDoc e) {
430             throw new XNIException(e);
431         }
432         
433     } // startGeneralEntity(String,String,String,String,String)
434

435     /**
436      * This method notifies the end of an entity. The DTD has the pseudo-name
437      * of "[dtd]" parameter entity names start with '%'; and general entity
438      * names are just the entity name.
439      * <p>
440      * <strong>Note:</strong> Since the document is an entity, the handler
441      * will be notified of the end of the document entity by calling the
442      * endEntity method with the entity name "[xml]" <em>after</em> calling
443      * the endDocument method. When exposing entity boundaries through the
444      * SAX API, the document entity is never reported, however.
445      * <p>
446      * <strong>Note:</strong> This method is not called for entity references
447      * appearing as part of attribute values.
448      *
449      * @param name The name of the entity.
450      * @param augs Additional information that may include infoset augmentations
451      *
452      * @throws XNIException Thrown by handler to signal an error.
453      */

454     public void endGeneralEntity(String JavaDoc name, Augmentations augs) throws XNIException {
455         
456         try {
457             // Only report endEntity if this entity was actually read.
458
if (augs == null || !Boolean.TRUE.equals(augs.getItem(Constants.ENTITY_SKIPPED))) {
459                 // SAX2 extension
460
if (fLexicalHandler != null) {
461                     fLexicalHandler.endEntity(name);
462                 }
463             }
464         }
465         catch (SAXException JavaDoc e) {
466             throw new XNIException(e);
467         }
468         
469     } // endEntity(String)
470

471     /**
472      * The start of an element. If the document specifies the start element
473      * by using an empty tag, then the startElement method will immediately
474      * be followed by the endElement method, with no intervening methods.
475      *
476      * @param element The name of the element.
477      * @param attributes The element attributes.
478      * @param augs Additional information that may include infoset augmentations
479      *
480      * @throws XNIException Thrown by handler to signal an error.
481      */

482     public void startElement(QName element, XMLAttributes attributes, Augmentations augs)
483     throws XNIException {
484         
485         try {
486             // SAX1
487
if (fDocumentHandler != null) {
488                 // REVISIT: should we support schema-normalized-value for SAX1 events
489
//
490
fAttributesProxy.setAttributes(attributes);
491                 fDocumentHandler.startElement(element.rawname, fAttributesProxy);
492             }
493             
494             // SAX2
495
if (fContentHandler != null) {
496                 
497                 if (fNamespaces) {
498                     // send prefix mapping events
499
startNamespaceMapping();
500                     
501                     // REVISIT: It should not be necessary to iterate over the attribute
502
// list when the set of [namespace attributes] is empty for this
503
// element. This should be computable from the NamespaceContext, but
504
// since we currently don't report the mappings for the xml prefix
505
// we cannot use the declared prefix count for the current context
506
// to skip this section. -- mrglavas
507
int len = attributes.getLength();
508                     for (int i = len - 1; i >= 0; --i) {
509                         attributes.getName(i, fQName);
510                         if ((fQName.prefix == XMLSymbols.PREFIX_XMLNS) ||
511                         (fQName.rawname == XMLSymbols.PREFIX_XMLNS)) {
512                             if (!fNamespacePrefixes) {
513                                 // remove namespace declaration attributes
514
attributes.removeAttributeAt(i);
515                             }
516                             else {
517                                 // localpart should be empty string as per SAX documentation:
518
// http://www.saxproject.org/?selected=namespaces
519
fQName.prefix = "";
520                                 fQName.uri = "";
521                                 fQName.localpart = "";
522                                 attributes.setName(i, fQName);
523                             }
524                         }
525                     }
526                 }
527                 
528                 fAugmentations = augs;
529                 
530                 String JavaDoc uri = element.uri != null ? element.uri : "";
531                 String JavaDoc localpart = fNamespaces ? element.localpart : "";
532                 fAttributesProxy.setAttributes(attributes);
533                 fContentHandler.startElement(uri, localpart, element.rawname,
534                 fAttributesProxy);
535             }
536         }
537         catch (SAXException JavaDoc e) {
538             throw new XNIException(e);
539         }
540         
541     } // startElement(QName,XMLAttributes)
542

543     /**
544      * Character content.
545      *
546      * @param text The content.
547      * @param augs Additional information that may include infoset augmentations
548      *
549      * @throws XNIException Thrown by handler to signal an error.
550      */

551     public void characters(XMLString text, Augmentations augs) throws XNIException {
552         
553         // if type is union (XML Schema) it is possible that we receive
554
// character call with empty data
555
if (text.length == 0) {
556             return;
557         }
558         
559         
560         try {
561             // SAX1
562
if (fDocumentHandler != null) {
563                 // REVISIT: should we support schema-normalized-value for SAX1 events
564
//
565
fDocumentHandler.characters(text.ch, text.offset, text.length);
566             }
567             
568             // SAX2
569
if (fContentHandler != null) {
570                 fContentHandler.characters(text.ch, text.offset, text.length);
571             }
572         }
573         catch (SAXException JavaDoc e) {
574             throw new XNIException(e);
575         }
576         
577     } // characters(XMLString)
578

579     /**
580      * Ignorable whitespace. For this method to be called, the document
581      * source must have some way of determining that the text containing
582      * only whitespace characters should be considered ignorable. For
583      * example, the validator can determine if a length of whitespace
584      * characters in the document are ignorable based on the element
585      * content model.
586      *
587      * @param text The ignorable whitespace.
588      * @param augs Additional information that may include infoset augmentations
589      *
590      * @throws XNIException Thrown by handler to signal an error.
591      */

592     public void ignorableWhitespace(XMLString text, Augmentations augs) throws XNIException {
593         
594         try {
595             // SAX1
596
if (fDocumentHandler != null) {
597                 fDocumentHandler.ignorableWhitespace(text.ch, text.offset, text.length);
598             }
599             
600             // SAX2
601
if (fContentHandler != null) {
602                 fContentHandler.ignorableWhitespace(text.ch, text.offset, text.length);
603             }
604         }
605         catch (SAXException JavaDoc e) {
606             throw new XNIException(e);
607         }
608         
609     } // ignorableWhitespace(XMLString)
610

611     /**
612      * The end of an element.
613      *
614      * @param element The name of the element.
615      * @param augs Additional information that may include infoset augmentations
616      *
617      * @throws XNIException Thrown by handler to signal an error.
618      */

619     public void endElement(QName element, Augmentations augs) throws XNIException {
620         
621         
622         try {
623             // SAX1
624
if (fDocumentHandler != null) {
625                 fDocumentHandler.endElement(element.rawname);
626             }
627             
628             // SAX2
629
if (fContentHandler != null) {
630                 fAugmentations = augs;
631                 String JavaDoc uri = element.uri != null ? element.uri : "";
632                 String JavaDoc localpart = fNamespaces ? element.localpart : "";
633                 fContentHandler.endElement(uri, localpart,
634                 element.rawname);
635                 if (fNamespaces) {
636                     endNamespaceMapping();
637                 }
638             }
639         }
640         catch (SAXException JavaDoc e) {
641             throw new XNIException(e);
642         }
643         
644     } // endElement(QName)
645

646     /**
647      * The start of a CDATA section.
648      * @param augs Additional information that may include infoset augmentations
649      *
650      * @throws XNIException Thrown by handler to signal an error.
651      */

652     public void startCDATA(Augmentations augs) throws XNIException {
653         
654         try {
655             // SAX2 extension
656
if (fLexicalHandler != null) {
657                 fLexicalHandler.startCDATA();
658             }
659         }
660         catch (SAXException JavaDoc e) {
661             throw new XNIException(e);
662         }
663         
664     } // startCDATA()
665

666     /**
667      * The end of a CDATA section.
668      * @param augs Additional information that may include infoset augmentations
669      *
670      * @throws XNIException Thrown by handler to signal an error.
671      */

672     public void endCDATA(Augmentations augs) throws XNIException {
673         
674         try {
675             // SAX2 extension
676
if (fLexicalHandler != null) {
677                 fLexicalHandler.endCDATA();
678             }
679         }
680         catch (SAXException JavaDoc e) {
681             throw new XNIException(e);
682         }
683         
684     } // endCDATA()
685

686     /**
687      * A comment.
688      *
689      * @param text The text in the comment.
690      * @param augs Additional information that may include infoset augmentations
691      *
692      * @throws XNIException Thrown by application to signal an error.
693      */

694     public void comment(XMLString text, Augmentations augs) throws XNIException {
695         
696         try {
697             // SAX2 extension
698
if (fLexicalHandler != null) {
699                 fLexicalHandler.comment(text.ch, 0, text.length);
700             }
701         }
702         catch (SAXException JavaDoc e) {
703             throw new XNIException(e);
704         }
705         
706     } // comment(XMLString)
707

708     /**
709      * A processing instruction. Processing instructions consist of a
710      * target name and, optionally, text data. The data is only meaningful
711      * to the application.
712      * <p>
713      * Typically, a processing instruction's data will contain a series
714      * of pseudo-attributes. These pseudo-attributes follow the form of
715      * element attributes but are <strong>not</strong> parsed or presented
716      * to the application as anything other than text. The application is
717      * responsible for parsing the data.
718      *
719      * @param target The target.
720      * @param data The data or null if none specified.
721      * @param augs Additional information that may include infoset augmentations
722      *
723      * @throws XNIException Thrown by handler to signal an error.
724      */

725     public void processingInstruction(String JavaDoc target, XMLString data, Augmentations augs)
726     throws XNIException {
727         
728         //
729
// REVISIT - I keep running into SAX apps that expect
730
// null data to be an empty string, which is contrary
731
// to the comment for this method in the SAX API.
732
//
733

734         try {
735             // SAX1
736
if (fDocumentHandler != null) {
737                 fDocumentHandler.processingInstruction(target,
738                 data.toString());
739             }
740             
741             // SAX2
742
if (fContentHandler != null) {
743                 fContentHandler.processingInstruction(target, data.toString());
744             }
745         }
746         catch (SAXException JavaDoc e) {
747             throw new XNIException(e);
748         }
749         
750     } // processingInstruction(String,XMLString)
751

752     
753     /**
754      * The end of the document.
755      * @param augs Additional information that may include infoset augmentations
756      *
757      * @throws XNIException Thrown by handler to signal an error.
758      */

759     public void endDocument(Augmentations augs) throws XNIException {
760         
761         try {
762             // SAX1
763
if (fDocumentHandler != null) {
764                 fDocumentHandler.endDocument();
765             }
766             
767             // SAX2
768
if (fContentHandler != null) {
769                 fContentHandler.endDocument();
770             }
771         }
772         catch (SAXException JavaDoc e) {
773             throw new XNIException(e);
774         }
775         
776     } // endDocument()
777

778     //
779
// XMLDTDHandler methods
780
//
781

782     /**
783      * The start of the DTD external subset.
784      *
785      * @param augs Additional information that may include infoset
786      * augmentations.
787      *
788      * @throws XNIException Thrown by handler to signal an error.
789      */

790     public void startExternalSubset(XMLResourceIdentifier identifier,
791     Augmentations augs) throws XNIException {
792         startParameterEntity("[dtd]", null, null, augs);
793     }
794     
795     /**
796      * The end of the DTD external subset.
797      *
798      * @param augs Additional information that may include infoset
799      * augmentations.
800      *
801      * @throws XNIException Thrown by handler to signal an error.
802      */

803     public void endExternalSubset(Augmentations augs) throws XNIException {
804         endParameterEntity("[dtd]", augs);
805     }
806     
807     /**
808      * This method notifies of the start of parameter entity. The DTD has the
809      * pseudo-name of "[dtd]" parameter entity names start with '%'; and
810      * general entity names are just the entity name.
811      * <p>
812      * <strong>Note:</strong> Since the document is an entity, the handler
813      * will be notified of the start of the document entity by calling the
814      * startEntity method with the entity name "[xml]" <em>before</em> calling
815      * the startDocument method. When exposing entity boundaries through the
816      * SAX API, the document entity is never reported, however.
817      * <p>
818      * <strong>Note:</strong> This method is not called for entity references
819      * appearing as part of attribute values.
820      *
821      * @param name The name of the parameter entity.
822      * @param identifier The resource identifier.
823      * @param encoding The auto-detected IANA encoding name of the entity
824      * stream. This value will be null in those situations
825      * where the entity encoding is not auto-detected (e.g.
826      * internal parameter entities).
827      * @param augs Additional information that may include infoset
828      * augmentations.
829      *
830      * @throws XNIException Thrown by handler to signal an error.
831      */

832     public void startParameterEntity(String JavaDoc name,
833     XMLResourceIdentifier identifier,
834     String JavaDoc encoding, Augmentations augs)
835     throws XNIException {
836         
837         try {
838             // Only report startEntity if this entity was actually read.
839
if (augs != null && Boolean.TRUE.equals(augs.getItem(Constants.ENTITY_SKIPPED))) {
840                 // report skipped entity to content handler
841
if (fContentHandler != null) {
842                     fContentHandler.skippedEntity(name);
843                 }
844             }
845             else {
846                 // SAX2 extension
847
if (fLexicalHandler != null && fLexicalHandlerParameterEntities) {
848                     fLexicalHandler.startEntity(name);
849                 }
850             }
851         }
852         catch (SAXException JavaDoc e) {
853             throw new XNIException(e);
854         }
855         
856     } // startParameterEntity(String,identifier,String,Augmentation)
857

858     /**
859      * This method notifies the end of an entity. The DTD has the pseudo-name
860      * of "[dtd]" parameter entity names start with '%'; and general entity
861      * names are just the entity name.
862      * <p>
863      * <strong>Note:</strong> Since the document is an entity, the handler
864      * will be notified of the end of the document entity by calling the
865      * endEntity method with the entity name "[xml]" <em>after</em> calling
866      * the endDocument method. When exposing entity boundaries through the
867      * SAX API, the document entity is never reported, however.
868      * <p>
869      * <strong>Note:</strong> This method is not called for entity references
870      * appearing as part of attribute values.
871      *
872      * @param name The name of the parameter entity.
873      * @param augs Additional information that may include infoset
874      * augmentations.
875      *
876      * @throws XNIException Thrown by handler to signal an error.
877      */

878     public void endParameterEntity(String JavaDoc name, Augmentations augs) throws XNIException {
879         
880         try {
881             // Only report endEntity if this entity was actually read.
882
if (augs == null || !Boolean.TRUE.equals(augs.getItem(Constants.ENTITY_SKIPPED))) {
883                 // SAX2 extension
884
if (fLexicalHandler != null && fLexicalHandlerParameterEntities) {
885                     fLexicalHandler.endEntity(name);
886                 }
887             }
888         }
889         catch (SAXException JavaDoc e) {
890             throw new XNIException(e);
891         }
892         
893     } // endEntity(String)
894

895     /**
896      * An element declaration.
897      *
898      * @param name The name of the element.
899      * @param contentModel The element content model.
900      *
901      * @param augs Additional information that may include infoset
902      * augmentations.
903      *
904      * @throws XNIException Thrown by handler to signal an error.
905      */

906     public void elementDecl(String JavaDoc name, String JavaDoc contentModel, Augmentations augs)
907     throws XNIException {
908         
909         try {
910             // SAX2 extension
911
if (fDeclHandler != null) {
912                 fDeclHandler.elementDecl(name, contentModel);
913             }
914         }
915         catch (SAXException JavaDoc e) {
916             throw new XNIException(e);
917         }
918         
919     } // elementDecl(String,String, Augmentations)
920

921     /**
922      * An attribute declaration.
923      *
924      * @param elementName The name of the element that this attribute
925      * is associated with.
926      * @param attributeName The name of the attribute.
927      * @param type The attribute type. This value will be one of
928      * the following: "CDATA", "ENTITY", "ENTITIES",
929      * "ENUMERATION", "ID", "IDREF", "IDREFS",
930      * "NMTOKEN", "NMTOKENS", or "NOTATION".
931      * @param enumeration If the type has the value "ENUMERATION" or
932      * "NOTATION", this array holds the allowed attribute
933      * values; otherwise, this array is null.
934      * @param defaultType The attribute default type. This value will be
935      * one of the following: "#FIXED", "#IMPLIED",
936      * "#REQUIRED", or null.
937      * @param defaultValue The attribute default value, or null if no
938      * default value is specified.
939      *
940      * @param nonNormalizedDefaultValue The attribute default value with no normalization
941      * performed, or null if no default value is specified.
942      * @param augs Additional information that may include infoset
943      * augmentations.
944      *
945      * @throws XNIException Thrown by handler to signal an error.
946      */

947     public void attributeDecl(String JavaDoc elementName, String JavaDoc attributeName,
948     String JavaDoc type, String JavaDoc[] enumeration,
949     String JavaDoc defaultType, XMLString defaultValue,
950     XMLString nonNormalizedDefaultValue, Augmentations augs) throws XNIException {
951         
952         try {
953             // SAX2 extension
954
if (fDeclHandler != null) {
955                 // used as a key to detect duplicate attribute definitions.
956
String JavaDoc elemAttr = new StringBuffer JavaDoc(elementName).append("<").append(attributeName).toString();
957                 if(fDeclaredAttrs.get(elemAttr) != null) {
958                     // we aren't permitted to return duplicate attribute definitions
959
return;
960                 }
961                 fDeclaredAttrs.put(elemAttr, Boolean.TRUE);
962                 if (type.equals("NOTATION") ||
963                 type.equals("ENUMERATION")) {
964                     
965                     StringBuffer JavaDoc str = new StringBuffer JavaDoc();
966                     if (type.equals("NOTATION")) {
967                         str.append(type);
968                         str.append(" (");
969                     }
970                     else {
971                         str.append("(");
972                     }
973                     for (int i = 0; i < enumeration.length; i++) {
974                         str.append(enumeration[i]);
975                         if (i < enumeration.length - 1) {
976                             str.append('|');
977                         }
978                     }
979                     str.append(')');
980                     type = str.toString();
981                 }
982                 String JavaDoc value = (defaultValue==null) ? null : defaultValue.toString();
983                 fDeclHandler.attributeDecl(elementName, attributeName,
984                 type, defaultType, value);
985             }
986         }
987         catch (SAXException JavaDoc e) {
988             throw new XNIException(e);
989         }
990         
991     } // attributeDecl(String,String,String,String[],String,XMLString, XMLString, Augmentations)
992

993     /**
994      * An internal entity declaration.
995      *
996      * @param name The name of the entity. Parameter entity names start with
997      * '%', whereas the name of a general entity is just the
998      * entity name.
999      * @param text The value of the entity.
1000     * @param nonNormalizedText The non-normalized value of the entity. This
1001     * value contains the same sequence of characters that was in
1002     * the internal entity declaration, without any entity
1003     * references expanded.
1004     *
1005     * @param augs Additional information that may include infoset
1006     * augmentations.
1007     *
1008     * @throws XNIException Thrown by handler to signal an error.
1009     */

1010    public void internalEntityDecl(String JavaDoc name, XMLString text,
1011    XMLString nonNormalizedText,
1012    Augmentations augs) throws XNIException {
1013        
1014        try {
1015            // SAX2 extensions
1016
if (fDeclHandler != null) {
1017                fDeclHandler.internalEntityDecl(name, text.toString());
1018            }
1019        }
1020        catch (SAXException JavaDoc e) {
1021            throw new XNIException(e);
1022        }
1023        
1024    } // internalEntityDecl(String,XMLString,XMLString)
1025

1026    /**
1027     * An external entity declaration.
1028     *
1029     * @param name The name of the entity. Parameter entity names start
1030     * with '%', whereas the name of a general entity is just
1031     * the entity name.
1032     * @param identifier An object containing all location information
1033     * pertinent to this entity.
1034     * @param augs Additional information that may include infoset
1035     * augmentations.
1036     *
1037     * @throws XNIException Thrown by handler to signal an error.
1038     */

1039    public void externalEntityDecl(String JavaDoc name, XMLResourceIdentifier identifier,
1040    Augmentations augs) throws XNIException {
1041        
1042        String JavaDoc publicId = identifier.getPublicId();
1043        String JavaDoc literalSystemId = identifier.getLiteralSystemId();
1044        String JavaDoc expandedSystemId = identifier.getExpandedSystemId();
1045        try {
1046            // SAX2 extension
1047
if (fDeclHandler != null) {
1048                fDeclHandler.externalEntityDecl(name, publicId, ((resolve_dtd_uris) ? expandedSystemId : literalSystemId));
1049            }
1050        }
1051        catch (SAXException JavaDoc e) {
1052            throw new XNIException(e);
1053        }
1054        
1055    } // externalEntityDecl(String,,XMLResourceIdentifier, Augmentations)
1056

1057    /**
1058     * An unparsed entity declaration.
1059     *
1060     * @param name The name of the entity.
1061     * @param identifier An object containing all location information
1062     * pertinent to this entity.
1063     * @param notation The name of the notation.
1064     *
1065     * @param augs Additional information that may include infoset
1066     * augmentations.
1067     *
1068     * @throws XNIException Thrown by handler to signal an error.
1069     */

1070    public void unparsedEntityDecl(String JavaDoc name, XMLResourceIdentifier identifier,
1071    String JavaDoc notation,
1072    Augmentations augs) throws XNIException {
1073        
1074        String JavaDoc publicId = identifier.getPublicId();
1075        String JavaDoc expandedSystemId = identifier.getExpandedSystemId();
1076        String JavaDoc literalSystemId = identifier.getLiteralSystemId();
1077        try {
1078            // SAX2 extension
1079
if (fDTDHandler != null) {
1080                fDTDHandler.unparsedEntityDecl(name, publicId,
1081                ((resolve_dtd_uris) ? expandedSystemId : literalSystemId), notation);
1082            }
1083        }
1084        catch (SAXException JavaDoc e) {
1085            throw new XNIException(e);
1086        }
1087        
1088    } // unparsedEntityDecl(String,XMLResourceIdentifier, String, Augmentations)
1089

1090    /**
1091     * A notation declaration
1092     *
1093     * @param name The name of the notation.
1094     * @param identifier An object containing all location information
1095     * pertinent to this notation.
1096     * @param augs Additional information that may include infoset
1097     * augmentations.
1098     *
1099     * @throws XNIException Thrown by handler to signal an error.
1100     */

1101    public void notationDecl(String JavaDoc name, XMLResourceIdentifier identifier,
1102    Augmentations augs) throws XNIException {
1103        
1104        String JavaDoc publicId = identifier.getPublicId();
1105        String JavaDoc expandedSystemId = identifier.getExpandedSystemId();
1106        String JavaDoc literalSystemId = identifier.getLiteralSystemId();
1107        try {
1108            // SAX1 and SAX2
1109
if (fDTDHandler != null) {
1110                fDTDHandler.notationDecl(name, publicId, ((resolve_dtd_uris) ? expandedSystemId : literalSystemId));
1111            }
1112        }
1113        catch (SAXException JavaDoc e) {
1114            throw new XNIException(e);
1115        }
1116        
1117    } // notationDecl(String,XMLResourceIdentifier, Augmentations)
1118

1119    /**
1120     * The end of the DTD.
1121     *
1122     * @param augs Additional information that may include infoset
1123     * augmentations.
1124     *
1125     * @throws XNIException Thrown by handler to signal an error.
1126     */

1127    public void endDTD(Augmentations augs) throws XNIException {
1128        fInDTD = false;
1129        
1130        try {
1131            // SAX2 extension
1132
if (fLexicalHandler != null) {
1133                fLexicalHandler.endDTD();
1134            }
1135        }
1136        catch (SAXException JavaDoc e) {
1137            throw new XNIException(e);
1138        }
1139        if(fDeclaredAttrs != null) {
1140            // help out the GC
1141
fDeclaredAttrs.clear();
1142        }
1143        
1144    } // endDTD()
1145

1146    //
1147
// Parser and XMLReader methods
1148
//
1149

1150    /**
1151     * Parses the input source specified by the given system identifier.
1152     * <p>
1153     * This method is equivalent to the following:
1154     * <pre>
1155     * parse(new InputSource(systemId));
1156     * </pre>
1157     *
1158     * @param systemId The system identifier (URI).
1159     *
1160     * @exception org.xml.sax.SAXException Throws exception on SAX error.
1161     * @exception java.io.IOException Throws exception on i/o error.
1162     */

1163    public void parse(String JavaDoc systemId) throws SAXException JavaDoc, IOException JavaDoc {
1164        
1165        // parse document
1166
XMLInputSource source = new XMLInputSource(null, systemId, null);
1167        try {
1168            parse(source);
1169        }
1170        
1171        // wrap XNI exceptions as SAX exceptions
1172
catch (XMLParseException e) {
1173            Exception JavaDoc ex = e.getException();
1174            if (ex == null) {
1175                // must be a parser exception; mine it for locator info and throw
1176
// a SAXParseException
1177
locatorType = true;
1178                LocatorImpl JavaDoc locatorImpl = new LocatorImpl JavaDoc(){
1179                    public String JavaDoc getXMLVersion() {
1180                        return fVersion;
1181                    }
1182                    // since XMLParseExceptions know nothing about encoding,
1183
// we cannot return anything meaningful in this context.
1184
// We *could* consult the LocatorProxy, but the
1185
// application can do this itself if it wishes to possibly
1186
// be mislead.
1187
public String JavaDoc getEncoding() {
1188                        return null;
1189                    }
1190                };
1191                locatorImpl.setPublicId(e.getPublicId());
1192                locatorImpl.setSystemId(e.getExpandedSystemId());
1193                locatorImpl.setLineNumber(e.getLineNumber());
1194                locatorImpl.setColumnNumber(e.getColumnNumber());
1195                throw new SAXParseException JavaDoc(e.getMessage(), locatorImpl);
1196            }
1197            if (ex instanceof SAXException JavaDoc) {
1198                // why did we create an XMLParseException?
1199
throw (SAXException JavaDoc)ex;
1200            }
1201            if (ex instanceof IOException JavaDoc) {
1202                throw (IOException JavaDoc)ex;
1203            }
1204            throw new SAXException JavaDoc(ex);
1205        }
1206        catch (XNIException e) {
1207            Exception JavaDoc ex = e.getException();
1208            if (ex == null) {
1209                throw new SAXException JavaDoc(e.getMessage());
1210            }
1211            if (ex instanceof SAXException JavaDoc) {
1212                throw (SAXException JavaDoc)ex;
1213            }
1214            if (ex instanceof IOException JavaDoc) {
1215                throw (IOException JavaDoc)ex;
1216            }
1217            throw new SAXException JavaDoc(ex);
1218        }
1219        
1220    } // parse(String)
1221

1222    /**
1223     * parse
1224     *
1225     * @param inputSource
1226     *
1227     * @exception org.xml.sax.SAXException
1228     * @exception java.io.IOException
1229     */

1230    public void parse(InputSource inputSource)
1231    throws SAXException JavaDoc, IOException JavaDoc {
1232        
1233        // parse document
1234
try {
1235            XMLInputSource xmlInputSource =
1236            new XMLInputSource(inputSource.getPublicId(),
1237            inputSource.getSystemId(),
1238            null);
1239            xmlInputSource.setByteStream(inputSource.getByteStream());
1240            xmlInputSource.setCharacterStream(inputSource.getCharacterStream());
1241            xmlInputSource.setEncoding(inputSource.getEncoding());
1242            parse(xmlInputSource);
1243        }
1244        
1245        // wrap XNI exceptions as SAX exceptions
1246
catch (XMLParseException e) {
1247            Exception JavaDoc ex = e.getException();
1248            if (ex == null) {
1249                // must be a parser exception; mine it for locator info and throw
1250
// a SAXParseException
1251
locatorType = true;
1252                LocatorImpl JavaDoc locatorImpl = new LocatorImpl JavaDoc() {
1253                    public String JavaDoc getXMLVersion() {
1254                        return fVersion;
1255                    }
1256                    // since XMLParseExceptions know nothing about encoding,
1257
// we cannot return anything meaningful in this context.
1258
// We *could* consult the LocatorProxy, but the
1259
// application can do this itself if it wishes to possibly
1260
// be mislead.
1261
public String JavaDoc getEncoding() {
1262                        return null;
1263                    }
1264                };
1265                locatorImpl.setPublicId(e.getPublicId());
1266                locatorImpl.setSystemId(e.getExpandedSystemId());
1267                locatorImpl.setLineNumber(e.getLineNumber());
1268                locatorImpl.setColumnNumber(e.getColumnNumber());
1269                throw new SAXParseException JavaDoc(e.getMessage(), locatorImpl);
1270            }
1271            if (ex instanceof SAXException JavaDoc) {
1272                // why did we create an XMLParseException?
1273
throw (SAXException JavaDoc)ex;
1274            }
1275            if (ex instanceof IOException JavaDoc) {
1276                throw (IOException JavaDoc)ex;
1277            }
1278            throw new SAXException JavaDoc(ex);
1279        }
1280        catch (XNIException e) {
1281            Exception JavaDoc ex = e.getException();
1282            if (ex == null) {
1283                throw new SAXException JavaDoc(e.getMessage());
1284            }
1285            if (ex instanceof SAXException JavaDoc) {
1286                throw (SAXException JavaDoc)ex;
1287            }
1288            if (ex instanceof IOException JavaDoc) {
1289                throw (IOException JavaDoc)ex;
1290            }
1291            throw new SAXException JavaDoc(ex);
1292        }
1293        
1294    } // parse(InputSource)
1295

1296    /**
1297     * Sets the resolver used to resolve external entities. The EntityResolver
1298     * interface supports resolution of public and system identifiers.
1299     *
1300     * @param resolver The new entity resolver. Passing a null value will
1301     * uninstall the currently installed resolver.
1302     */

1303    public void setEntityResolver(EntityResolver resolver) {
1304        
1305        try {
1306            if(resolver instanceof EntityResolver2 JavaDoc){
1307                resolverType = true;
1308                fConfiguration.setProperty(ENTITY_RESOLVER, new EntityResolver2Wrapper((EntityResolver2 JavaDoc)resolver));
1309            }else
1310                fConfiguration.setProperty(ENTITY_RESOLVER, new EntityResolverWrapper(resolver));
1311        }
1312        catch (XMLConfigurationException e) {
1313            // do nothing
1314
}
1315        
1316    } // setEntityResolver(EntityResolver)
1317

1318    /**
1319     * Return the current entity resolver.
1320     *
1321     * @return The current entity resolver, or null if none
1322     * has been registered.
1323     * @see #setEntityResolver
1324     */

1325    public EntityResolver getEntityResolver() {
1326        
1327        EntityResolver entityResolver = null;
1328        try {
1329            XMLEntityResolver xmlEntityResolver =
1330            (XMLEntityResolver)fConfiguration.getProperty(ENTITY_RESOLVER);
1331            if (xmlEntityResolver != null){
1332                if( xmlEntityResolver instanceof EntityResolverWrapper) {
1333                    entityResolver = ((EntityResolverWrapper)xmlEntityResolver).getEntityResolver();
1334                }else if(xmlEntityResolver instanceof EntityResolver2Wrapper){
1335                    entityResolver = ((EntityResolver2Wrapper)xmlEntityResolver).getEntityResolver();
1336                }
1337            }
1338        }catch (XMLConfigurationException e) {
1339            // do nothing
1340
}
1341        return entityResolver;
1342        
1343    } // getEntityResolver():EntityResolver
1344

1345    /**
1346     * Allow an application to register an error event handler.
1347     *
1348     * <p>If the application does not register an error handler, all
1349     * error events reported by the SAX parser will be silently
1350     * ignored; however, normal processing may not continue. It is
1351     * highly recommended that all SAX applications implement an
1352     * error handler to avoid unexpected bugs.</p>
1353     *
1354     * <p>Applications may register a new or different handler in the
1355     * middle of a parse, and the SAX parser must begin using the new
1356     * handler immediately.</p>
1357     *
1358     * @param errorHandler The error handler.
1359     * @see #getErrorHandler
1360     */

1361    public void setErrorHandler(ErrorHandler errorHandler) {
1362        
1363        try {
1364            fConfiguration.setProperty(ERROR_HANDLER,
1365            new ErrorHandlerWrapper(errorHandler));
1366        }
1367        catch (XMLConfigurationException e) {
1368            // do nothing
1369
}
1370        
1371    } // setErrorHandler(ErrorHandler)
1372

1373    /**
1374     * Return the current error handler.
1375     *
1376     * @return The current error handler, or null if none
1377     * has been registered.
1378     * @see #setErrorHandler
1379     */

1380    public ErrorHandler getErrorHandler() {
1381        
1382        ErrorHandler errorHandler = null;
1383        try {
1384            XMLErrorHandler xmlErrorHandler =
1385            (XMLErrorHandler)fConfiguration.getProperty(ERROR_HANDLER);
1386            if (xmlErrorHandler != null &&
1387            xmlErrorHandler instanceof ErrorHandlerWrapper) {
1388                errorHandler = ((ErrorHandlerWrapper)xmlErrorHandler).getErrorHandler();
1389            }
1390        }
1391        catch (XMLConfigurationException e) {
1392            // do nothing
1393
}
1394        return errorHandler;
1395        
1396    } // getErrorHandler():ErrorHandler
1397

1398    /**
1399     * Set the locale to use for messages.
1400     *
1401     * @param locale The locale object to use for localization of messages.
1402     *
1403     * @exception SAXException An exception thrown if the parser does not
1404     * support the specified locale.
1405     *
1406     * @see org.xml.sax.Parser
1407     */

1408    public void setLocale(Locale JavaDoc locale) throws SAXException JavaDoc {
1409        //REVISIT:this methods is not part of SAX2 interfaces, we should throw exception
1410
//if any application uses SAX2 and sets locale also. -nb
1411
fConfiguration.setLocale(locale);
1412        
1413    } // setLocale(Locale)
1414

1415    /**
1416     * Allow an application to register a DTD event handler.
1417     * <p>
1418     * If the application does not register a DTD handler, all DTD
1419     * events reported by the SAX parser will be silently ignored.
1420     * <p>
1421     * Applications may register a new or different handler in the
1422     * middle of a parse, and the SAX parser must begin using the new
1423     * handler immediately.
1424     *
1425     * @param dtdHandler The DTD handler.
1426     *
1427     *
1428     * @see #getDTDHandler
1429     */

1430    public void setDTDHandler(DTDHandler JavaDoc dtdHandler) {
1431        fDTDHandler = dtdHandler;
1432    } // setDTDHandler(DTDHandler)
1433

1434    //
1435
// Parser methods
1436
//
1437

1438    /**
1439     * Allow an application to register a document event handler.
1440     * <p>
1441     * If the application does not register a document handler, all
1442     * document events reported by the SAX parser will be silently
1443     * ignored (this is the default behaviour implemented by
1444     * HandlerBase).
1445     * <p>
1446     * Applications may register a new or different handler in the
1447     * middle of a parse, and the SAX parser must begin using the new
1448     * handler immediately.
1449     *
1450     * @param documentHandler The document handler.
1451     */

1452    public void setDocumentHandler(DocumentHandler JavaDoc documentHandler) {
1453        fDocumentHandler = documentHandler;
1454    } // setDocumentHandler(DocumentHandler)
1455

1456    //
1457
// XMLReader methods
1458
//
1459

1460    /**
1461     * Allow an application to register a content event handler.
1462     * <p>
1463     * If the application does not register a content handler, all
1464     * content events reported by the SAX parser will be silently
1465     * ignored.
1466     * <p>
1467     * Applications may register a new or different handler in the
1468     * middle of a parse, and the SAX parser must begin using the new
1469     * handler immediately.
1470     *
1471     * @param contentHandler The content handler.
1472     *
1473     * @see #getContentHandler
1474     */

1475    public void setContentHandler(ContentHandler JavaDoc contentHandler) {
1476        fContentHandler = contentHandler;
1477    } // setContentHandler(ContentHandler)
1478

1479    /**
1480     * Return the current content handler.
1481     *
1482     * @return The current content handler, or null if none
1483     * has been registered.
1484     *
1485     * @see #setContentHandler
1486     */

1487    public ContentHandler JavaDoc getContentHandler() {
1488        return fContentHandler;
1489    } // getContentHandler():ContentHandler
1490

1491    /**
1492     * Return the current DTD handler.
1493     *
1494     * @return The current DTD handler, or null if none
1495     * has been registered.
1496     * @see #setDTDHandler
1497     */

1498    public DTDHandler JavaDoc getDTDHandler() {
1499        return fDTDHandler;
1500    } // getDTDHandler():DTDHandler
1501

1502    /**
1503     * Set the state of any feature in a SAX2 parser. The parser
1504     * might not recognize the feature, and if it does recognize
1505     * it, it might not be able to fulfill the request.
1506     *
1507     * @param featureId The unique identifier (URI) of the feature.
1508     * @param state The requested state of the feature (true or false).
1509     *
1510     * @exception SAXNotRecognizedException If the
1511     * requested feature is not known.
1512     * @exception SAXNotSupportedException If the
1513     * requested feature is known, but the requested
1514     * state is not supported.
1515     */

1516    public void setFeature(String JavaDoc featureId, boolean state)
1517    throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
1518        
1519        try {
1520            //
1521
// SAX2 Features
1522
//
1523

1524            if (featureId.startsWith(Constants.SAX_FEATURE_PREFIX)) {
1525                final int suffixLength = featureId.length() - Constants.SAX_FEATURE_PREFIX.length();
1526                
1527                // http://xml.org/sax/features/namespaces
1528
if (suffixLength == Constants.NAMESPACES_FEATURE.length() &&
1529                featureId.endsWith(Constants.NAMESPACES_FEATURE)) {
1530                    fConfiguration.setFeature(featureId, state);
1531                    fNamespaces = state;
1532                    return;
1533                }
1534                // http://xml.org/sax/features/namespace-prefixes
1535
// controls the reporting of raw prefixed names and Namespace
1536
// declarations (xmlns* attributes): when this feature is false
1537
// (the default), raw prefixed names may optionally be reported,
1538
// and xmlns* attributes must not be reported.
1539
//
1540
if (suffixLength == Constants.NAMESPACE_PREFIXES_FEATURE.length() &&
1541                featureId.endsWith(Constants.NAMESPACE_PREFIXES_FEATURE)) {
1542                    fConfiguration.setFeature(featureId, state);
1543                    fNamespacePrefixes = state;
1544                    return;
1545                }
1546                // http://xml.org/sax/features/string-interning
1547
// controls the use of java.lang.String#intern() for strings
1548
// passed to SAX handlers.
1549
//
1550
if (suffixLength == Constants.STRING_INTERNING_FEATURE.length() &&
1551                featureId.endsWith(Constants.STRING_INTERNING_FEATURE)) {
1552                    if (!state) {
1553                        throw new SAXNotSupportedException JavaDoc(
1554                        SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
1555                        "false-not-supported", new Object JavaDoc [] {featureId}));
1556                    }
1557                    return;
1558                }
1559                // http://xml.org/sax/features/lexical-handler/parameter-entities
1560
// controls whether the beginning and end of parameter entities
1561
// will be reported to the LexicalHandler.
1562
//
1563
if (suffixLength == Constants.LEXICAL_HANDLER_PARAMETER_ENTITIES_FEATURE.length() &&
1564                featureId.endsWith(Constants.LEXICAL_HANDLER_PARAMETER_ENTITIES_FEATURE)) {
1565                    fLexicalHandlerParameterEntities = state;
1566                    return;
1567                }
1568                
1569                if(suffixLength == Constants.RESOLVE_DTD_URIS_FEATURE.length() && featureId.endsWith(Constants.RESOLVE_DTD_URIS_FEATURE)){
1570                    resolve_dtd_uris = state;
1571                    fConfiguration.setFeature(featureId, state);
1572                    return;
1573                }
1574                
1575                if((suffixLength == Constants.XML_11_FEATURE.length() &&
1576                featureId.endsWith(Constants.XML_11_FEATURE)) ||
1577                (suffixLength == Constants.USE_ENTITY_RESOLVER2_FEATURE.length() &&
1578                featureId.endsWith(Constants.USE_ENTITY_RESOLVER2_FEATURE))||
1579                (suffixLength == Constants.USE_LOCATOR2_FEATURE.length() &&
1580                featureId.endsWith(Constants.USE_LOCATOR2_FEATURE))||
1581                (suffixLength == Constants.USE_ATTRIBUTES2_FEATURE.length() &&
1582                featureId.endsWith(Constants.USE_ATTRIBUTES2_FEATURE))||
1583                (suffixLength == Constants.IS_STANDALONE_FEATURE.length() &&
1584                featureId.endsWith(Constants.IS_STANDALONE_FEATURE))
1585                ){
1586                    throw new SAXNotSupportedException JavaDoc(
1587                    SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
1588                    "feature-read-only", new Object JavaDoc [] {featureId}));
1589                }
1590                
1591                
1592                //
1593
// Drop through and perform default processing
1594
//
1595
}
1596            
1597            //
1598
// Xerces Features
1599
//
1600

1601            /*
1602            else if (featureId.startsWith(XERCES_FEATURES_PREFIX)) {
1603                String feature = featureId.substring(XERCES_FEATURES_PREFIX.length());
1604                //
1605                // Drop through and perform default processing
1606                //
1607            }
1608             */

1609            
1610            //
1611
// Default handling
1612
//
1613

1614            fConfiguration.setFeature(featureId, state);
1615        }
1616        catch (XMLConfigurationException e) {
1617            String JavaDoc identifier = e.getIdentifier();
1618            if (e.getType() == XMLConfigurationException.NOT_RECOGNIZED) {
1619                throw new SAXNotRecognizedException JavaDoc(
1620                SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
1621                "feature-not-recognized", new Object JavaDoc [] {identifier}));
1622            }
1623            else {
1624                throw new SAXNotSupportedException JavaDoc(
1625                SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
1626                "feature-not-supported", new Object JavaDoc [] {identifier}));
1627            }
1628        }
1629        
1630    } // setFeature(String,boolean)
1631

1632    /**
1633     * Query the state of a feature.
1634     *
1635     * Query the current state of any feature in a SAX2 parser. The
1636     * parser might not recognize the feature.
1637     *
1638     * @param featureId The unique identifier (URI) of the feature
1639     * being set.
1640     * @return The current state of the feature.
1641     * @exception org.xml.sax.SAXNotRecognizedException If the
1642     * requested feature is not known.
1643     * @exception SAXNotSupportedException If the
1644     * requested feature is known but not supported.
1645     */

1646    public boolean getFeature(String JavaDoc featureId)
1647    throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
1648        
1649        try {
1650            //
1651
// SAX2 Features
1652
//
1653

1654            if (featureId.startsWith(Constants.SAX_FEATURE_PREFIX)) {
1655                final int suffixLength = featureId.length() - Constants.SAX_FEATURE_PREFIX.length();
1656                
1657                // http://xml.org/sax/features/namespace-prefixes
1658
// controls the reporting of raw prefixed names and Namespace
1659
// declarations (xmlns* attributes): when this feature is false
1660
// (the default), raw prefixed names may optionally be reported,
1661
// and xmlns* attributes must not be reported.
1662
//
1663
if (suffixLength == Constants.NAMESPACE_PREFIXES_FEATURE.length() &&
1664                featureId.endsWith(Constants.NAMESPACE_PREFIXES_FEATURE)) {
1665                    boolean state = fConfiguration.getFeature(featureId);
1666                    return state;
1667                }
1668                // http://xml.org/sax/features/string-interning
1669
// controls the use of java.lang.String#intern() for strings
1670
// passed to SAX handlers.
1671
//
1672
if (suffixLength == Constants.STRING_INTERNING_FEATURE.length() &&
1673                featureId.endsWith(Constants.STRING_INTERNING_FEATURE)) {
1674                    return true;
1675                }
1676                
1677                // http://xml.org/sax/features/lexical-handler/parameter-entities
1678
// controls whether the beginning and end of parameter entities
1679
// will be reported to the LexicalHandler.
1680
//
1681
if (suffixLength == Constants.LEXICAL_HANDLER_PARAMETER_ENTITIES_FEATURE.length() &&
1682                featureId.endsWith(Constants.LEXICAL_HANDLER_PARAMETER_ENTITIES_FEATURE)) {
1683                    return fLexicalHandlerParameterEntities;
1684                }
1685                
1686                if(suffixLength == Constants.USE_ENTITY_RESOLVER2_FEATURE.length() &&
1687                featureId.endsWith(Constants.USE_ENTITY_RESOLVER2_FEATURE)){
1688                    return resolverType;
1689                }
1690                
1691                if(suffixLength == Constants.USE_LOCATOR2_FEATURE.length() && featureId.endsWith(Constants.USE_LOCATOR2_FEATURE)){
1692                    return locatorType;
1693                    
1694                }
1695                if(suffixLength == Constants.USE_ATTRIBUTES2_FEATURE.length() && featureId.endsWith(Constants.USE_ATTRIBUTES2_FEATURE)){
1696                    return attributeType;
1697                }
1698                
1699                if(suffixLength == Constants.IS_STANDALONE_FEATURE.length() && featureId.endsWith(Constants.IS_STANDALONE_FEATURE)){
1700                    return isStandalone;
1701                }
1702                
1703                //
1704
// Drop through and perform default processing
1705
//
1706
}
1707            
1708            //
1709
// Xerces Features
1710
//
1711

1712            /*
1713            else if (featureId.startsWith(XERCES_FEATURES_PREFIX)) {
1714                //
1715                // Drop through and perform default processing
1716                //
1717            }
1718             */

1719            
1720            return fConfiguration.getFeature(featureId);
1721        }
1722        catch (XMLConfigurationException e) {
1723            String JavaDoc identifier = e.getIdentifier();
1724            if (e.getType() == XMLConfigurationException.NOT_RECOGNIZED) {
1725                throw new SAXNotRecognizedException JavaDoc(
1726                SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
1727                "feature-not-recognized", new Object JavaDoc [] {identifier}));
1728            }
1729            else {
1730                throw new SAXNotSupportedException JavaDoc(
1731                SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
1732                "feature-not-supported", new Object JavaDoc [] {identifier}));
1733            }
1734        }
1735        
1736    } // getFeature(String):boolean
1737

1738    /**
1739     * Set the value of any property in a SAX2 parser. The parser
1740     * might not recognize the property, and if it does recognize
1741     * it, it might not support the requested value.
1742     *
1743     * @param propertyId The unique identifier (URI) of the property
1744     * being set.
1745     * @param value The value to which the property is being set.
1746     *
1747     * @exception SAXNotRecognizedException If the
1748     * requested property is not known.
1749     * @exception SAXNotSupportedException If the
1750     * requested property is known, but the requested
1751     * value is not supported.
1752     */

1753    public void setProperty(String JavaDoc propertyId, Object JavaDoc value)
1754    throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
1755        
1756        try {
1757            //
1758
// SAX2 core properties
1759
//
1760

1761            if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) {
1762                final int suffixLength = propertyId.length() - Constants.SAX_PROPERTY_PREFIX.length();
1763                
1764                //
1765
// http://xml.org/sax/properties/lexical-handler
1766
// Value type: org.xml.sax.ext.LexicalHandler
1767
// Access: read/write, pre-parse only
1768
// Set the lexical event handler.
1769
//
1770
if (suffixLength == Constants.LEXICAL_HANDLER_PROPERTY.length() &&
1771                propertyId.endsWith(Constants.LEXICAL_HANDLER_PROPERTY)) {
1772                    try {
1773                        setLexicalHandler((LexicalHandler JavaDoc)value);
1774                    }
1775                    catch (ClassCastException JavaDoc e) {
1776                        throw new SAXNotSupportedException JavaDoc(
1777                        SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
1778                        "incompatible-class", new Object JavaDoc [] {propertyId, "org.xml.sax.ext.LexicalHandler"}));
1779                    }
1780                    return;
1781                }
1782                //
1783
// http://xml.org/sax/properties/declaration-handler
1784
// Value type: org.xml.sax.ext.DeclHandler
1785
// Access: read/write, pre-parse only
1786
// Set the DTD declaration event handler.
1787
//
1788
if (suffixLength == Constants.DECLARATION_HANDLER_PROPERTY.length() &&
1789                propertyId.endsWith(Constants.DECLARATION_HANDLER_PROPERTY)) {
1790                    try {
1791                        setDeclHandler((DeclHandler JavaDoc)value);
1792                    }
1793                    catch (ClassCastException JavaDoc e) {
1794                        throw new SAXNotSupportedException JavaDoc(
1795                        SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
1796                        "incompatible-class", new Object JavaDoc [] {propertyId, "org.xml.sax.ext.DeclHandler"}));
1797                    }
1798                    return;
1799                }
1800                //
1801
// http://xml.org/sax/properties/dom-node
1802
// Value type: DOM Node
1803
// Access: read-only
1804
// Get the DOM node currently being visited, if the SAX parser is
1805
// iterating over a DOM tree. If the parser recognises and
1806
// supports this property but is not currently visiting a DOM
1807
// node, it should return null (this is a good way to check for
1808
// availability before the parse begins).
1809
//
1810
if (suffixLength == Constants.DOM_NODE_PROPERTY.length() &&
1811                propertyId.endsWith(Constants.DOM_NODE_PROPERTY)) {
1812                    throw new SAXNotSupportedException JavaDoc(
1813                    SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
1814                    "property-read-only", new Object JavaDoc [] {propertyId}));
1815                }
1816                
1817                if(suffixLength == Constants.DOCUMENT_XML_VERSION_PROPERTY.length() && propertyId.endsWith(Constants.DOCUMENT_XML_VERSION_PROPERTY)){
1818                    throw new SAXNotSupportedException JavaDoc(
1819                    SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
1820                    "property-read-only", new Object JavaDoc [] {propertyId}));
1821                }
1822                
1823                //
1824
// Drop through and perform default processing
1825
//
1826
}
1827            
1828            //
1829
// Xerces Properties
1830
//
1831

1832            /*
1833            else if (propertyId.startsWith(XERCES_PROPERTIES_PREFIX)) {
1834                //
1835                // Drop through and perform default processing
1836                //
1837            }
1838             */

1839            
1840            //
1841
// Perform default processing
1842
//
1843

1844            fConfiguration.setProperty(propertyId, value);
1845        }
1846        catch (XMLConfigurationException e) {
1847            String JavaDoc identifier = e.getIdentifier();
1848            if (e.getType() == XMLConfigurationException.NOT_RECOGNIZED) {
1849                throw new SAXNotRecognizedException JavaDoc(
1850                SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
1851                "property-not-recognized", new Object JavaDoc [] {identifier}));
1852            }
1853            else {
1854                throw new SAXNotSupportedException JavaDoc(
1855                SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
1856                "property-not-supported", new Object JavaDoc [] {identifier}));
1857            }
1858        }
1859        
1860    } // setProperty(String,Object)
1861

1862    /**
1863     * Query the value of a property.
1864     *
1865     * Return the current value of a property in a SAX2 parser.
1866     * The parser might not recognize the property.
1867     *
1868     * @param propertyId The unique identifier (URI) of the property
1869     * being set.
1870     * @return The current value of the property.
1871     * @exception org.xml.sax.SAXNotRecognizedException If the
1872     * requested property is not known.
1873     * @exception SAXNotSupportedException If the
1874     * requested property is known but not supported.
1875     */

1876    public Object JavaDoc getProperty(String JavaDoc propertyId)
1877    throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
1878        
1879        try {
1880            //
1881
// SAX2 core properties
1882
//
1883

1884            if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) {
1885                final int suffixLength = propertyId.length() - Constants.SAX_PROPERTY_PREFIX.length();
1886                
1887                //
1888
// http://xml.org/sax/properties/lexical-handler
1889
// Value type: org.xml.sax.ext.LexicalHandler
1890
// Access: read/write, pre-parse only
1891
// Set the lexical event handler.
1892
//
1893
if (suffixLength == Constants.LEXICAL_HANDLER_PROPERTY.length() &&
1894                propertyId.endsWith(Constants.LEXICAL_HANDLER_PROPERTY)) {
1895                    return getLexicalHandler();
1896                }
1897                //
1898
// http://xml.org/sax/properties/declaration-handler
1899
// Value type: org.xml.sax.ext.DeclHandler
1900
// Access: read/write, pre-parse only
1901
// Set the DTD declaration event handler.
1902
//
1903
if (suffixLength == Constants.DECLARATION_HANDLER_PROPERTY.length() &&
1904                propertyId.endsWith(Constants.DECLARATION_HANDLER_PROPERTY)) {
1905                    return getDeclHandler();
1906                }
1907                //
1908
// http://xml.org/sax/properties/dom-node
1909
// Value type: DOM Node
1910
// Access: read-only
1911
// Get the DOM node currently being visited, if the SAX parser is
1912
// iterating over a DOM tree. If the parser recognises and
1913
// supports this property but is not currently visiting a DOM
1914
// node, it should return null (this is a good way to check for
1915
// availability before the parse begins).
1916
//
1917
if (suffixLength == Constants.DOM_NODE_PROPERTY.length() &&
1918                propertyId.endsWith(Constants.DOM_NODE_PROPERTY)) {
1919                    // we are not iterating a DOM tree
1920
throw new SAXNotSupportedException JavaDoc(
1921                    SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
1922                    "dom-node-read-not-supported", null));
1923                }
1924                if(suffixLength == Constants.DOCUMENT_XML_VERSION_PROPERTY.length() &&
1925                propertyId.endsWith(Constants.DOCUMENT_XML_VERSION_PROPERTY)){
1926                    if(startDocumentCalled){
1927                        return fVersion;
1928                    }else{
1929                        throw new SAXNotSupportedException JavaDoc(
1930                        SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
1931                        "start-document-not-called", new Object JavaDoc [] {propertyId}));
1932                    }
1933                    
1934                }
1935                //
1936
// Drop through and perform default processing
1937
//
1938
}
1939            
1940            //
1941
// Xerces properties
1942
//
1943

1944            /*
1945            else if (propertyId.startsWith(XERCES_PROPERTIES_PREFIX)) {
1946                //
1947                // Drop through and perform default processing
1948                //
1949            }
1950             */

1951            
1952            //
1953
// Perform default processing
1954
//
1955

1956            return fConfiguration.getProperty(propertyId);
1957        }
1958        catch (XMLConfigurationException e) {
1959            String JavaDoc identifier = e.getIdentifier();
1960            if (e.getType() == XMLConfigurationException.NOT_RECOGNIZED) {
1961                throw new SAXNotRecognizedException JavaDoc(
1962                SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
1963                "property-not-recognized", new Object JavaDoc [] {identifier}));
1964            }
1965            else {
1966                throw new SAXNotSupportedException JavaDoc(
1967                SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
1968                "property-not-supported", new Object JavaDoc [] {identifier}));
1969            }
1970        }
1971        
1972    } // getProperty(String):Object
1973

1974    //
1975
// Protected methods
1976
//
1977

1978    // SAX2 core properties
1979

1980    /**
1981     * Set the DTD declaration event handler.
1982     * <p>
1983     * This method is the equivalent to the property:
1984     * <pre>
1985     * http://xml.org/sax/properties/declaration-handler
1986     * </pre>
1987     *
1988     * @param handler The new handler.
1989     *
1990     * @see #getDeclHandler
1991     * @see #setProperty
1992     */

1993    protected void setDeclHandler(DeclHandler JavaDoc handler)
1994    throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
1995        
1996        if (fParseInProgress) {
1997            throw new SAXNotSupportedException JavaDoc(
1998            SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
1999            "property-not-parsing-supported",
2000            new Object JavaDoc [] {"http://xml.org/sax/properties/declaration-handler"}));
2001        }
2002        fDeclHandler = handler;
2003        
2004    } // setDeclHandler(DeclHandler)
2005

2006    /**
2007     * Returns the DTD declaration event handler.
2008     *
2009     * @see #setDeclHandler
2010     */

2011    protected DeclHandler JavaDoc getDeclHandler()
2012    throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
2013        return fDeclHandler;
2014    } // getDeclHandler():DeclHandler
2015

2016    /**
2017     * Set the lexical event handler.
2018     * <p>
2019     * This method is the equivalent to the property:
2020     * <pre>
2021     * http://xml.org/sax/properties/lexical-handler
2022     * </pre>
2023     *
2024     * @param handler lexical event handler
2025     *
2026     * @see #getLexicalHandler
2027     * @see #setProperty
2028     */

2029    protected void setLexicalHandler(LexicalHandler JavaDoc handler)
2030    throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
2031        
2032        if (fParseInProgress) {
2033            throw new SAXNotSupportedException JavaDoc(
2034            SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
2035            "property-not-parsing-supported",
2036            new Object JavaDoc [] {"http://xml.org/sax/properties/lexical-handler"}));
2037        }
2038        fLexicalHandler = handler;
2039        
2040    } // setLexicalHandler(LexicalHandler)
2041

2042    /**
2043     * Returns the lexical handler.
2044     *
2045     * @see #setLexicalHandler
2046     */

2047    protected LexicalHandler JavaDoc getLexicalHandler()
2048    throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
2049        return fLexicalHandler;
2050    } // getLexicalHandler():LexicalHandler
2051

2052    /**
2053     * Send startPrefixMapping events
2054     */

2055    protected final void startNamespaceMapping() throws SAXException JavaDoc{
2056        int count = fNamespaceContext.getDeclaredPrefixCount();
2057        if (count > 0) {
2058            String JavaDoc prefix = null;
2059            String JavaDoc uri = null;
2060            for (int i = 0; i < count; i++) {
2061                prefix = fNamespaceContext.getDeclaredPrefixAt(i);
2062                uri = fNamespaceContext.getURI(prefix);
2063                fContentHandler.startPrefixMapping(prefix,
2064                (uri == null) ? "" : uri);
2065            }
2066        }
2067    }
2068    
2069    /**
2070     * Send endPrefixMapping events
2071     */

2072    protected final void endNamespaceMapping() throws SAXException JavaDoc {
2073        int count = fNamespaceContext.getDeclaredPrefixCount();
2074        if (count > 0) {
2075            for (int i = 0; i < count; i++) {
2076                fContentHandler.endPrefixMapping(fNamespaceContext.getDeclaredPrefixAt(i));
2077            }
2078        }
2079    }
2080    
2081    //
2082
// XMLDocumentParser methods
2083
//
2084

2085    /**
2086     * Reset all components before parsing.
2087     *
2088     * @throws XNIException Thrown if an error occurs during initialization.
2089     */

2090    public void reset() throws XNIException {
2091        super.reset();
2092        
2093        // reset state
2094
fInDTD = false;
2095        fVersion = "1.0";
2096        
2097        // features
2098
fNamespaces = fConfiguration.getFeature(NAMESPACES);
2099        fNamespacePrefixes = fConfiguration.getFeature(NAMESPACE_PREFIXES);
2100        fAugmentations = null;
2101        fDeclaredAttrs = null;
2102        
2103    } // reset()
2104

2105    //
2106
// Classes
2107
//
2108

2109    protected class LocatorProxy
2110    implements Locator2 JavaDoc {
2111        
2112        //
2113
// Data
2114
//
2115

2116        /** XML locator. */
2117        protected XMLLocator fLocator;
2118        
2119        //
2120
// Constructors
2121
//
2122

2123        /** Constructs an XML locator proxy. */
2124        public LocatorProxy(XMLLocator locator) {
2125            fLocator = locator;
2126        }
2127        
2128        //
2129
// Locator methods
2130
//
2131

2132        /** Public identifier. */
2133        public String JavaDoc getPublicId() {
2134            return fLocator.getPublicId();
2135        }
2136        
2137        /** System identifier. */
2138        public String JavaDoc getSystemId() {
2139            return fLocator.getExpandedSystemId();
2140        }
2141        /** Line number. */
2142        public int getLineNumber() {
2143            return fLocator.getLineNumber();
2144        }
2145        
2146        /** Column number. */
2147        public int getColumnNumber() {
2148            return fLocator.getColumnNumber();
2149        }
2150        
2151        // Locator2 methods
2152
public String JavaDoc getXMLVersion() {
2153            return fVersion;
2154        }
2155        
2156        public String JavaDoc getEncoding() {
2157            return fLocator.getEncoding();
2158        }
2159        
2160    } // class LocatorProxy
2161

2162    protected static final class AttributesProxy
2163    implements AttributeList JavaDoc, Attributes2 JavaDoc {
2164        
2165        //
2166
// Data
2167
//
2168

2169        /** XML attributes. */
2170        protected XMLAttributes fAttributes;
2171        
2172        //
2173
// Public methods
2174
//
2175

2176        /** Sets the XML attributes. */
2177        public void setAttributes(XMLAttributes attributes) {
2178            fAttributes = attributes;
2179        } // setAttributes(XMLAttributes)
2180

2181        public int getLength() {
2182            return fAttributes.getLength();
2183        }
2184        
2185        public String JavaDoc getName(int i) {
2186            return fAttributes.getQName(i);
2187        }
2188        
2189        public String JavaDoc getQName(int index) {
2190            return fAttributes.getQName(index);
2191        }
2192        
2193        public String JavaDoc getURI(int index) {
2194            // REVISIT: this hides the fact that internally we use
2195
// null instead of empty string
2196
// SAX requires URI to be a string or an empty string
2197
String JavaDoc uri= fAttributes.getURI(index);
2198            return uri != null ? uri : "";
2199        }
2200        
2201        public String JavaDoc getLocalName(int index) {
2202            return fAttributes.getLocalName(index);
2203        }
2204        
2205        public String JavaDoc getType(int i) {
2206            return fAttributes.getType(i);
2207        }
2208        
2209        public String JavaDoc getType(String JavaDoc name) {
2210            return fAttributes.getType(name);
2211        }
2212        
2213        public String JavaDoc getType(String JavaDoc uri, String JavaDoc localName) {
2214            return uri.equals("") ? fAttributes.getType(null, localName) :
2215                fAttributes.getType(uri, localName);
2216        }
2217        
2218        public String JavaDoc getValue(int i) {
2219            return fAttributes.getValue(i);
2220        }
2221        
2222        public String JavaDoc getValue(String JavaDoc name) {
2223            return fAttributes.getValue(name);
2224        }
2225        
2226        public String JavaDoc getValue(String JavaDoc uri, String JavaDoc localName) {
2227            return uri.equals("") ? fAttributes.getValue(null, localName) :
2228                fAttributes.getValue(uri, localName);
2229        }
2230        
2231        public int getIndex(String JavaDoc qName) {
2232            return fAttributes.getIndex(qName);
2233        }
2234        
2235        public int getIndex(String JavaDoc uri, String JavaDoc localPart) {
2236            return uri.equals("") ? fAttributes.getIndex(null, localPart) :
2237                fAttributes.getIndex(uri, localPart);
2238        }
2239        
2240        // Attributes2 methods
2241
// REVISIT: Localize exception messages. -- mrglavas
2242
public boolean isDeclared(int index) {
2243            if (index < 0 || index >= fAttributes.getLength()) {
2244                throw new ArrayIndexOutOfBoundsException JavaDoc(index);
2245            }
2246            return Boolean.TRUE.equals(
2247            fAttributes.getAugmentations(index).getItem(
2248            Constants.ATTRIBUTE_DECLARED));
2249        }
2250        
2251        public boolean isDeclared(String JavaDoc qName) {
2252            int index = getIndex(qName);
2253            if (index == -1) {
2254                throw new IllegalArgumentException JavaDoc(qName);
2255            }
2256            return Boolean.TRUE.equals(
2257            fAttributes.getAugmentations(index).getItem(
2258            Constants.ATTRIBUTE_DECLARED));
2259        }
2260        
2261        public boolean isDeclared(String JavaDoc uri, String JavaDoc localName) {
2262            int index = getIndex(uri, localName);
2263            if (index == -1) {
2264                throw new IllegalArgumentException JavaDoc(localName);
2265            }
2266            return Boolean.TRUE.equals(
2267            fAttributes.getAugmentations(index).getItem(
2268            Constants.ATTRIBUTE_DECLARED));
2269        }
2270        
2271        public boolean isSpecified(int index) {
2272            if (index < 0 || index >= fAttributes.getLength()) {
2273                throw new ArrayIndexOutOfBoundsException JavaDoc(index);
2274            }
2275            return fAttributes.isSpecified(index);
2276        }
2277        
2278        public boolean isSpecified(String JavaDoc qName) {
2279            int index = getIndex(qName);
2280            if (index == -1) {
2281                throw new IllegalArgumentException JavaDoc(qName);
2282            }
2283            return fAttributes.isSpecified(index);
2284        }
2285        
2286        public boolean isSpecified(String JavaDoc uri, String JavaDoc localName) {
2287            int index = getIndex(uri, localName);
2288            if (index == -1) {
2289                throw new IllegalArgumentException JavaDoc(localName);
2290            }
2291            return fAttributes.isSpecified(index);
2292        }
2293        
2294    } // class AttributesProxy
2295

2296    
2297    // PSVIProvider methods
2298

2299    public ElementPSVI getElementPSVI(){
2300        return (fAugmentations != null)?(ElementPSVI)fAugmentations.getItem(Constants.ELEMENT_PSVI):null;
2301    }
2302    
2303    
2304    public AttributePSVI getAttributePSVI(int index){
2305        
2306        return (AttributePSVI)fAttributesProxy.fAttributes.getAugmentations(index).getItem(Constants.ATTRIBUTE_PSVI);
2307    }
2308    
2309    
2310    public AttributePSVI getAttributePSVIByName(String JavaDoc uri,
2311    String JavaDoc localname){
2312        return (AttributePSVI)fAttributesProxy.fAttributes.getAugmentations(uri, localname).getItem(Constants.ATTRIBUTE_PSVI);
2313    }
2314    
2315} // class AbstractSAXParser
2316
Popular Tags