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
6package org.xml.sax.ext;
7
8import java.io.IOException;
9import org.xml.sax.InputSource;
10import org.xml.sax.SAXException;
11import 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 */
37public class DefaultHandler2 extends DefaultHandler
38    implements LexicalHandler, DeclHandler, EntityResolver2
39{
40    /** Constructs a handler which ignores all parsing events. */
41    public DefaultHandler2 () { }
42
43
44    // SAX2 ext-1.0 LexicalHandler
45
46    public void startCDATA ()
47    throws SAXException
48    {}
49
50    public void endCDATA ()
51    throws SAXException
52    {}
53
54    public void startDTD (String name, String publicId, String systemId)
55    throws SAXException
56    {}
57
58    public void endDTD ()
59    throws SAXException
60    {}
61
62    public void startEntity (String name)
63    throws SAXException
64    {}
65
66    public void endEntity (String name)
67    throws SAXException
68    {}
69
70    public void comment (char ch [], int start, int length)
71    throws SAXException
72    { }
73
74
75    // SAX2 ext-1.0 DeclHandler
76
77    public void attributeDecl (String eName, String aName,
78        String type, String mode, String value)
79    throws SAXException
80    {}
81
82    public void elementDecl (String name, String model)
83    throws SAXException
84    {}
85
86    public void externalEntityDecl (String name,
87        String publicId, String systemId)
88    throws SAXException
89    {}
90
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     */
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     */
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     */
182    public InputSource resolveEntity (String publicId, String systemId)
183    throws SAXException, IOException
184    { return resolveEntity (null, publicId, null, systemId); }
185}
186