DefaultHandler2.java revision 628:2bfaf29cc90b
1/*
2 * Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26// DefaultHandler2.java - extended DefaultHandler
27// http://www.saxproject.org
28// Public Domain: no warranty.
29// $Id: DefaultHandler2.java,v 1.2 2004/11/03 22:49:08 jsuttor Exp $
30
31package org.xml.sax.ext;
32
33import java.io.IOException;
34import org.xml.sax.InputSource;
35import org.xml.sax.SAXException;
36import org.xml.sax.helpers.DefaultHandler;
37
38
39/**
40 * This class extends the SAX2 base handler class to support the
41 * SAX2 {@link LexicalHandler}, {@link DeclHandler}, and
42 * {@link EntityResolver2} extensions.  Except for overriding the
43 * original SAX1 {@link DefaultHandler#resolveEntity resolveEntity()}
44 * method the added handler methods just return.  Subclassers may
45 * override everything on a method-by-method basis.
46 *
47 * <blockquote>
48 * <em>This module, both source code and documentation, is in the
49 * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
50 * </blockquote>
51 *
52 * <p> <em>Note:</em> this class might yet learn that the
53 * <em>ContentHandler.setDocumentLocator()</em> call might be passed a
54 * {@link Locator2} object, and that the
55 * <em>ContentHandler.startElement()</em> call might be passed a
56 * {@link Attributes2} object.
57 *
58 * @since 1.5, SAX 2.0 (extensions 1.1 alpha)
59 * @author David Brownell
60 */
61public class DefaultHandler2 extends DefaultHandler
62    implements LexicalHandler, DeclHandler, EntityResolver2
63{
64    /** Constructs a handler which ignores all parsing events. */
65    public DefaultHandler2 () { }
66
67
68    // SAX2 ext-1.0 LexicalHandler
69
70    public void startCDATA ()
71    throws SAXException
72        {}
73
74    public void endCDATA ()
75    throws SAXException
76        {}
77
78    public void startDTD (String name, String publicId, String systemId)
79    throws SAXException
80        {}
81
82    public void endDTD ()
83    throws SAXException
84        {}
85
86    public void startEntity (String name)
87    throws SAXException
88        {}
89
90    public void endEntity (String name)
91    throws SAXException
92        {}
93
94    public void comment (char ch [], int start, int length)
95    throws SAXException
96        { }
97
98
99    // SAX2 ext-1.0 DeclHandler
100
101    public void attributeDecl (String eName, String aName,
102            String type, String mode, String value)
103    throws SAXException
104        {}
105
106    public void elementDecl (String name, String model)
107    throws SAXException
108        {}
109
110    public void externalEntityDecl (String name,
111        String publicId, String systemId)
112    throws SAXException
113        {}
114
115    public void internalEntityDecl (String name, String value)
116    throws SAXException
117        {}
118
119    // SAX2 ext-1.1 EntityResolver2
120
121    /**
122     * Tells the parser that if no external subset has been declared
123     * in the document text, none should be used.
124     */
125    public InputSource getExternalSubset (String name, String baseURI)
126    throws SAXException, IOException
127        { return null; }
128
129    /**
130     * Tells the parser to resolve the systemId against the baseURI
131     * and read the entity text from that resulting absolute URI.
132     * Note that because the older
133     * {@link DefaultHandler#resolveEntity DefaultHandler.resolveEntity()},
134     * method is overridden to call this one, this method may sometimes
135     * be invoked with null <em>name</em> and <em>baseURI</em>, and
136     * with the <em>systemId</em> already absolutized.
137     */
138    public InputSource resolveEntity (String name, String publicId,
139            String baseURI, String systemId)
140    throws SAXException, IOException
141        { return null; }
142
143    // SAX1 EntityResolver
144
145    /**
146     * Invokes
147     * {@link EntityResolver2#resolveEntity EntityResolver2.resolveEntity()}
148     * with null entity name and base URI.
149     * You only need to override that method to use this class.
150     */
151    public InputSource resolveEntity (String publicId, String systemId)
152    throws SAXException, IOException
153        { return resolveEntity (null, publicId, null, systemId); }
154}
155