KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sax > XMLReaderBase


1 /*--
2
3  Copyright (C) 2000 Brett McLaughlin & Jason Hunter.
4  All rights reserved.
5  
6  Redistribution and use in source and binary forms, with or without
7  modification, are permitted provided that the following conditions
8  are met:
9  
10  1. Redistributions of source code must retain the above copyright
11     notice, this list of conditions, and the following disclaimer.
12  
13  2. Redistributions in binary form must reproduce the above copyright
14     notice, this list of conditions, and the disclaimer that follows
15     these conditions in the documentation and/or other materials
16     provided with the distribution.
17
18  3. The name "JDOM" must not be used to endorse or promote products
19     derived from this software without prior written permission. For
20     written permission, please contact license@jdom.org.
21  
22  4. Products derived from this software may not be called "JDOM", nor
23     may "JDOM" appear in their name, without prior written permission
24     from the JDOM Project Management (pm@jdom.org).
25  
26  In addition, we request (but do not require) that you include in the
27  end-user documentation provided with the redistribution and/or in the
28  software itself an acknowledgement equivalent to the following:
29      "This product includes software developed by the
30       JDOM Project (http://www.jdom.org/)."
31  Alternatively, the acknowledgment may be graphical using the logos
32  available at http://www.jdom.org/images/logos.
33
34  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
35  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
36  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37  DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
38  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
41  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
42  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
43  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
44  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45  SUCH DAMAGE.
46
47  This software consists of voluntary contributions made by many
48  individuals on behalf of the JDOM Project and was originally
49  created by Brett McLaughlin <brett@jdom.org> and
50  Jason Hunter <jhunter@jdom.org>. For more information on the
51  JDOM Project, please see <http://www.jdom.org/>.
52  
53  */

54 package sax;
55
56 import java.io.IOException JavaDoc;
57
58 import org.xml.sax.Attributes JavaDoc;
59 import org.xml.sax.ContentHandler JavaDoc;
60 import org.xml.sax.DTDHandler JavaDoc;
61 import org.xml.sax.EntityResolver JavaDoc;
62 import org.xml.sax.ErrorHandler JavaDoc;
63 import org.xml.sax.InputSource JavaDoc;
64 import org.xml.sax.Locator JavaDoc;
65 import org.xml.sax.SAXException JavaDoc;
66 import org.xml.sax.SAXParseException JavaDoc;
67 import org.xml.sax.SAXNotSupportedException JavaDoc;
68 import org.xml.sax.SAXNotRecognizedException JavaDoc;
69 import org.xml.sax.XMLReader JavaDoc;
70 import org.xml.sax.ext.LexicalHandler JavaDoc;
71 import org.xml.sax.helpers.AttributesImpl JavaDoc;
72 import org.xml.sax.helpers.DefaultHandler JavaDoc;
73
74
75 /**
76  * Base class for implementing an XML reader.
77  *
78  * Adapted from David Megginson's XMLFilterImpl and XMLFilterBase.
79  */

80 public abstract class XMLReaderBase extends DefaultHandler JavaDoc
81 implements LexicalHandler JavaDoc, XMLReader JavaDoc
82 {
83     
84     ////////////////////////////////////////////////////////////////////
85
// Constructors.
86
////////////////////////////////////////////////////////////////////
87

88     
89     /**
90      * Creates new XMLReaderBase.
91      */

92     public XMLReaderBase ()
93     {
94     }
95     
96     
97     ////////////////////////////////////////////////////////////////////
98
// Convenience methods.
99
////////////////////////////////////////////////////////////////////
100

101
102     /**
103      * Start a new element without a qname or attributes.
104      *
105      * <p>This method will provide a default empty attribute
106      * list and an empty string for the qualified name. It invokes
107      * {@link #startElement(String, String, String, Attributes)}
108      * directly.</p>
109      *
110      * @param uri The element's Namespace URI.
111      * @param localName The element's local name.
112      * @exception org.xml.sax.SAXException If a filter
113      * further down the chain raises an exception.
114      * @see org.xml.sax.ContentHandler#startElement
115      */

116     public void startElement (String JavaDoc uri, String JavaDoc localName)
117     throws SAXException JavaDoc
118     {
119         startElement(uri, localName, "", EMPTY_ATTS);
120     }
121
122
123     /**
124      * Start a new element without a Namespace URI or qname.
125      *
126      * <p>This method will provide an empty string for the
127      * Namespace URI, and empty string for the qualified name.
128      * It invokes
129      * {@link #startElement(String, String, String, Attributes)}
130      * directly.</p>
131      *
132      * @param localName The element's local name.
133      * @param atts The element's attribute list.
134      * @exception org.xml.sax.SAXException If a filter
135      * further down the chain raises an exception.
136      * @see org.xml.sax.ContentHandler#startElement
137      */

138     public void startElement (String JavaDoc localName, Attributes JavaDoc atts)
139     throws SAXException JavaDoc
140     {
141         startElement("", localName, "", atts);
142     }
143
144
145     /**
146      * Start a new element without a Namespace URI, qname, or attributes.
147      *
148      * <p>This method will provide an empty string for the
149      * Namespace URI, and empty string for the qualified name,
150      * and a default empty attribute list. It invokes
151      * {@link #startElement(String, String, String, Attributes)}
152      * directly.</p>
153      *
154      * @param localName The element's local name.
155      * @exception org.xml.sax.SAXException If a filter
156      * further down the chain raises an exception.
157      * @see org.xml.sax.ContentHandler#startElement
158      */

159     public void startElement (String JavaDoc localName)
160     throws SAXException JavaDoc
161     {
162         startElement("", localName, "", EMPTY_ATTS);
163     }
164
165
166     /**
167      * End an element without a qname.
168      *
169      * <p>This method will supply an empty string for the qName.
170      * It invokes {@link #endElement(String, String, String)}
171      * directly.</p>
172      *
173      * @param uri The element's Namespace URI.
174      * @param localName The element's local name.
175      * @exception org.xml.sax.SAXException If a filter
176      * further down the chain raises an exception.
177      * @see org.xml.sax.ContentHandler#endElement
178      */

179     public void endElement (String JavaDoc uri, String JavaDoc localName)
180     throws SAXException JavaDoc
181     {
182         endElement(uri, localName, "");
183     }
184
185
186     /**
187      * End an element without a Namespace URI or qname.
188      *
189      * <p>This method will supply an empty string for the qName
190      * and an empty string for the Namespace URI.
191      * It invokes {@link #endElement(String, String, String)}
192      * directly.</p>
193      *
194      * @param localName The element's local name.
195      * @exception org.xml.sax.SAXException If a filter
196      * further down the chain raises an exception.
197      * @see org.xml.sax.ContentHandler#endElement
198      */

199     public void endElement (String JavaDoc localName)
200     throws SAXException JavaDoc
201     {
202         endElement("", localName, "");
203     }
204
205
206     /**
207      * Add an empty element.
208      *
209      * Both a {@link #startElement startElement} and an
210      * {@link #endElement endElement} event will be passed on down
211      * the filter chain.
212      *
213      * @param uri The element's Namespace URI, or the empty string
214      * if the element has no Namespace or if Namespace
215      * processing is not being performed.
216      * @param localName The element's local name (without prefix). This
217      * parameter must be provided.
218      * @param qName The element's qualified name (with prefix), or
219      * the empty string if none is available. This parameter
220      * is strictly advisory: the writer may or may not use
221      * the prefix attached.
222      * @param atts The element's attribute list.
223      * @exception org.xml.sax.SAXException If a filter
224      * further down the chain raises an exception.
225      * @see org.xml.sax.ContentHandler#startElement
226      * @see org.xml.sax.ContentHandler#endElement
227      */

228     public void emptyElement (String JavaDoc uri, String JavaDoc localName,
229     String JavaDoc qName, Attributes JavaDoc atts)
230     throws SAXException JavaDoc
231     {
232         startElement(uri, localName, qName, atts);
233         endElement(uri, localName, qName);
234     }
235
236
237      /**
238       * Add an empty element without a qname or attributes.
239       *
240       * <p>This method will supply an empty string for the qname
241       * and an empty attribute list. It invokes
242       * {@link #emptyElement(String, String, String, Attributes)}
243       * directly.</p>
244       *
245       * @param uri The element's Namespace URI.
246       * @param localName The element's local name.
247       * @exception org.xml.sax.SAXException If a filter
248       * further down the chain raises an exception.
249       * @see #emptyElement(String, String, String, Attributes)
250       */

251     public void emptyElement (String JavaDoc uri, String JavaDoc localName)
252     throws SAXException JavaDoc
253     {
254         emptyElement(uri, localName, "", EMPTY_ATTS);
255     }
256     
257     
258     /**
259      * Add an empty element without a Namespace URI or qname.
260      *
261      * <p>This method will provide an empty string for the
262      * Namespace URI, and empty string for the qualified name.
263      * It invokes
264      * {@link #emptyElement(String, String, String, Attributes)}
265      * directly.</p>
266      *
267      * @param localName The element's local name.
268      * @param atts The element's attribute list.
269      * @exception org.xml.sax.SAXException If a filter
270      * further down the chain raises an exception.
271      * @see org.xml.sax.ContentHandler#startElement
272      */

273     public void emptyElement (String JavaDoc localName, Attributes JavaDoc atts)
274     throws SAXException JavaDoc
275     {
276         emptyElement("", localName, "", atts);
277     }
278
279
280     /**
281      * Add an empty element without a Namespace URI, qname or attributes.
282      *
283      * <p>This method will supply an empty string for the qname,
284      * and empty string for the Namespace URI, and an empty
285      * attribute list. It invokes
286      * {@link #emptyElement(String, String, String, Attributes)}
287      * directly.</p>
288      *
289      * @param localName The element's local name.
290      * @exception org.xml.sax.SAXException If a filter
291      * further down the chain raises an exception.
292       * @see #emptyElement(String, String, String, Attributes)
293      */

294     public void emptyElement (String JavaDoc localName)
295     throws SAXException JavaDoc
296     {
297         emptyElement("", localName, "", EMPTY_ATTS);
298     }
299
300
301     /**
302      * Add an element with character data content.
303      *
304      * <p>This is a convenience method to add a complete element
305      * with character data content, including the start tag
306      * and end tag.</p>
307      *
308      * <p>This method invokes
309      * {@link @see org.xml.sax.ContentHandler#startElement},
310      * followed by
311      * {@link #characters(String)}, followed by
312      * {@link @see org.xml.sax.ContentHandler#endElement}.</p>
313      *
314      * @param uri The element's Namespace URI.
315      * @param localName The element's local name.
316      * @param qName The element's default qualified name.
317      * @param atts The element's attributes.
318      * @param content The character data content.
319      * @exception org.xml.sax.SAXException If a filter
320      * further down the chain raises an exception.
321      * @see org.xml.sax.ContentHandler#startElement
322      * @see #characters(String)
323      * @see org.xml.sax.ContentHandler#endElement
324      */

325     public void dataElement (String JavaDoc uri, String JavaDoc localName,
326                              String JavaDoc qName, Attributes JavaDoc atts,
327                              String JavaDoc content)
328     throws SAXException JavaDoc
329     {
330         startElement(uri, localName, qName, atts);
331         characters(content);
332         endElement(uri, localName, qName);
333     }
334
335
336     /**
337      * Add an element with character data content but no qname or attributes.
338      *
339      * <p>This is a convenience method to add a complete element
340      * with character data content, including the start tag
341      * and end tag. This method provides an empty string
342      * for the qname and an empty attribute list. It invokes
343      * {@link #dataElement(String, String, String, Attributes, String)}}
344      * directly.</p>
345      *
346      * @param uri The element's Namespace URI.
347      * @param localName The element's local name.
348      * @param content The character data content.
349      * @exception org.xml.sax.SAXException If a filter
350      * further down the chain raises an exception.
351      * @see org.xml.sax.ContentHandler#startElement
352      * @see #characters(String)
353      * @see org.xml.sax.ContentHandler#endElement
354      */

355     public void dataElement (String JavaDoc uri, String JavaDoc localName, String JavaDoc content)
356     throws SAXException JavaDoc
357     {
358         dataElement(uri, localName, "", EMPTY_ATTS, content);
359     }
360
361
362     /**
363      * Add an element with character data content but no Namespace URI or qname.
364      *
365      * <p>This is a convenience method to add a complete element
366      * with character data content, including the start tag
367      * and end tag. The method provides an empty string for the
368      * Namespace URI, and empty string for the qualified name. It invokes
369      * {@link #dataElement(String, String, String, Attributes, String)}}
370      * directly.</p>
371      *
372      * @param localName The element's local name.
373      * @param atts The element's attributes.
374      * @param content The character data content.
375      * @exception org.xml.sax.SAXException If a filter
376      * further down the chain raises an exception.
377      * @see org.xml.sax.ContentHandler#startElement
378      * @see #characters(String)
379      * @see org.xml.sax.ContentHandler#endElement
380      */

381     public void dataElement (String JavaDoc localName, Attributes JavaDoc atts, String JavaDoc content)
382     throws SAXException JavaDoc
383     {
384         dataElement("", localName, "", atts, content);
385     }
386
387
388     /**
389      * Add an element with character data content but no attributes
390      * or Namespace URI.
391      *
392      * <p>This is a convenience method to add a complete element
393      * with character data content, including the start tag
394      * and end tag. The method provides an empty string for the
395      * Namespace URI, and empty string for the qualified name,
396      * and an empty attribute list. It invokes
397      * {@link #dataElement(String, String, String, Attributes, String)}}
398      * directly.</p>
399      *
400      * @param localName The element's local name.
401      * @param content The character data content.
402      * @exception org.xml.sax.SAXException If a filter
403      * further down the chain raises an exception.
404      * @see org.xml.sax.ContentHandler#startElement
405      * @see #characters(String)
406      * @see org.xml.sax.ContentHandler#endElement
407      */

408     public void dataElement (String JavaDoc localName, String JavaDoc content)
409     throws SAXException JavaDoc
410     {
411         dataElement("", localName, "", EMPTY_ATTS, content);
412     }
413
414
415     /**
416      * Add a string of character data, with XML escaping.
417      *
418      * <p>This is a convenience method that takes an XML
419      * String, converts it to a character array, then invokes
420      * {@link @see org.xml.sax.ContentHandler#characters}.</p>
421      *
422      * @param data The character data.
423      * @exception org.xml.sax.SAXException If a filter
424      * further down the chain raises an exception.
425      * @see @see org.xml.sax.ContentHandler#characters
426      */

427     public void characters (String JavaDoc data)
428     throws SAXException JavaDoc
429     {
430         char ch[] = data.toCharArray();
431         characters(ch, 0, ch.length);
432     }
433
434
435
436     ////////////////////////////////////////////////////////////////////
437
// Implementation of org.xml.sax.XMLReader.
438
////////////////////////////////////////////////////////////////////
439

440     
441     /**
442      * Set the state of a feature.
443      *
444      * <p>This will always fail.</p>
445      *
446      * @param name The feature name.
447      * @param state The requested feature state.
448      * @exception org.xml.sax.SAXNotRecognizedException When the
449      * XMLReader does not recognize the feature name.
450      * @exception org.xml.sax.SAXNotSupportedException When the
451      * XMLReader recognizes the feature name but
452      * cannot set the requested value.
453      * @see org.xml.sax.XMLReader#setFeature
454      */

455     public void setFeature (String JavaDoc name, boolean state)
456     throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc
457     {
458         throw new SAXNotRecognizedException JavaDoc("Feature: " + name);
459     }
460     
461     
462     /**
463      * Look up the state of a feature.
464      *
465      * <p>This will always fail.</p>
466      *
467      * @param name The feature name.
468      * @return The current state of the feature.
469      * @exception org.xml.sax.SAXNotRecognizedException When the
470      * XMLReader does not recognize the feature name.
471      * @exception org.xml.sax.SAXNotSupportedException When the
472      * XMLReader recognizes the feature name but
473      * cannot determine its state at this time.
474      * @see org.xml.sax.XMLReader#getFeature
475      */

476     public boolean getFeature (String JavaDoc name)
477     throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc
478     {
479         throw new SAXNotRecognizedException JavaDoc("Feature: " + name);
480     }
481     
482     
483     /**
484      * Set the value of a property.
485      *
486      * <p>Only lexical-handler properties are recognized.</p>
487      *
488      * @param name The property name.
489      * @param state The requested property value.
490      * @exception org.xml.sax.SAXNotRecognizedException When the
491      * XMLReader does not recognize the property name.
492      * @exception org.xml.sax.SAXNotSupportedException When the
493      * XMLReader recognizes the property name but
494      * cannot set the requested value.
495      * @see org.xml.sax.XMLReader#setProperty
496      */

497     public void setProperty (String JavaDoc name, Object JavaDoc value)
498     throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc
499     {
500         for (int i = 0; i < LEXICAL_HANDLER_NAMES.length; i++) {
501             if (LEXICAL_HANDLER_NAMES[i].equals(name)) {
502                 setLexicalHandler((LexicalHandler JavaDoc) value);
503                 return;
504             }
505         }
506         throw new SAXNotRecognizedException JavaDoc("Property: " + name);
507     }
508     
509     
510     /**
511      * Look up the value of a property.
512      *
513      * <p>Only lexical-handler properties are recognized.</p>
514      *
515      * @param name The property name.
516      * @return The current value of the property.
517      * @exception org.xml.sax.SAXNotRecognizedException When the
518      * XMLReader does not recognize the feature name.
519      * @exception org.xml.sax.SAXNotSupportedException When the
520      * XMLReader recognizes the property name but
521      * cannot determine its value at this time.
522      * @see org.xml.sax.XMLReader#setFeature
523      */

524     public Object JavaDoc getProperty (String JavaDoc name)
525     throws SAXNotRecognizedException JavaDoc, SAXNotSupportedException JavaDoc
526     {
527         for (int i = 0; i < LEXICAL_HANDLER_NAMES.length; i++) {
528             if (LEXICAL_HANDLER_NAMES[i].equals(name)) {
529                 return getLexicalHandler();
530             }
531         }
532         throw new SAXNotRecognizedException JavaDoc("Property: " + name);
533     }
534
535
536     /**
537      * Parse a document. Subclass must implement.
538      *
539      * @param input The input source for the document entity.
540      * @exception org.xml.sax.SAXException Any SAX exception, possibly
541      * wrapping another exception.
542      * @exception java.io.IOException An IO exception from the parser,
543      * possibly from a byte stream or character stream
544      * supplied by the application.
545      * @see org.xml.sax.XMLReader#parse(org.xml.sax.InputSource)
546      */

547     public abstract void parse (InputSource JavaDoc input)
548     throws SAXException JavaDoc, IOException JavaDoc;
549
550
551     /**
552      * Parse a document.
553      *
554      * @param systemId The system identifier as a fully-qualified URI.
555      * @exception org.xml.sax.SAXException Any SAX exception, possibly
556      * wrapping another exception.
557      * @exception java.io.IOException An IO exception from the parser,
558      * possibly from a byte stream or character stream
559      * supplied by the application.
560      * @see org.xml.sax.XMLReader#parse(java.lang.String)
561      */

562     public void parse (String JavaDoc systemId)
563     throws SAXException JavaDoc, IOException JavaDoc
564     {
565         parse(new InputSource JavaDoc(systemId));
566     }
567
568
569     /**
570      * Set the entity resolver.
571      *
572      * @param resolver The new entity resolver.
573      * @exception java.lang.NullPointerException If the resolver
574      * is null.
575      * @see org.xml.sax.XMLReader#setEntityResolver
576      */

577     public void setEntityResolver (EntityResolver JavaDoc resolver)
578     {
579         if (resolver == null) {
580             throw new NullPointerException JavaDoc("Null entity resolver");
581         } else {
582             entityResolver = resolver;
583         }
584     }
585     
586     
587     /**
588      * Get the current entity resolver.
589      *
590      * @return The current entity resolver, or null if none was set.
591      * @see org.xml.sax.XMLReader#getEntityResolver
592      */

593     public EntityResolver JavaDoc getEntityResolver ()
594     {
595         return entityResolver;
596     }
597     
598     
599     /**
600      * Set the DTD event handler.
601      *
602      * @param resolver The new DTD handler.
603      * @exception java.lang.NullPointerException If the handler
604      * is null.
605      * @see org.xml.sax.XMLReader#setDTDHandler
606      */

607     public void setDTDHandler (DTDHandler JavaDoc handler)
608     {
609         if (handler == null) {
610             throw new NullPointerException JavaDoc("Null DTD handler");
611         } else {
612             dtdHandler = handler;
613         }
614     }
615     
616     
617     /**
618      * Get the current DTD event handler.
619      *
620      * @return The current DTD handler, or null if none was set.
621      * @see org.xml.sax.XMLReader#getDTDHandler
622      */

623     public DTDHandler JavaDoc getDTDHandler ()
624     {
625         return dtdHandler;
626     }
627     
628     
629     /**
630      * Set the content event handler.
631      *
632      * @param resolver The new content handler.
633      * @exception java.lang.NullPointerException If the handler
634      * is null.
635      * @see org.xml.sax.XMLReader#setContentHandler
636      */

637     public void setContentHandler (ContentHandler JavaDoc handler)
638     {
639         if (handler == null) {
640             throw new NullPointerException JavaDoc("Null content handler");
641         } else {
642             contentHandler = handler;
643         }
644     }
645     
646     
647     /**
648      * Get the content event handler.
649      *
650      * @return The current content handler, or null if none was set.
651      * @see org.xml.sax.XMLReader#getContentHandler
652      */

653     public ContentHandler JavaDoc getContentHandler ()
654     {
655         return contentHandler;
656     }
657     
658     
659     /**
660      * Set the error event handler.
661      *
662      * @param handle The new error handler.
663      * @exception java.lang.NullPointerException If the handler
664      * is null.
665      * @see org.xml.sax.XMLReader#setErrorHandler
666      */

667     public void setErrorHandler (ErrorHandler JavaDoc handler)
668     {
669         if (handler == null) {
670             throw new NullPointerException JavaDoc("Null error handler");
671         } else {
672             errorHandler = handler;
673         }
674     }
675     
676     
677     /**
678      * Get the current error event handler.
679      *
680      * @return The current error handler, or null if none was set.
681      * @see org.xml.sax.XMLReader#getErrorHandler
682      */

683     public ErrorHandler JavaDoc getErrorHandler ()
684     {
685         return errorHandler;
686     }
687
688
689
690     ////////////////////////////////////////////////////////////////////
691
// Registration of org.xml.sax.ext.LexicalHandler.
692
////////////////////////////////////////////////////////////////////
693

694
695     /**
696      * Set the lexical handler.
697      *
698      * @param handler The new lexical handler.
699      * @exception java.lang.NullPointerException If the handler
700      * is null.
701      */

702     public void setLexicalHandler (LexicalHandler JavaDoc handler)
703     {
704         if (handler == null) {
705             throw new NullPointerException JavaDoc("Null lexical handler");
706         } else {
707             lexicalHandler = handler;
708         }
709     }
710     
711     
712     /**
713      * Get the current lexical handler.
714      *
715      * @return The current lexical handler, or null if none was set.
716      */

717     public LexicalHandler JavaDoc getLexicalHandler ()
718     {
719         return lexicalHandler;
720     }
721
722
723     
724     ////////////////////////////////////////////////////////////////////
725
// Implementation of org.xml.sax.EntityResolver.
726
////////////////////////////////////////////////////////////////////
727

728     
729     /**
730      * Resolves an external entity.
731      *
732      * @param publicId The entity's public identifier, or null.
733      * @param systemId The entity's system identifier.
734      * @return A new InputSource or null for the default.
735      * @exception org.xml.sax.SAXException The client may throw
736      * an exception during processing.
737      * @exception java.io.IOException The client may throw an
738      * I/O-related exception while obtaining the
739      * new InputSource.
740      * @see org.xml.sax.EntityResolver#resolveEntity
741      */

742     public InputSource JavaDoc resolveEntity (String JavaDoc publicId, String JavaDoc systemId)
743     throws SAXException JavaDoc /* IOException added in SAX2.01 bugfix release */
744     {
745         if (entityResolver != null) {
746             try {
747                 return entityResolver.resolveEntity(publicId, systemId);
748             }
749             catch (IOException JavaDoc ex) {
750                 throw new SAXException JavaDoc(ex);
751             }
752         } else {
753             return null;
754         }
755     }
756     
757     
758     
759     ////////////////////////////////////////////////////////////////////
760
// Implementation of org.xml.sax.DTDHandler.
761
////////////////////////////////////////////////////////////////////
762

763     
764     /**
765      * Add notation declaration.
766      *
767      * @param name The notation name.
768      * @param publicId The notation's public identifier, or null.
769      * @param systemId The notation's system identifier, or null.
770      * @exception org.xml.sax.SAXException The client may throw
771      * an exception during processing.
772      * @see org.xml.sax.DTDHandler#notationDecl
773      */

774     public void notationDecl (String JavaDoc name, String JavaDoc publicId, String JavaDoc systemId)
775     throws SAXException JavaDoc
776     {
777         if (dtdHandler != null) {
778             dtdHandler.notationDecl(name, publicId, systemId);
779         }
780     }
781     
782     
783     /**
784      * Add unparsed entity declaration.
785      *
786      * @param name The entity name.
787      * @param publicId The entity's public identifier, or null.
788      * @param systemId The entity's system identifier, or null.
789      * @param notationName The name of the associated notation.
790      * @exception org.xml.sax.SAXException The client may throw
791      * an exception during processing.
792      * @see org.xml.sax.DTDHandler#unparsedEntityDecl
793      */

794     public void unparsedEntityDecl (String JavaDoc name, String JavaDoc publicId,
795     String JavaDoc systemId, String JavaDoc notationName)
796     throws SAXException JavaDoc
797     {
798         if (dtdHandler != null) {
799             dtdHandler.unparsedEntityDecl(name, publicId, systemId,
800             notationName);
801         }
802     }
803     
804     
805     
806     ////////////////////////////////////////////////////////////////////
807
// Implementation of org.xml.sax.ContentHandler.
808
////////////////////////////////////////////////////////////////////
809

810     
811     /**
812      * Assigns the document locator.
813      *
814      * @param locator The document locator.
815      * @see org.xml.sax.ContentHandler#setDocumentLocator
816      */

817     public void setDocumentLocator (Locator JavaDoc locator)
818     {
819         this.locator = locator;
820         if (contentHandler != null) {
821             contentHandler.setDocumentLocator(locator);
822         }
823     }
824     
825     
826     /**
827      * Send start of document.
828      *
829      * @exception org.xml.sax.SAXException The client may throw
830      * an exception during processing.
831      * @see org.xml.sax.ContentHandler#startDocument
832      */

833     public void startDocument ()
834     throws SAXException JavaDoc
835     {
836         if (contentHandler != null) {
837             contentHandler.startDocument();
838         }
839     }
840     
841     
842     /**
843      * Send end of document.
844      *
845      * @exception org.xml.sax.SAXException The client may throw
846      * an exception during processing.
847      * @see org.xml.sax.ContentHandler#endDocument
848      */

849     public void endDocument ()
850     throws SAXException JavaDoc
851     {
852         if (contentHandler != null) {
853             contentHandler.endDocument();
854         }
855     }
856     
857     
858     /**
859      * Sends start of namespace prefix mapping.
860      *
861      * @param prefix The Namespace prefix.
862      * @param uri The Namespace URI.
863      * @exception org.xml.sax.SAXException The client may throw
864      * an exception during processing.
865      * @see org.xml.sax.ContentHandler#startPrefixMapping
866      */

867     public void startPrefixMapping (String JavaDoc prefix, String JavaDoc uri)
868     throws SAXException JavaDoc
869     {
870         if (contentHandler != null) {
871             contentHandler.startPrefixMapping(prefix, uri);
872         }
873     }
874     
875     
876     /**
877      * Sends end of namespace prefix mapping.
878      *
879      * @param prefix The Namespace prefix.
880      * @exception org.xml.sax.SAXException The client may throw
881      * an exception during processing.
882      * @see org.xml.sax.ContentHandler#endPrefixMapping
883      */

884     public void endPrefixMapping (String JavaDoc prefix)
885     throws SAXException JavaDoc
886     {
887         if (contentHandler != null) {
888             contentHandler.endPrefixMapping(prefix);
889         }
890     }
891     
892     
893     /**
894      * Sends start of element.
895      *
896      * @param uri The element's Namespace URI, or the empty string.
897      * @param localName The element's local name, or the empty string.
898      * @param qName The element's qualified (prefixed) name, or the empty
899      * string.
900      * @param atts The element's attributes.
901      * @exception org.xml.sax.SAXException The client may throw
902      * an exception during processing.
903      * @see org.xml.sax.ContentHandler#startElement
904      */

905     public void startElement (String JavaDoc uri, String JavaDoc localName, String JavaDoc qName,
906     Attributes JavaDoc atts)
907     throws SAXException JavaDoc
908     {
909         if (contentHandler != null) {
910             contentHandler.startElement(uri, localName, qName, atts);
911         }
912     }
913     
914     
915     /**
916      * Sends end of element.
917      *
918      * @param uri The element's Namespace URI, or the empty string.
919      * @param localName The element's local name, or the empty string.
920      * @param qName The element's qualified (prefixed) name, or the empty
921      * string.
922      * @exception org.xml.sax.SAXException The client may throw
923      * an exception during processing.
924      * @see org.xml.sax.ContentHandler#endElement
925      */

926     public void endElement (String JavaDoc uri, String JavaDoc localName, String JavaDoc qName)
927     throws SAXException JavaDoc
928     {
929         if (contentHandler != null) {
930             contentHandler.endElement(uri, localName, qName);
931         }
932     }
933     
934     
935     /**
936      * Sends character data.
937      *
938      * @param ch An array of characters.
939      * @param start The starting position in the array.
940      * @param length The number of characters to use from the array.
941      * @exception org.xml.sax.SAXException The client may throw
942      * an exception during processing.
943      * @see org.xml.sax.ContentHandler#characters
944      */

945     public void characters (char ch[], int start, int length)
946     throws SAXException JavaDoc
947     {
948         if (contentHandler != null) {
949             contentHandler.characters(ch, start, length);
950         }
951     }
952     
953     
954     /**
955      * Sends ignorable whitespace.
956      *
957      * @param ch An array of characters.
958      * @param start The starting position in the array.
959      * @param length The number of characters to use from the array.
960      * @exception org.xml.sax.SAXException The client may throw
961      * an exception during processing.
962      * @see org.xml.sax.ContentHandler#ignorableWhitespace
963      */

964     public void ignorableWhitespace (char ch[], int start, int length)
965     throws SAXException JavaDoc
966     {
967         if (contentHandler != null) {
968             contentHandler.ignorableWhitespace(ch, start, length);
969         }
970     }
971     
972     
973     /**
974      * Sends processing instruction.
975      *
976      * @param target The processing instruction target.
977      * @param data The text following the target.
978      * @exception org.xml.sax.SAXException The client may throw
979      * an exception during processing.
980      * @see org.xml.sax.ContentHandler#processingInstruction
981      */

982     public void processingInstruction (String JavaDoc target, String JavaDoc data)
983     throws SAXException JavaDoc
984     {
985         if (contentHandler != null) {
986             contentHandler.processingInstruction(target, data);
987         }
988     }
989     
990     
991     /**
992      * Sends skipped entity.
993      *
994      * @param name The name of the skipped entity.
995      * @exception org.xml.sax.SAXException The client may throw
996      * an exception during processing.
997      * @see org.xml.sax.ContentHandler#skippedEntity
998      */

999     public void skippedEntity (String JavaDoc name)
1000    throws SAXException JavaDoc
1001    {
1002        if (contentHandler != null) {
1003            contentHandler.skippedEntity(name);
1004        }
1005    }
1006    
1007    
1008    
1009    ////////////////////////////////////////////////////////////////////
1010
// Implementation of org.xml.sax.ErrorHandler.
1011
////////////////////////////////////////////////////////////////////
1012

1013    
1014    /**
1015     * Sends warning.
1016     *
1017     * @param e The nwarning as an exception.
1018     * @exception org.xml.sax.SAXException The client may throw
1019     * an exception during processing.
1020     * @see org.xml.sax.ErrorHandler#warning
1021     */

1022    public void warning (SAXParseException JavaDoc e)
1023    throws SAXException JavaDoc
1024    {
1025        if (errorHandler != null) {
1026            errorHandler.warning(e);
1027        }
1028    }
1029    
1030    
1031    /**
1032     * Sends error.
1033     *
1034     * @param e The error as an exception.
1035     * @exception org.xml.sax.SAXException The client may throw
1036     * an exception during processing.
1037     * @see org.xml.sax.ErrorHandler#error
1038     */

1039    public void error (SAXParseException JavaDoc e)
1040    throws SAXException JavaDoc
1041    {
1042        if (errorHandler != null) {
1043            errorHandler.error(e);
1044        }
1045    }
1046    
1047    
1048    /**
1049     * Sends fatal error.
1050     *
1051     * @param e The error as an exception.
1052     * @exception org.xml.sax.SAXException The client may throw
1053     * an exception during processing.
1054     * @see org.xml.sax.ErrorHandler#fatalError
1055     */

1056    public void fatalError (SAXParseException JavaDoc e)
1057    throws SAXException JavaDoc
1058    {
1059        if (errorHandler != null) {
1060            errorHandler.fatalError(e);
1061        }
1062    }
1063    
1064    
1065    
1066    ////////////////////////////////////////////////////////////////////
1067
// Implementation of org.xml.sax.ext.LexicalHandler.
1068
////////////////////////////////////////////////////////////////////
1069

1070
1071    /**
1072     * Sends start of DTD.
1073     *
1074     * @param name The document type name.
1075     * @param publicId The declared public identifier for the
1076     * external DTD subset, or null if none was declared.
1077     * @param systemId The declared system identifier for the
1078     * external DTD subset, or null if none was declared.
1079     * @exception org.xml.sax.SAXException If a filter
1080     * further down the chain raises an exception.
1081     * @see org.xml.sax.ext.LexicalHandler#startDTD
1082     */

1083    public void startDTD(String JavaDoc name, String JavaDoc publicId, String JavaDoc systemId)
1084    throws SAXException JavaDoc {
1085        if (lexicalHandler != null) {
1086            lexicalHandler.startDTD(name, publicId, systemId);
1087        }
1088    }
1089
1090
1091    /**
1092     * Sends end of DTD.
1093     *
1094     * @exception org.xml.sax.SAXException If a filter
1095     * further down the chain raises an exception.
1096     * @see org.xml.sax.ext.LexicalHandler#endDTD
1097     */

1098    public void endDTD()
1099    throws SAXException JavaDoc {
1100        if (lexicalHandler != null) {
1101            lexicalHandler.endDTD();
1102        }
1103    }
1104
1105
1106    /*
1107     * Sends start of entity.
1108     *
1109     * @param name The name of the entity. If it is a parameter
1110     * entity, the name will begin with '%', and if it is the
1111     * external DTD subset, it will be "[dtd]".
1112     * @exception org.xml.sax.SAXException If a filter
1113     * further down the chain raises an exception.
1114     * @see org.xml.sax.ext.LexicalHandler#startEntity
1115     */

1116    public void startEntity(String JavaDoc name)
1117    throws SAXException JavaDoc {
1118        if (lexicalHandler != null) {
1119            lexicalHandler.startEntity(name);
1120        }
1121    }
1122
1123
1124    /*
1125     * Sends end of entity.
1126     *
1127     * @param name The name of the entity that is ending.
1128     * @exception org.xml.sax.SAXException If a filter
1129     * further down the chain raises an exception.
1130     * @see org.xml.sax.ext.LexicalHandler#endEntity
1131     */

1132    public void endEntity(String JavaDoc name)
1133    throws SAXException JavaDoc {
1134        if (lexicalHandler != null) {
1135            lexicalHandler.endEntity(name);
1136        }
1137    }
1138
1139
1140    /*
1141     * Sends start of CDATA.
1142     *
1143     * @exception org.xml.sax.SAXException If a filter
1144     * further down the chain raises an exception.
1145     * @see org.xml.sax.ext.LexicalHandler#startCDATA
1146     */

1147    public void startCDATA()
1148    throws SAXException JavaDoc {
1149        if (lexicalHandler != null) {
1150            lexicalHandler.startCDATA();
1151        }
1152    }
1153
1154
1155    /*
1156     * Sends end of CDATA.
1157     *
1158     * @exception org.xml.sax.SAXException If a filter
1159     * further down the chain raises an exception.
1160     * @see org.xml.sax.ext.LexicalHandler#endCDATA
1161     */

1162    public void endCDATA()
1163    throws SAXException JavaDoc {
1164        if (lexicalHandler != null) {
1165            lexicalHandler.endCDATA();
1166        }
1167    }
1168
1169
1170    /*
1171     * Sends comment.
1172     *
1173     * @param ch An array holding the characters in the comment.
1174     * @param start The starting position in the array.
1175     * @param length The number of characters to use from the array.
1176     * @exception org.xml.sax.SAXException If a filter
1177     * further down the chain raises an exception.
1178     * @see org.xml.sax.ext.LexicalHandler#comment
1179     */

1180    public void comment(char[] ch, int start, int length)
1181    throws SAXException JavaDoc {
1182        if (lexicalHandler != null) {
1183            lexicalHandler.comment(ch, start, length);
1184        }
1185    }
1186
1187
1188
1189    ////////////////////////////////////////////////////////////////////
1190
// Internal state.
1191
////////////////////////////////////////////////////////////////////
1192

1193    private Locator JavaDoc locator = null;
1194    private EntityResolver JavaDoc entityResolver = null;
1195    private DTDHandler JavaDoc dtdHandler = null;
1196    private ContentHandler JavaDoc contentHandler = null;
1197    private ErrorHandler JavaDoc errorHandler = null;
1198    private LexicalHandler JavaDoc lexicalHandler = null;
1199
1200
1201
1202    ////////////////////////////////////////////////////////////////////
1203
// Constants.
1204
////////////////////////////////////////////////////////////////////
1205

1206
1207    protected static final Attributes JavaDoc EMPTY_ATTS = new AttributesImpl JavaDoc();
1208
1209    protected static final String JavaDoc[] LEXICAL_HANDLER_NAMES = {
1210        "http://xml.org/sax/properties/lexical-handler",
1211        "http://xml.org/sax/handlers/LexicalHandler"
1212    };
1213
1214
1215}
1216
1217// end of XMLReaderBase.java
1218
Popular Tags