KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > apache > xerces > parsers > SAXParser


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

57
58 package org.enhydra.apache.xerces.parsers;
59
60 import org.enhydra.apache.xerces.framework.XMLAttrList;
61 import org.enhydra.apache.xerces.framework.XMLContentSpec;
62 import org.enhydra.apache.xerces.framework.XMLDocumentHandler;
63 import org.enhydra.apache.xerces.framework.XMLParser;
64 import org.enhydra.apache.xerces.readers.XMLEntityHandler;
65 import org.enhydra.apache.xerces.utils.QName;
66 import org.enhydra.apache.xerces.utils.StringPool;
67 import org.enhydra.apache.xerces.validators.common.XMLAttributeDecl;
68 import org.enhydra.apache.xerces.validators.common.XMLElementDecl;
69 import org.xml.sax.AttributeList JavaDoc;
70 import org.xml.sax.ContentHandler JavaDoc;
71 import org.xml.sax.DocumentHandler JavaDoc;
72 import org.xml.sax.Parser JavaDoc;
73 import org.xml.sax.SAXException JavaDoc;
74 import org.xml.sax.SAXNotRecognizedException JavaDoc;
75 import org.xml.sax.SAXNotSupportedException JavaDoc;
76 import org.xml.sax.XMLReader JavaDoc;
77 import org.xml.sax.ext.DeclHandler JavaDoc;
78 import org.xml.sax.ext.LexicalHandler JavaDoc;
79 import org.xml.sax.helpers.AttributesImpl JavaDoc;
80
81 // REVISIT: [SAX2beta] ContentHandler#skippedEntity(String)
82

83 /**
84  * SAXParser provides a parser which implements the SAX1 and SAX2
85  * parser APIs.
86  *
87  * @version $Id: SAXParser.java,v 1.2 2005/01/26 08:28:44 jkjome Exp $
88  */

89 public class SAXParser
90     extends XMLParser
91     implements XMLDocumentHandler, XMLDocumentHandler.DTDHandler,
92                Parser, XMLReader JavaDoc {
93
94     //
95
// Constants
96
//
97

98     // private
99

100     /** Features recognized by this parser. */
101     private static final String JavaDoc RECOGNIZED_FEATURES[] = {
102         // SAX2 core
103
/*"http://xml.org/sax/features/normalize-text",*/
104         /*"http://xml.org/sax/features/use-locator",*/
105         "http://xml.org/sax/features/namespace-prefixes",
106         "http://xml.org/sax/features/string-interning",
107         // Xerces
108
};
109
110     /** Properties recognized by this parser. */
111     private static final String JavaDoc RECOGNIZED_PROPERTIES[] = {
112         // SAX2 core
113
"http://xml.org/sax/properties/lexical-handler",
114         "http://xml.org/sax/properties/declaration-handler",
115         "http://xml.org/sax/properties/dom-node",
116         // Xerces
117
};
118
119     // debugging
120

121     /** Set to true and recompile to debug callbacks. */
122     private static final boolean DEBUG_CALLBACKS = false;
123
124     //
125
// Data
126
//
127

128     // parser handlers
129

130     /** Document handler. */
131     private DocumentHandler fDocumentHandler;
132
133     // parser/xmlreader handlers
134

135     /** DTD handler. */
136     private org.xml.sax.DTDHandler JavaDoc fDTDHandler;
137
138     // xmlreader handlers
139

140     /** Content handler. */
141     private ContentHandler JavaDoc fContentHandler;
142
143     /** Decl handler. */
144     private DeclHandler JavaDoc fDeclHandler;
145
146     /** Lexical handler. */
147     private LexicalHandler JavaDoc fLexicalHandler;
148     
149     private boolean fNamespacePrefixes = false;
150
151     // temp
152

153     private transient AttributesImpl JavaDoc fAttributes = new AttributesImpl JavaDoc();
154
155     //
156
// Constructors
157
//
158

159     /** Default constructor. */
160     public SAXParser() {
161         initHandlers(true, this, this);
162     }
163
164     protected SAXParser(StringPool stringPool) {
165         super(stringPool);
166         initHandlers(true, this, this);
167     }
168
169     //
170
// Public methods
171
//
172

173     // features and properties
174

175     /**
176      * Returns a list of features that this parser recognizes.
177      * This method will never return null; if no features are
178      * recognized, this method will return a zero length array.
179      *
180      * @see #isFeatureRecognized
181      * @see #setFeature
182      * @see #getFeature
183      */

184     public String JavaDoc[] getFeaturesRecognized() {
185
186         // get features that super/this recognizes
187
String JavaDoc superRecognized[] = super.getFeaturesRecognized();
188         String JavaDoc thisRecognized[] = RECOGNIZED_FEATURES;
189
190         // is one or the other the empty set?
191
int thisLength = thisRecognized.length;
192         if (thisLength == 0) {
193             return superRecognized;
194         }
195         int superLength = superRecognized.length;
196         if (superLength == 0) {
197             return thisRecognized;
198         }
199
200         // combine the two lists and return
201
String JavaDoc recognized[] = new String JavaDoc[superLength + thisLength];
202         System.arraycopy(superRecognized, 0, recognized, 0, superLength);
203         System.arraycopy(thisRecognized, 0, recognized, superLength, thisLength);
204         return recognized;
205
206     } // getFeaturesRecognized():String[]
207

208     /**
209      * Returns a list of properties that this parser recognizes.
210      * This method will never return null; if no properties are
211      * recognized, this method will return a zero length array.
212      *
213      * @see #isPropertyRecognized
214      * @see #setProperty
215      * @see #getProperty
216      */

217     public String JavaDoc[] getPropertiesRecognized() {
218
219         // get properties that super/this recognizes
220
String JavaDoc superRecognized[] = super.getPropertiesRecognized();
221         String JavaDoc thisRecognized[] = RECOGNIZED_PROPERTIES;
222
223         // is one or the other the empty set?
224
int thisLength = thisRecognized.length;
225         if (thisLength == 0) {
226             return superRecognized;
227         }
228         int superLength = superRecognized.length;
229         if (superLength == 0) {
230             return thisRecognized;
231         }
232
233         // combine the two lists and return
234
String JavaDoc recognized[] = new String JavaDoc[superLength + thisLength];
235         System.arraycopy(superRecognized, 0, recognized, 0, superLength);
236         System.arraycopy(thisRecognized, 0, recognized, superLength, thisLength);
237         return recognized;
238
239     }
240
241     //
242
// Protected methods
243
//
244

245     // SAX2 core features
246

247     /**
248      * <b>Note: Currently, the parser does not support this feature.</b>
249      * Setting this feature to true will throw a SAXNotSupportedException.
250      * <p>
251      * Ensures that all consecutive text is returned in a single callback
252      * to the DocumentHandler.characters or DocumentHandler.ignorableWhitespace
253      * methods.
254      * <p>
255      * This method is the equivalent to the feature:
256      * <pre>
257      * http://xml.org/sax/features/normalize-text
258      * <pre>
259      *
260      * @param normalize True to normalize; false not to normalize.
261      *
262      * @see #getNormalizeText
263      * @see #setFeature
264      */

265     /*
266     protected void setNormalizeText(boolean normalize)
267         throws SAXNotRecognizedException, SAXNotSupportedException {
268         if (normalize) {
269             throw new SAXNotSupportedException("http://xml.org/sax/features/normalize-text");
270         }
271     }
272     */

273
274     /**
275      * <b>Note: This feature is always false.</b>
276      * <p>
277      * Returns true if the parser normalizes all consecutive text into
278      * a single callback to the DocumentHandler.characters or
279      * DocumentHandler.ignorableWhitespace methods.
280      *
281      * @see #setNormalizeText
282      */

283     /*
284     protected boolean getNormalizeText()
285         throws SAXNotRecognizedException, SAXNotSupportedException {
286         return false;
287     }
288     */

289
290     /**
291      * <b>Note: Currently, this parser always sets the locator.</b>
292      * Setting this feature to false will throw a SAXNotSupportedException.
293      * <p>
294      * Provide a Locator using the DocumentHandler.setDocumentLocator
295      * callback (true), or explicitly do not provide one (false).
296      * <p>
297      * This method is the equivalent to the feature:
298      * <pre>
299      * http://xml.org/sax/features/use-locator
300      * </pre>
301      *
302      * @see #getUseLocator
303      * @see #setFeature
304      */

305     /*
306     protected void setUseLocator(boolean use)
307         throws SAXNotRecognizedException, SAXNotSupportedException {
308         if (!use) {
309             throw new SAXNotSupportedException("http://xml.org/sax/features/use-locator");
310         }
311     }
312     */

313
314     /**
315      * <b>Note: This feature is always true.</b>
316      * <p>
317      * Returns true if the locator is always set.
318      *
319      * @see #setUseLocator
320      */

321     /*
322     protected boolean getUseLocator()
323         throws SAXNotRecognizedException, SAXNotSupportedException {
324         return true;
325     }
326     */

327
328     // SAX2 core properties
329

330     /**
331      * Set the DTD declaration event handler.
332      * <p>
333      * This method is the equivalent to the property:
334      * <pre>
335      * http://xml.org/sax/properties/declaration-handler
336      * </pre>
337      *
338      * @param handler The new handler.
339      *
340      * @see #getDeclHandler
341      * @see #setProperty
342      */

343     protected void setDeclHandler(DeclHandler JavaDoc handler)
344         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
345         if (fParseInProgress) {
346             throw new SAXNotSupportedException JavaDoc(
347                 "PAR011 Feature: http://xml.org/sax/properties/declaration-handler"
348                 +" is not supported during parse."
349                 +"\nhttp://xml.org/sax/properties/declaration-handler");
350         }
351         fDeclHandler = handler;
352     }
353
354     /**
355      * Returns the DTD declaration event handler.
356      *
357      * @see #setDeclHandler
358      */

359     protected DeclHandler JavaDoc getDeclHandler()
360         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
361         return fDeclHandler;
362     }
363
364     /**
365      * Set the lexical event handler.
366      * <p>
367      * This method is the equivalent to the property:
368      * <pre>
369      * http://xml.org/sax/properties/lexical-handler
370      * </pre>
371      *
372      * @param handler lexical event handler
373      *
374      * @see #getLexicalHandler
375      * @see #setProperty
376      */

377     protected void setLexicalHandler(LexicalHandler JavaDoc handler)
378         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
379         if (fParseInProgress) {
380             throw new SAXNotSupportedException JavaDoc(
381             "PAR011 Feature: http://xml.org/sax/properties/lexical-handler"
382             +" is not supported during parse."
383             +"\nhttp://xml.org/sax/properties/lexical-handler");
384         }
385         fLexicalHandler = handler;
386     }
387
388     /**
389      * Returns the lexical handler.
390      *
391      * @see #setLexicalHandler
392      */

393     protected LexicalHandler JavaDoc getLexicalHandler()
394         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
395         return fLexicalHandler;
396     }
397
398     //
399
// Parser methods
400
//
401

402     /** Sets the document handler. */
403     public void setDocumentHandler(DocumentHandler handler) {
404         fDocumentHandler = handler;
405     }
406
407     //
408
// Parser/XMLReader methods
409
//
410

411     /**
412      * Allow an application to register a DTD event handler.
413      *
414      * <p>If the application does not register a DTD handler, all DTD
415      * events reported by the SAX parser will be silently ignored.</p>
416      *
417      * <p>Applications may register a new or different handler in the
418      * middle of a parse, and the SAX parser must begin using the new
419      * handler immediately.</p>
420      *
421      * @param handler The DTD handler.
422      * @exception java.lang.NullPointerException If the handler
423      * argument is null.
424      * @see #getDTDHandler
425      */

426     public void setDTDHandler(org.xml.sax.DTDHandler JavaDoc handler) {
427         fDTDHandler = handler;
428     }
429
430     /**
431      * Return the current DTD handler.
432      *
433      * @return The current DTD handler, or null if none
434      * has been registered.
435      * @see #setDTDHandler
436      */

437     public org.xml.sax.DTDHandler JavaDoc getDTDHandler() {
438         return fDTDHandler;
439     }
440     
441     /**
442      * Sets how the parser reports raw prefixed names,
443      * and whether xmlns attributes are reported.
444      * <p>
445      * This method is the equivalent to the feature:
446      * <pre>
447      * http://xml.org/sax/features/namespaces-prefixes
448      * <pre>
449      *
450      * @param process True to process namespaces; false to not process.
451      *
452      * @see #getNamespaces
453      * @see #setFeature
454      */

455     protected void setNamespacePrefixes(boolean process)
456         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
457         if (fParseInProgress) {
458             throw new SAXNotSupportedException JavaDoc("PAR004 Cannot setFeature(http://xml.org/sax/features/namespace-prefixes): parse is in progress.\n"+
459                                                "http://xml.org/sax/features/namespace-prefixes");
460         }
461         fNamespacePrefixes = process;
462     }
463
464     /**
465      * Returns the http://xml.org/features/namespace-prefixes
466      * value.
467      *
468      * @see #setNamespacePrefixes
469      */

470     protected boolean getNamespacePrefixes()
471         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
472         return fNamespacePrefixes;
473     }
474     
475
476     //
477
// XMLReader methods
478
//
479

480     /**
481      * Set the state of any feature in a SAX2 parser. The parser
482      * might not recognize the feature, and if it does recognize
483      * it, it might not be able to fulfill the request.
484      *
485      * @param featureId The unique identifier (URI) of the feature.
486      * @param state The requested state of the feature (true or false).
487      *
488      * @exception SAXNotRecognizedException If the
489      * requested feature is not known.
490      * @exception SAXNotSupportedException If the
491      * requested feature is known, but the requested
492      * state is not supported.
493      */

494     public void setFeature(String JavaDoc featureId, boolean state)
495         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
496
497         //
498
// SAX2 Features
499
//
500

501         if (featureId.startsWith(SAX2_FEATURES_PREFIX)) {
502             String JavaDoc feature = featureId.substring(SAX2_FEATURES_PREFIX.length());
503
504             /*
505             //
506             // http://xml.org/sax/features/normalize-text
507             // Ensure that all consecutive text is returned in a single callback to
508             // DocumentHandler.characters or DocumentHandler.ignorableWhitespace
509             // (true) or explicitly do not require it (false).
510             //
511             if (feature.equals("normalize-text")) {
512                 setNormalizeText(state);
513                 return;
514             }
515             */

516             /*
517             //
518             // http://xml.org/sax/features/use-locator
519             // Provide a Locator using the DocumentHandler.setDocumentLocator
520             // callback (true), or explicitly do not provide one (false).
521             //
522             if (feature.equals("use-locator")) {
523                 setUseLocator(state);
524                 return;
525             }
526             */

527
528             // http://xml.org/sax/features/namespace-prefixes
529
// controls the reporting of raw prefixed names and Namespace
530
// declarations (xmlns* attributes): when this feature is false
531
// (the default), raw prefixed names may optionally be reported,
532
// and xmlns* attributes must not be reported.
533
//
534
if (feature.equals("namespace-prefixes")) {
535                 setNamespacePrefixes(state);
536                 return;
537             }
538             // http://xml.org/sax/features/string-interning
539
// controls the use of java.lang.String#intern() for strings
540
// passed to SAX handlers.
541
//
542
if (feature.equals("string-interning")) {
543                 if (state) {
544                     throw new SAXNotSupportedException JavaDoc(
545                         "PAR018 "+state+" state for feature \""+featureId+"\" is not supported.\n"+
546                         state+'\t'+featureId
547                         );
548                 }
549                 return;
550             }
551    
552             //
553
// Drop through and perform default processing
554
//
555
}
556
557         //
558
// Xerces Features
559
//
560

561         /*
562         else if (featureId.startsWith(XERCES_FEATURES_PREFIX)) {
563             String feature = featureId.substring(XERCES_FEATURES_PREFIX.length());
564             //
565             // Drop through and perform default processing
566             //
567         }
568         */

569
570         //
571
// Perform default processing
572
//
573

574         super.setFeature(featureId, state);
575
576     } // setFeature(String,boolean)
577

578     /**
579      * Query the state of a feature.
580      *
581      * Query the current state of any feature in a SAX2 parser. The
582      * parser might not recognize the feature.
583      *
584      * @param featureId The unique identifier (URI) of the feature
585      * being set.
586      * @return The current state of the feature.
587      * @exception org.xml.sax.SAXNotRecognizedException If the
588      * requested feature is not known.
589      * @exception SAXNotSupportedException If the
590      * requested feature is known but not supported.
591      */

592     public boolean getFeature(String JavaDoc featureId)
593         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
594
595         //
596
// SAX2 Features
597
//
598

599         if (featureId.startsWith(SAX2_FEATURES_PREFIX)) {
600             String JavaDoc feature = featureId.substring(SAX2_FEATURES_PREFIX.length());
601
602             /*
603             //
604             // http://xml.org/sax/features/normalize-text
605             // Ensure that all consecutive text is returned in a single callback to
606             // DocumentHandler.characters or DocumentHandler.ignorableWhitespace
607             // (true) or explicitly do not require it (false).
608             //
609             if (feature.equals("normalize-text")) {
610                 return getNormalizeText();
611             }
612             */

613             /*
614             //
615             // http://xml.org/sax/features/use-locator
616             // Provide a Locator using the DocumentHandler.setDocumentLocator
617             // callback (true), or explicitly do not provide one (false).
618             //
619             if (feature.equals("use-locator")) {
620                 return getUseLocator();
621             }
622             */

623
624             // http://xml.org/sax/features/namespace-prefixes
625
// controls the reporting of raw prefixed names and Namespace
626
// declarations (xmlns* attributes): when this feature is false
627
// (the default), raw prefixed names may optionally be reported,
628
// and xmlns* attributes must not be reported.
629
//
630
if (feature.equals("namespace-prefixes")) {
631                 return getNamespacePrefixes();
632             }
633             // http://xml.org/sax/features/string-interning
634
// controls the use of java.lang.String#intern() for strings
635
// passed to SAX handlers.
636
//
637
if (feature.equals("string-interning")) {
638                 return false;
639             }
640
641             //
642
// Drop through and perform default processing
643
//
644
}
645
646         //
647
// Xerces Features
648
//
649

650         /*
651         else if (featureId.startsWith(XERCES_FEATURES_PREFIX)) {
652             //
653             // Drop through and perform default processing
654             //
655         }
656         */

657
658         //
659
// Perform default processing
660
//
661

662         return super.getFeature(featureId);
663
664     } // getFeature(String):boolean
665

666     /**
667      * Set the value of any property in a SAX2 parser. The parser
668      * might not recognize the property, and if it does recognize
669      * it, it might not support the requested value.
670      *
671      * @param propertyId The unique identifier (URI) of the property
672      * being set.
673      * @param Object The value to which the property is being set.
674      *
675      * @exception SAXNotRecognizedException If the
676      * requested property is not known.
677      * @exception SAXNotSupportedException If the
678      * requested property is known, but the requested
679      * value is not supported.
680      */

681     public void setProperty(String JavaDoc propertyId, Object JavaDoc value)
682         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
683
684         //
685
// SAX2 core properties
686
//
687

688         if (propertyId.startsWith(SAX2_PROPERTIES_PREFIX)) {
689             String JavaDoc property = propertyId.substring(SAX2_PROPERTIES_PREFIX.length());
690             //
691
// http://xml.org/sax/properties/lexical-handler
692
// Value type: org.xml.sax.ext.LexicalHandler
693
// Access: read/write, pre-parse only
694
// Set the lexical event handler.
695
//
696
if (property.equals("lexical-handler")) {
697                 try {
698                     setLexicalHandler((LexicalHandler JavaDoc)value);
699                 }
700                 catch (ClassCastException JavaDoc e) {
701                     throw new SAXNotSupportedException JavaDoc(
702                     "PAR012 For propertyID \""
703                     +propertyId+"\", the value \""
704                     +value+"\" cannot be cast to LexicalHandler."
705                     +'\n'+propertyId+'\t'+value+"\tLexicalHandler");
706                 }
707                 return;
708             }
709             //
710
// http://xml.org/sax/properties/declaration-handler
711
// Value type: org.xml.sax.ext.DeclHandler
712
// Access: read/write, pre-parse only
713
// Set the DTD declaration event handler.
714
//
715
if (property.equals("declaration-handler")) {
716                 try {
717                     setDeclHandler((DeclHandler JavaDoc)value);
718                 }
719                 catch (ClassCastException JavaDoc e) {
720                     throw new SAXNotSupportedException JavaDoc(
721                     "PAR012 For propertyID \""
722                     +propertyId+"\", the value \""
723                     +value+"\" cannot be cast to DeclHandler."
724                     +'\n'+propertyId+'\t'+value+"\tDeclHandler"
725                     );
726                 }
727                 return;
728             }
729             //
730
// http://xml.org/sax/properties/dom-node
731
// Value type: DOM Node
732
// Access: read-only
733
// Get the DOM node currently being visited, if the SAX parser is
734
// iterating over a DOM tree. If the parser recognises and supports
735
// this property but is not currently visiting a DOM node, it should
736
// return null (this is a good way to check for availability before the
737
// parse begins).
738
//
739
if (property.equals("dom-node")) {
740                 throw new SAXNotSupportedException JavaDoc(
741                     "PAR013 Property \""+propertyId+"\" is read only."
742                     +'\n'+propertyId
743                     ); // read-only property
744
}
745             //
746
// Drop through and perform default processing
747
//
748
}
749
750         //
751
// Xerces Properties
752
//
753

754         /*
755         else if (propertyId.startsWith(XERCES_PROPERTIES_PREFIX)) {
756             //
757             // Drop through and perform default processing
758             //
759         }
760         */

761
762         //
763
// Perform default processing
764
//
765

766         super.setProperty(propertyId, value);
767
768     } // setProperty(String,Object)
769

770     /**
771      * Query the value of a property.
772      *
773      * Return the current value of a property in a SAX2 parser.
774      * The parser might not recognize the property.
775      *
776      * @param propertyId The unique identifier (URI) of the property
777      * being set.
778      * @return The current value of the property.
779      * @exception org.xml.sax.SAXNotRecognizedException If the
780      * requested property is not known.
781      * @exception SAXNotSupportedException If the
782      * requested property is known but not supported.
783      */

784     public Object JavaDoc getProperty(String JavaDoc propertyId)
785         throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc {
786
787         //
788
// SAX2 core properties
789
//
790

791         if (propertyId.startsWith(SAX2_PROPERTIES_PREFIX)) {
792             String JavaDoc property = propertyId.substring(SAX2_PROPERTIES_PREFIX.length());
793             //
794
// http://xml.org/sax/properties/lexical-handler
795
// Value type: org.xml.sax.ext.LexicalHandler
796
// Access: read/write, pre-parse only
797
// Set the lexical event handler.
798
//
799
if (property.equals("lexical-handler")) {
800                 return getLexicalHandler();
801             }
802             //
803
// http://xml.org/sax/properties/declaration-handler
804
// Value type: org.xml.sax.ext.DeclHandler
805
// Access: read/write, pre-parse only
806
// Set the DTD declaration event handler.
807
//
808
if (property.equals("declaration-handler")) {
809                 return getDeclHandler();
810             }
811             //
812
// http://xml.org/sax/properties/dom-node
813
// Value type: DOM Node
814
// Access: read-only
815
// Get the DOM node currently being visited, if the SAX parser is
816
// iterating over a DOM tree. If the parser recognises and supports
817
// this property but is not currently visiting a DOM node, it should
818
// return null (this is a good way to check for availability before the
819
// parse begins).
820
//
821
if (property.equals("dom-node")) {
822                 throw new SAXNotSupportedException JavaDoc(
823                 "PAR014 Cannot getProperty(\""+propertyId
824                 +"\". No DOM Tree exists.\n"+propertyId
825                 ); // we are not iterating a DOM tree
826
}
827             //
828
// Drop through and perform default processing
829
//
830
}
831
832         //
833
// Xerces properties
834
//
835

836         /*
837         else if (propertyId.startsWith(XERCES_PROPERTIES_PREFIX)) {
838             //
839             // Drop through and perform default processing
840             //
841         }
842         */

843
844         //
845
// Perform default processing
846
//
847

848         return super.getProperty(propertyId);
849
850     } // getProperty(String):Object
851

852     /**
853      * Allow an application to register a content event handler.
854      *
855      * <p>If the application does not register a content handler, all
856      * content events reported by the SAX parser will be silently
857      * ignored.</p>
858      *
859      * <p>Applications may register a new or different handler in the
860      * middle of a parse, and the SAX parser must begin using the new
861      * handler immediately.</p>
862      *
863      * @param handler The content handler.
864      * @exception java.lang.NullPointerException If the handler
865      * argument is null.
866      * @see #getContentHandler
867      */

868     public void setContentHandler(ContentHandler JavaDoc handler) {
869         if (handler == null) {
870             throw new NullPointerException JavaDoc();
871         }
872         fContentHandler = handler;
873     }
874
875     /**
876      * Return the current content handler.
877      *
878      * @return The current content handler, or null if none
879      * has been registered.
880      * @see #setContentHandler
881      */

882     public ContentHandler JavaDoc getContentHandler() {
883         return fContentHandler;
884     }
885
886     //
887
// XMLParser methods
888
//
889

890     /**
891      * This function will be called when a &lt;!DOCTYPE...&gt; declaration is
892      * encountered.
893      */

894     public void startDTD(QName rootElement, int publicId, int systemId) throws Exception JavaDoc {
895         if (fLexicalHandler != null || DEBUG_CALLBACKS) {
896
897             // strings
898
String JavaDoc name = fStringPool.toString(rootElement.rawname);
899             String JavaDoc pubid = fStringPool.toString(publicId);
900             String JavaDoc sysid = fStringPool.toString(systemId);
901
902             // perform callback
903
if (DEBUG_CALLBACKS) {
904                 System.err.println("startDTD(" + name + ", " + pubid + ", " + sysid + ")");
905             }
906             if (fLexicalHandler != null) {
907                 fLexicalHandler.startDTD(name, pubid, sysid);
908             }
909         }
910     }
911
912     /**
913      * This function will be called at the end of the DTD.
914      */

915     public void endDTD() throws Exception JavaDoc {
916         if (DEBUG_CALLBACKS) {
917             System.err.println("endDTD()");
918         }
919         if (fLexicalHandler != null) {
920             fLexicalHandler.endDTD();
921         }
922     }
923
924     /**
925      * Report an element type declaration.
926      *
927      * The content model will consist of the string "EMPTY", the
928      * string "ANY", or a parenthesised group, optionally followed
929      * by an occurrence indicator. The model will be normalized so
930      * that all whitespace is removed.
931      *
932      * @param name The element type name.
933      * @param model The content model as a normalized string.
934      * @exception SAXException The application may raise an exception.
935      */

936     public void elementDecl(QName elementDecl,
937                             int contentSpecType,
938                             int contentSpecIndex,
939                             XMLContentSpec.Provider contentSpecProvider) throws Exception JavaDoc {
940
941         if (fDeclHandler != null || DEBUG_CALLBACKS) {
942
943             // strings
944
String JavaDoc name = fStringPool.toString(elementDecl.rawname);
945             String JavaDoc contentModel;
946             if (contentSpecType == XMLElementDecl.TYPE_ANY) {
947                 contentModel = "ANY";
948             }
949             else if (contentSpecType == XMLElementDecl.TYPE_EMPTY) {
950                 contentModel = "EMPTY";
951             }
952             else {
953                 contentModel = XMLContentSpec.toString(contentSpecProvider,
954                                                        fStringPool,
955                                                        contentSpecIndex);
956             }
957
958             // perform callback
959
if (DEBUG_CALLBACKS) {
960                 System.err.println("elementDecl(" + name + ", " + contentModel + ")");
961             }
962             if (fDeclHandler != null) {
963                 fDeclHandler.elementDecl(name, contentModel);
964             }
965         }
966
967     }
968
969     /**
970      * Report an attribute type declaration.
971      *
972      * Only the effective (first) declaration for an attribute will
973      * be reported. The type will be one of the strings "CDATA",
974      * "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY",
975      * "ENTITIES", or "NOTATION", or a parenthesized token group with
976      * the separator "|" and all whitespace removed.
977      *
978      * @param eName The name of the associated element.
979      * @param aName The name of the attribute.
980      * @param type A string representing the attribute type.
981      * @param valueDefault A string representing the attribute default
982      * ("#IMPLIED", "#REQUIRED", or "#FIXED") or null if
983      * none of these applies.
984      * @param value A string representing the attribute's default value,
985      * or null if there is none.
986      * @exception SAXException The application may raise an exception.
987      */

988     public void attlistDecl(QName elementDecl, QName attributeDecl,
989                             int attType, boolean attList, String JavaDoc enumString,
990                             int attDefaultType,
991                             int attDefaultValue) throws Exception JavaDoc
992     {
993         if (fDeclHandler != null || DEBUG_CALLBACKS) {
994
995             // strings
996
String JavaDoc eName = fStringPool.toString(elementDecl.rawname);
997             String JavaDoc aName = fStringPool.toString(attributeDecl.rawname);
998             String JavaDoc aType = enumString;
999             if (attType != XMLAttributeDecl.TYPE_ENUMERATION) {
1000                switch (attType) {
1001                    case XMLAttributeDecl.TYPE_CDATA: {
1002                        aType = "CDATA";
1003                        break;
1004                    }
1005                    case XMLAttributeDecl.TYPE_ENTITY: {
1006                        aType = attList ? "ENTITIES" : "ENTITY";
1007                        break;
1008                    }
1009                    case XMLAttributeDecl.TYPE_ID: {
1010                        aType = "ID";
1011                        break;
1012                    }
1013                    case XMLAttributeDecl.TYPE_IDREF: {
1014                        aType = attList ? "IDREFS" : "IDREF";
1015                        break;
1016                    }
1017                    case XMLAttributeDecl.TYPE_NMTOKEN: {
1018                        aType = attList ? "NMTOKENS" : "NMTOKEN";
1019                        break;
1020                    }
1021                    case XMLAttributeDecl.TYPE_NOTATION: {
1022                        aType = "NOTATION "+enumString;
1023                        break;
1024                    }
1025                }
1026            }
1027            String JavaDoc aDefaultType = null;
1028            switch (attDefaultType) {
1029                case XMLAttributeDecl.DEFAULT_TYPE_FIXED: {
1030                    aDefaultType = "#FIXED";
1031                    break;
1032                }
1033                case XMLAttributeDecl.DEFAULT_TYPE_IMPLIED: {
1034                    aDefaultType = "#IMPLIED";
1035                    break;
1036                }
1037                case XMLAttributeDecl.DEFAULT_TYPE_REQUIRED: {
1038                    aDefaultType = "#REQUIRED";
1039                    break;
1040                }
1041            }
1042            String JavaDoc aDefaultValue = fStringPool.toString(attDefaultValue);
1043
1044            // perform callback
1045
if (DEBUG_CALLBACKS) {
1046                System.err.println("attributeDecl(" +
1047                                    eName + ", " +
1048                                    aName + ", " +
1049                                    aType + ", " +
1050                                    aDefaultType + ", " +
1051                                    aDefaultValue + ")");
1052            }
1053            if (fDeclHandler != null) {
1054                fDeclHandler.attributeDecl(eName, aName, aType, aDefaultType, aDefaultValue);
1055            }
1056        }
1057    }
1058
1059    /**
1060     * Report an internal parameter entity declaration.
1061     */

1062    public void internalPEDecl(int entityName, int entityValue) throws Exception JavaDoc {
1063
1064        if (fDeclHandler != null || DEBUG_CALLBACKS) {
1065
1066            // strings
1067
String JavaDoc name = "%" + fStringPool.toString(entityName);
1068            String JavaDoc value = fStringPool.toString(entityValue);
1069
1070            // perform callback
1071
if (DEBUG_CALLBACKS) {
1072                System.err.println("internalEntityDecl(" + name + ", " + value + ")");
1073            }
1074            if (fDeclHandler != null) {
1075                fDeclHandler.internalEntityDecl(name, value);
1076            }
1077        }
1078
1079    }
1080
1081    /**
1082     * Report a parsed external parameter entity declaration.
1083     */

1084    public void externalPEDecl(int entityName, int publicId, int systemId) throws Exception JavaDoc {
1085
1086        if (fDeclHandler != null || DEBUG_CALLBACKS) {
1087
1088            // strings
1089
String JavaDoc name = "%" + fStringPool.toString(entityName);
1090            String JavaDoc pubid = fStringPool.toString(publicId);
1091            String JavaDoc sysid = fStringPool.toString(systemId);
1092
1093            // perform callback
1094
if (DEBUG_CALLBACKS) {
1095                System.err.println("externalEntityDecl(" + name + ", " + pubid + ", " + sysid + ")");
1096            }
1097            if (fDeclHandler != null) {
1098                fDeclHandler.externalEntityDecl(name, pubid, sysid);
1099            }
1100        }
1101
1102    }
1103
1104    /**
1105     * Report an internal general entity declaration.
1106     */

1107    public void internalEntityDecl(int entityName, int entityValue) throws Exception JavaDoc {
1108
1109        if (fDeclHandler != null || DEBUG_CALLBACKS) {
1110
1111            // strings
1112
String JavaDoc name = fStringPool.toString(entityName);
1113            String JavaDoc value = fStringPool.toString(entityValue);
1114
1115            // perform callback
1116
if (DEBUG_CALLBACKS) {
1117                System.err.println("internalEntityDecl(" + name + ", " + value + ")");
1118            }
1119            if (fDeclHandler != null) {
1120                fDeclHandler.internalEntityDecl(name, value);
1121            }
1122        }
1123
1124    }
1125
1126    /**
1127     * Report a parsed external general entity declaration.
1128     */

1129    public void externalEntityDecl(int entityName, int publicId, int systemId) throws Exception JavaDoc {
1130
1131        if (fDeclHandler != null || DEBUG_CALLBACKS) {
1132
1133            // strings
1134
String JavaDoc name = fStringPool.toString(entityName);
1135            String JavaDoc pubid = fStringPool.toString(publicId);
1136            String JavaDoc sysid = fStringPool.toString(systemId);
1137
1138            // perform callback
1139
if (DEBUG_CALLBACKS) {
1140                System.err.println("externalEntityDecl(" + name + ", " + pubid + ", " + sysid + ")");
1141            }
1142            if (fDeclHandler != null) {
1143                fDeclHandler.externalEntityDecl(name, pubid, sysid);
1144            }
1145        }
1146
1147    }
1148
1149    /**
1150     * Receive notification of an unparsed entity declaration event.
1151     */

1152    public void unparsedEntityDecl(int entityName, int publicId, int systemId, int notationName) throws Exception JavaDoc {
1153
1154        if (fDTDHandler != null || DEBUG_CALLBACKS) {
1155
1156            // strings
1157
String JavaDoc name = fStringPool.toString(entityName);
1158            String JavaDoc pubid = fStringPool.toString(publicId);
1159            String JavaDoc sysid = fStringPool.toString(systemId);
1160            String JavaDoc notation = fStringPool.toString(notationName);
1161
1162            // perform callback
1163
if (DEBUG_CALLBACKS) {
1164                System.err.println("unparsedEntityDecl(" + name + ", " + pubid + ", " + sysid + ", " + notation + ")");
1165            }
1166            if (fDTDHandler != null) {
1167                fDTDHandler.unparsedEntityDecl(name, pubid, sysid, notation);
1168            }
1169        }
1170
1171    }
1172
1173    /**
1174     * Receive notification of a notation declaration event.
1175     */

1176    public void notationDecl(int notationName, int publicId, int systemId) throws Exception JavaDoc {
1177
1178        if (fDTDHandler != null || DEBUG_CALLBACKS) {
1179
1180            // strings
1181
String JavaDoc name = fStringPool.toString(notationName);
1182            String JavaDoc pubid = fStringPool.toString(publicId);
1183            String JavaDoc sysid = fStringPool.toString(systemId);
1184
1185            // perform callback
1186
if (DEBUG_CALLBACKS) {
1187                System.err.println("notationDecl(" + name + ", " + pubid + ", " + sysid + ")");
1188            }
1189            if (fDTDHandler != null) {
1190                fDTDHandler.notationDecl(name, pubid, sysid);
1191            }
1192        }
1193
1194    }
1195
1196    /** Start document. */
1197    public void startDocument() throws Exception JavaDoc {
1198
1199        // perform callbacks
1200
if (DEBUG_CALLBACKS) {
1201            System.err.println("setDocumentLocator(<locator>)");
1202            System.err.println("startDocument()");
1203        }
1204        if (fDocumentHandler != null) {
1205            fDocumentHandler.setDocumentLocator(getLocator());
1206            fDocumentHandler.startDocument();
1207        }
1208        if (fContentHandler != null) {
1209            fContentHandler.setDocumentLocator(getLocator());
1210            fContentHandler.startDocument();
1211        }
1212
1213    } // startDocument()
1214

1215    /** End document. */
1216    public void endDocument() throws Exception JavaDoc {
1217
1218        // perform callback
1219
if (DEBUG_CALLBACKS) {
1220            System.err.println("endDocument()");
1221        }
1222        if (fDocumentHandler != null) {
1223            fDocumentHandler.endDocument();
1224        }
1225        if (fContentHandler != null) {
1226            fContentHandler.endDocument();
1227        }
1228
1229    } // endDocument()
1230

1231    /** XML declaration. */
1232    public void xmlDecl(int versionIndex, int encodingIndex, int standaloneIndex) throws Exception JavaDoc {
1233
1234        // perform callbacks
1235
if (DEBUG_CALLBACKS) {
1236            String JavaDoc notes = "";
1237            if (versionIndex != -1)
1238                notes += " version='" + fStringPool.toString(versionIndex) + "'";
1239            if (encodingIndex != -1)
1240                notes += " encoding='" + fStringPool.toString(encodingIndex) + "'";
1241            if (standaloneIndex != -1)
1242                notes += " standalone='" + fStringPool.toString(standaloneIndex) + "'";
1243            System.err.println("xmlDecl(<?xml" + notes + "?>)");
1244        }
1245
1246        // release strings
1247
fStringPool.releaseString(versionIndex);
1248        fStringPool.releaseString(encodingIndex);
1249        fStringPool.releaseString(standaloneIndex);
1250
1251    }
1252
1253    /** Text declaration. */
1254    public void textDecl(int versionIndex, int encodingIndex) throws Exception JavaDoc {
1255
1256        // perform callbacks
1257
if (DEBUG_CALLBACKS) {
1258            String JavaDoc notes = "";
1259            if (versionIndex != -1)
1260                notes += " version='" + fStringPool.toString(versionIndex) + "'";
1261            if (encodingIndex != -1)
1262                notes += " encoding='" + fStringPool.toString(encodingIndex) + "'";
1263            System.err.println("textDecl(<?xml" + notes + "?>)");
1264        }
1265
1266        // release strings
1267
fStringPool.releaseString(versionIndex);
1268        fStringPool.releaseString(encodingIndex);
1269    }
1270
1271    /**
1272     * Report the start of the scope of a namespace declaration.
1273     */

1274    public void startNamespaceDeclScope(int prefix, int uri) throws Exception JavaDoc {
1275
1276        if (fContentHandler != null || DEBUG_CALLBACKS) {
1277
1278            // strings
1279
String JavaDoc p = fStringPool.toString(prefix);
1280            String JavaDoc ns = fStringPool.toString(uri);
1281
1282            // perform callback
1283
if (DEBUG_CALLBACKS) {
1284                System.err.println("startNamespaceDeclScope(" + p + ", " + ns + ")");
1285            }
1286            if (fContentHandler != null) {
1287                fContentHandler.startPrefixMapping(p, ns);
1288            }
1289        }
1290
1291    }
1292
1293    /**
1294     * Report the end of the scope of a namespace declaration.
1295     */

1296    public void endNamespaceDeclScope(int prefix) throws Exception JavaDoc {
1297
1298        if (fContentHandler != null || DEBUG_CALLBACKS) {
1299
1300            // strings
1301
String JavaDoc p = fStringPool.toString(prefix);
1302
1303            // perform callback
1304
if (DEBUG_CALLBACKS) {
1305                System.err.println("endNamespaceDeclScope(" + p + ")");
1306            }
1307            if (fContentHandler != null) {
1308                fContentHandler.endPrefixMapping(p);
1309            }
1310        }
1311
1312    }
1313    
1314    /** New callback from DOM Level 2. There is no corresponding SAX callout for this yet. */
1315    public void internalSubset(int internalSubset) {
1316    }
1317
1318    /** Start element */
1319    public void startElement(QName element,
1320                             XMLAttrList attrList, int attrListIndex)
1321        throws Exception JavaDoc {
1322
1323        // parameters
1324
String JavaDoc name = fStringPool.toString(element.rawname);
1325        AttributeList JavaDoc attrs = attrList.getAttributeList(attrListIndex);
1326
1327        // perform callback
1328
if (DEBUG_CALLBACKS) {
1329            String JavaDoc atts = attrs.getLength() > 0 ? "" : " ";
1330            for (int i = 0; i < attrs.getLength(); i++) {
1331                atts += " " + attrs.getName(i) + "='" + attrs.getValue(i) + "'";
1332            }
1333            System.err.println("startElement(" + name + "," + atts + ")");
1334        }
1335        if (fDocumentHandler != null) {
1336            fDocumentHandler.startElement(name, attrs);
1337        }
1338        if (fContentHandler != null) {
1339            boolean namespaces = getNamespaces();
1340            int uriIndex = element.uri;
1341            String JavaDoc uri = uriIndex != StringPool.EMPTY_STRING && namespaces
1342                       ? fStringPool.toString(uriIndex) : "";
1343            int localIndex = element.localpart;
1344            String JavaDoc local = localIndex != -1 && namespaces
1345                         ? fStringPool.toString(localIndex) : "";
1346            String JavaDoc raw = name;
1347            fAttributes.clear();
1348            for (int attrIndex = attrList.getFirstAttr(attrListIndex);
1349                 attrIndex != -1;
1350                 attrIndex = attrList.getNextAttr(attrIndex)) {
1351                int attrNameIndex = attrList.getAttrName(attrIndex);
1352                int attrUriIndex = attrList.getAttrURI(attrIndex);
1353                String JavaDoc attrUri = attrUriIndex != -1 && namespaces
1354                               ? fStringPool.toString(attrUriIndex) : "";
1355                int attrLocalIndex = attrList.getAttrLocalpart(attrIndex);
1356                String JavaDoc attrLocal = attrLocalIndex != -1 && namespaces
1357                                 ? fStringPool.toString(attrLocalIndex) : "";
1358                String JavaDoc attrRaw = fStringPool.toString(attrNameIndex);
1359                String JavaDoc attrType = fStringPool.toString(attrList.getAttType(attrIndex));
1360                String JavaDoc attrValue = fStringPool.toString(attrList.getAttValue(attrIndex));
1361                //int attrPrefix = fStringPool.getPrefixForQName(attrNameIndex);
1362
int attrPrefix = attrList.getAttrPrefix(attrIndex);
1363                boolean namespacePrefixes = getNamespacePrefixes();
1364                if (!namespaces || namespacePrefixes ||
1365                    (attrPrefix != fStringPool.addSymbol("xmlns")
1366                    && attrLocalIndex != fStringPool.addSymbol("xmlns")
1367                    ))
1368                    fAttributes.addAttribute(attrUri, attrLocal, attrRaw,
1369                                            attrType, attrValue);
1370                    
1371            }
1372            fContentHandler.startElement(uri, local, raw, fAttributes);
1373        }
1374
1375        // free attribute list
1376
attrList.releaseAttrList(attrListIndex);
1377
1378    } // startElement(QName,XMLAttrList,int)
1379

1380    /** End element. */
1381    public void endElement(QName element) throws Exception JavaDoc {
1382
1383        // perform callback
1384
if (DEBUG_CALLBACKS) {
1385            System.err.println("endElement(" + fStringPool.toString(element.rawname) + ")");
1386        }
1387        if (fDocumentHandler != null) {
1388            fDocumentHandler.endElement(fStringPool.toString(element.rawname));
1389        }
1390        if (fContentHandler != null) {
1391            boolean namespaces = getNamespaces();
1392            int uriIndex = element.uri;
1393            String JavaDoc uri = uriIndex != StringPool.EMPTY_STRING && namespaces
1394                       ? fStringPool.toString(uriIndex) : "";
1395            int localIndex = element.localpart;
1396            String JavaDoc local = localIndex != -1 && namespaces
1397                         ? fStringPool.toString(localIndex) : "";
1398            String JavaDoc raw = fStringPool.toString(element.rawname);
1399            fContentHandler.endElement(uri, local, raw);
1400        }
1401
1402    } // endElement(QName)
1403

1404    /** Start entity reference. */
1405    public void startEntityReference(int entityName, int entityType, int entityContext) throws Exception JavaDoc {
1406        if (fLexicalHandler != null || DEBUG_CALLBACKS) {
1407            switch (entityType) {
1408            case XMLEntityHandler.ENTITYTYPE_INTERNAL_PE:
1409            case XMLEntityHandler.ENTITYTYPE_EXTERNAL_PE:
1410                if (DEBUG_CALLBACKS) {
1411                    System.err.println("startEntity(%" + fStringPool.toString(entityName) + ")");
1412                }
1413                if (fLexicalHandler != null) {
1414                    fLexicalHandler.startEntity("%" + fStringPool.toString(entityName));
1415                }
1416                break;
1417            case XMLEntityHandler.ENTITYTYPE_INTERNAL:
1418            case XMLEntityHandler.ENTITYTYPE_EXTERNAL:
1419                if (DEBUG_CALLBACKS) {
1420                    System.err.println("startEntity(" + fStringPool.toString(entityName) + ")");
1421                }
1422                if (fLexicalHandler != null) {
1423                    fLexicalHandler.startEntity(fStringPool.toString(entityName));
1424                }
1425                break;
1426            case XMLEntityHandler.ENTITYTYPE_UNPARSED: // these are mentioned by name, not referenced
1427
throw new RuntimeException JavaDoc(
1428                    "PAR015 startEntityReference(): ENTITYTYPE_UNPARSED");
1429            case XMLEntityHandler.ENTITYTYPE_DOCUMENT:
1430                break; // not reported
1431
case XMLEntityHandler.ENTITYTYPE_EXTERNAL_SUBSET:
1432                if (DEBUG_CALLBACKS) {
1433                    System.err.println("startEntity(\"[dtd]\")");
1434                }
1435                if (fLexicalHandler != null) {
1436                    fLexicalHandler.startEntity("[dtd]");
1437                }
1438                break;
1439            }
1440        }
1441    }
1442
1443    /** End entity reference. */
1444    public void endEntityReference(int entityName, int entityType, int entityContext) throws Exception JavaDoc {
1445        if (fLexicalHandler != null || DEBUG_CALLBACKS) {
1446            switch (entityType) {
1447            case XMLEntityHandler.ENTITYTYPE_INTERNAL_PE:
1448            case XMLEntityHandler.ENTITYTYPE_EXTERNAL_PE:
1449                if (DEBUG_CALLBACKS) {
1450                    System.err.println("endEntity(%" + fStringPool.toString(entityName) + ")");
1451                }
1452                if (fLexicalHandler != null) {
1453                    fLexicalHandler.endEntity("%" + fStringPool.toString(entityName));
1454                }
1455                break;
1456            case XMLEntityHandler.ENTITYTYPE_INTERNAL:
1457            case XMLEntityHandler.ENTITYTYPE_EXTERNAL:
1458                if (DEBUG_CALLBACKS) {
1459                    System.err.println("endEntity(" + fStringPool.toString(entityName) + ")");
1460                }
1461                if (fLexicalHandler != null) {
1462                    fLexicalHandler.endEntity(fStringPool.toString(entityName));
1463                }
1464                break;
1465            case XMLEntityHandler.ENTITYTYPE_UNPARSED: // these are mentioned by name, not referenced
1466
throw new RuntimeException JavaDoc("PAR016 endEntityReference(): ENTITYTYPE_UNPARSED");
1467            case XMLEntityHandler.ENTITYTYPE_DOCUMENT:
1468                break; // not reported
1469
case XMLEntityHandler.ENTITYTYPE_EXTERNAL_SUBSET:
1470                if (DEBUG_CALLBACKS) {
1471                    System.err.println("endEntity(\"[dtd]\")");
1472                }
1473                if (fLexicalHandler != null) {
1474                    fLexicalHandler.endEntity("[dtd]");
1475                }
1476                break;
1477            }
1478        }
1479    }
1480
1481    /** Start CDATA section. */
1482    public void startCDATA() throws Exception JavaDoc {
1483        if (DEBUG_CALLBACKS) {
1484            System.err.println("startCDATA()");
1485        }
1486        if (fLexicalHandler != null) {
1487            fLexicalHandler.startCDATA();
1488        }
1489    }
1490
1491    /** End CDATA section. */
1492    public void endCDATA() throws Exception JavaDoc {
1493        if (DEBUG_CALLBACKS) {
1494            System.err.println("endCDATA()");
1495        }
1496        if (fLexicalHandler != null) {
1497            fLexicalHandler.endCDATA();
1498        }
1499    }
1500
1501    /** Not called. */
1502    public void characters(int dataIndex) throws Exception JavaDoc {
1503        throw new RuntimeException JavaDoc("PAR017 cannot happen 5\n5");
1504    }
1505
1506    /** Not called. */
1507    public void ignorableWhitespace(int dataIndex) throws Exception JavaDoc {
1508        throw new RuntimeException JavaDoc("PAR017 cannot happen 6\n6");
1509    }
1510
1511    /** Processing instruction. */
1512    public void processingInstruction(int piTarget, int piData) throws Exception JavaDoc {
1513
1514        if (fDocumentHandler != null || fContentHandler != null || DEBUG_CALLBACKS) {
1515            //
1516
// REVISIT - I keep running into SAX apps that expect
1517
// null data to be an empty string, which is contrary
1518
// to the comment for this method in the SAX API.
1519
//
1520

1521            // strings
1522
String JavaDoc target = fStringPool.orphanString(piTarget);
1523            String JavaDoc data = piData == -1 ? "" : fStringPool.orphanString(piData);
1524
1525            // perform callback
1526
if (DEBUG_CALLBACKS) {
1527                System.err.println("processingInstruction(" + target + ", " + data + ")");
1528            }
1529            if (fDocumentHandler != null) {
1530                fDocumentHandler.processingInstruction(target, data);
1531            }
1532            if (fContentHandler != null) {
1533                fContentHandler.processingInstruction(target, data);
1534            }
1535
1536        }
1537        else {
1538            fStringPool.releaseString(piTarget);
1539            fStringPool.releaseString(piData);
1540        }
1541
1542    }
1543
1544    /** Comment. */
1545    public void comment(int dataIndex) throws Exception JavaDoc {
1546
1547        if (fLexicalHandler != null || DEBUG_CALLBACKS) {
1548
1549            // strings
1550
String JavaDoc data = fStringPool.orphanString(dataIndex);
1551
1552            // perform callback
1553
if (DEBUG_CALLBACKS) {
1554                System.err.println("comment(" + data + ")");
1555            }
1556            if (fLexicalHandler != null) {
1557                fLexicalHandler.comment(data.toCharArray(), 0, data.length());
1558            }
1559        } else {
1560            fStringPool.releaseString(dataIndex);
1561        }
1562    }
1563
1564    /** Characters. */
1565    public void characters(char ch[], int start, int length) throws Exception JavaDoc {
1566
1567        // perform callback
1568
if (DEBUG_CALLBACKS) {
1569            System.err.println("characters(<char-data>) length " + length);
1570        }
1571        if (fDocumentHandler != null) {
1572            fDocumentHandler.characters(ch, start, length);
1573        }
1574        if (fContentHandler != null) {
1575            fContentHandler.characters(ch, start, length);
1576        }
1577
1578    }
1579
1580    /** Ignorable whitespace. */
1581    public void ignorableWhitespace(char ch[], int start, int length) throws Exception JavaDoc {
1582
1583        // perform callback
1584
if (DEBUG_CALLBACKS) {
1585            System.err.println("ignorableWhitespace(<white-space>)");
1586        }
1587        if (fDocumentHandler != null) {
1588            fDocumentHandler.ignorableWhitespace(ch, start, length);
1589        }
1590        if (fContentHandler != null) {
1591            fContentHandler.ignorableWhitespace(ch, start, length);
1592        }
1593
1594    }
1595
1596} // class SAXParser
1597
Popular Tags