1 // DefaultHandler2.java - extended DefaultHandler
2 // http://www.saxproject.org
3 // Public Domain: no warranty.
4 // $Id: DefaultHandler2.java,v 1.3 2002/01/12 19:04:19 dbrownell Exp $
5 
6 package org.xml.sax.ext;
7 
8 import java.io.IOException;
9 import org.xml.sax.InputSource;
10 import org.xml.sax.SAXException;
11 import org.xml.sax.helpers.DefaultHandler;
12 
13 
14 /**
15  * This class extends the SAX2 base handler class to support the
16  * SAX2 {@link LexicalHandler}, {@link DeclHandler}, and
17  * {@link EntityResolver2} extensions.  Except for overriding the
18  * original SAX1 {@link DefaultHandler#resolveEntity resolveEntity()}
19  * method the added handler methods just return.  Subclassers may
20  * override everything on a method-by-method basis.
21  *
22  * <blockquote>
23  * <em>This module, both source code and documentation, is in the
24  * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
25  * </blockquote>
26  *
27  * <p> <em>Note:</em> this class might yet learn that the
28  * <em>ContentHandler.setDocumentLocator()</em> call might be passed a
29  * {@link Locator2} object, and that the
30  * <em>ContentHandler.startElement()</em> call might be passed a
31  * {@link Attributes2} object.
32  *
33  * @since SAX 2.0 (extensions 1.1 alpha)
34  * @author David Brownell
35  * @version TBS
36  */
37 public class DefaultHandler2 extends DefaultHandler
38     implements LexicalHandler, DeclHandler, EntityResolver2
39 {
40     /** Constructs a handler which ignores all parsing events. */
DefaultHandler2()41     public DefaultHandler2 () { }
42 
43 
44     // SAX2 ext-1.0 LexicalHandler
45 
startCDATA()46     public void startCDATA ()
47     throws SAXException
48     {}
49 
endCDATA()50     public void endCDATA ()
51     throws SAXException
52     {}
53 
startDTD(String name, String publicId, String systemId)54     public void startDTD (String name, String publicId, String systemId)
55     throws SAXException
56     {}
57 
endDTD()58     public void endDTD ()
59     throws SAXException
60     {}
61 
startEntity(String name)62     public void startEntity (String name)
63     throws SAXException
64     {}
65 
endEntity(String name)66     public void endEntity (String name)
67     throws SAXException
68     {}
69 
comment(char ch [], int start, int length)70     public void comment (char ch [], int start, int length)
71     throws SAXException
72     { }
73 
74 
75     // SAX2 ext-1.0 DeclHandler
76 
attributeDecl(String eName, String aName, String type, String mode, String value)77     public void attributeDecl (String eName, String aName,
78         String type, String mode, String value)
79     throws SAXException
80     {}
81 
elementDecl(String name, String model)82     public void elementDecl (String name, String model)
83     throws SAXException
84     {}
85 
externalEntityDecl(String name, String publicId, String systemId)86     public void externalEntityDecl (String name,
87         String publicId, String systemId)
88     throws SAXException
89     {}
90 
internalEntityDecl(String name, String value)91     public void internalEntityDecl (String name, String value)
92     throws SAXException
93     {}
94 
95     // SAX2 ext-1.1 EntityResolver2
96 
97     /**
98      * Tells the parser that if no external subset has been declared
99      * in the document text, none should be used.
100      *
101      * @param name Identifies the document root element.  This name comes
102      *    from a DOCTYPE declaration (where available) or from the actual
103      *    root element. The parameter is ignored.
104      * @param baseURI The document's base URI, serving as an additional
105      *    hint for selecting the external subset.  This is always an absolute
106      *    URI, unless it is null because the XMLReader was given an InputSource
107      *    without one. The parameter is ignored.
108      *
109      * @return null (always).
110      *
111      * @exception SAXException Any SAX exception, possibly wrapping
112      *    another exception.
113      * @exception IOException Probably indicating a failure to create
114      *    a new InputStream or Reader, or an illegal URL.
115      */
getExternalSubset(String name, String baseURI)116     public InputSource getExternalSubset (String name, String baseURI)
117     throws SAXException, IOException
118     { return null; }
119 
120     /**
121      * Tells the parser to resolve the systemId against the baseURI
122      * and read the entity text from that resulting absolute URI.
123      * Note that because the older
124      * {@link DefaultHandler#resolveEntity DefaultHandler.resolveEntity()},
125      * method is overridden to call this one, this method may sometimes
126      * be invoked with null <em>name</em> and <em>baseURI</em>, and
127      * with the <em>systemId</em> already absolutized.
128      *
129      * @param name Identifies the external entity being resolved.
130      *    Either "[dtd]" for the external subset, or a name starting
131      *    with "%" to indicate a parameter entity, or else the name of
132      *    a general entity.  This is never null when invoked by a SAX2
133      *    parser.
134      * @param publicId The public identifier of the external entity being
135      *    referenced (normalized as required by the XML specification), or
136      *    null if none was supplied.
137      * @param baseURI The URI with respect to which relative systemIDs
138      *    are interpreted.  This is always an absolute URI, unless it is
139      *    null (likely because the XMLReader was given an InputSource without
140      *  one).  This URI is defined by the XML specification to be the one
141      *    associated with the "&lt;" starting the relevant declaration.
142      * @param systemId The system identifier of the external entity
143      *    being referenced; either a relative or absolute URI.
144      *  This is never null when invoked by a SAX2 parser; only declared
145      *    entities, and any external subset, are resolved by such parsers.
146      *
147      * @return An InputSource object describing the new input source.
148      *
149      * @exception SAXException Any SAX exception, possibly wrapping
150      *    another exception.
151      * @exception IOException Probably indicating a failure to create
152      *    a new InputStream or Reader, or an illegal URL.
153      */
resolveEntity(String name, String publicId, String baseURI, String systemId)154     public InputSource resolveEntity (String name, String publicId,
155         String baseURI, String systemId)
156     throws SAXException, IOException
157     { return null; }
158 
159     // SAX1 EntityResolver
160 
161     /**
162      * Invokes
163      * {@link EntityResolver2#resolveEntity EntityResolver2.resolveEntity()}
164      * with null entity name and base URI.
165      * You only need to override that method to use this class.
166      *
167      * @param publicId The public identifier of the external entity being
168      *    referenced (normalized as required by the XML specification), or
169      *    null if none was supplied.
170      * @param systemId The system identifier of the external entity
171      *    being referenced; either a relative or absolute URI.
172      *  This is never null when invoked by a SAX2 parser; only declared
173      *    entities, and any external subset, are resolved by such parsers.
174      *
175      * @return An InputSource object describing the new input source.
176      *
177      * @exception SAXException Any SAX exception, possibly wrapping
178      *    another exception.
179      * @exception IOException Probably indicating a failure to create
180      *    a new InputStream or Reader, or an illegal URL.
181      */
resolveEntity(String publicId, String systemId)182     public InputSource resolveEntity (String publicId, String systemId)
183     throws SAXException, IOException
184     { return resolveEntity (null, publicId, null, systemId); }
185 }
186