001// HandlerBase.java: Simple base class for AElfred processors.
002// NO WARRANTY! See README, and copyright below.
003// $Id$
004package com.microstar.xml;
005
006/**
007 * Convenience base class for AElfred handlers.
008 * <p>This base class implements the XmlHandler interface with
009 * (mostly empty) default handlers.  You are not required to use this,
010 * but if you need to handle only a few events, you might find
011 * it convenient to extend this class rather than implementing
012 * the entire interface.  This example overrides only the
013 * <code>charData</code> method, using the defaults for the others:
014 * <pre>
015 * import com.microstar.xml.HandlerBase;
016 *
017 * public class MyHandler extends HandlerBase {
018 *   public void charData (char ch[], int start, int length)
019 *   {
020 *     System.out.println("Data: " + new String (ch, start, length));
021 *   }
022 * }
023 * </pre>
024 * <p>This class is optional, but if you use it, you must also
025 * include the <code>XmlException</code> class.
026 * <p>Do not extend this if you are using SAX; extend
027 * <code>org.xml.sax.HandlerBase</code> instead.
028 * @author Copyright (c) 1998 by Microstar Software Ltd.
029 * @author written by David Megginson &lt;dmeggins@microstar.com&gt;
030 * @version 1.1
031 * @since Ptolemy II 0.2
032 * @see XmlHandler
033 * @see XmlException
034 */
035public class HandlerBase implements XmlHandler {
036    /**
037     * Handle the start of the document.
038     * <p>The default implementation does nothing.
039     * @see com.microstar.xml.XmlHandler#startDocument
040     * @exception java.lang.Exception Derived methods may throw exceptions.
041     */
042    @Override
043    public void startDocument() throws java.lang.Exception {
044    }
045
046    /**
047     * Handle the end of the document.
048     * <p>The default implementation does nothing.
049     * @see com.microstar.xml.XmlHandler#endDocument
050     * @exception java.lang.Exception Derived methods may throw exceptions.
051     */
052    @Override
053    public void endDocument() throws java.lang.Exception {
054    }
055
056    /**
057     * Resolve an external entity.
058     * <p>The default implementation simply returns the supplied
059     * system identifier.
060     * @see com.microstar.xml.XmlHandler#resolveEntity
061     * @exception java.lang.Exception Derived methods may throw exceptions.
062     */
063    @Override
064    public Object resolveEntity(String publicId, String systemId)
065            throws java.lang.Exception {
066        return null;
067    }
068
069    /**
070     * Handle the start of an external entity.
071     * <p>The default implementation does nothing.
072     * @see com.microstar.xml.XmlHandler#startExternalEntity
073     * @exception java.lang.Exception Derived methods may throw exceptions.
074     */
075    @Override
076    public void startExternalEntity(String systemId)
077            throws java.lang.Exception {
078    }
079
080    /**
081     * Handle the end of an external entity.
082     * <p>The default implementation does nothing.
083     * @see com.microstar.xml.XmlHandler#endExternalEntity
084     * @exception java.lang.Exception Derived methods may throw exceptions.
085     */
086    @Override
087    public void endExternalEntity(String systemId) throws java.lang.Exception {
088    }
089
090    /**
091     * Handle a document type declaration.
092     * <p>The default implementation does nothing.
093     * @see com.microstar.xml.XmlHandler#doctypeDecl
094     * @exception java.lang.Exception Derived methods may throw exceptions.
095     */
096    @Override
097    public void doctypeDecl(String name, String publicId, String systemId)
098            throws java.lang.Exception {
099    }
100
101    /**
102     * Handle an attribute assignment.
103     * <p>The default implementation does nothing.
104     * @see com.microstar.xml.XmlHandler#attribute
105     * @exception java.lang.Exception Derived methods may throw exceptions.
106     */
107    @Override
108    public void attribute(String aname, String value, boolean isSpecified)
109            throws java.lang.Exception {
110    }
111
112    /**
113     * Handle the start of an element.
114     * <p>The default implementation does nothing.
115     * @see com.microstar.xml.XmlHandler#startElement
116     * @exception java.lang.Exception Derived methods may throw exceptions.
117     */
118    @Override
119    public void startElement(String elname) throws java.lang.Exception {
120    }
121
122    /**
123     * Handle the end of an element.
124     * <p>The default implementation does nothing.
125     * @see com.microstar.xml.XmlHandler#endElement
126     * @exception java.lang.Exception Derived methods may throw exceptions.
127     */
128    @Override
129    public void endElement(String elname) throws java.lang.Exception {
130    }
131
132    /**
133     * Handle character data.
134     * <p>The default implementation does nothing.
135     * @see com.microstar.xml.XmlHandler#charData
136     * @exception java.lang.Exception Derived methods may throw exceptions.
137     */
138    @Override
139    public void charData(char[] ch, int start, int length)
140            throws java.lang.Exception {
141    }
142
143    /**
144     * Handle ignorable whitespace.
145     * <p>The default implementation does nothing.
146     * @see com.microstar.xml.XmlHandler#ignorableWhitespace
147     * @exception java.lang.Exception Derived methods may throw exceptions.
148     */
149    @Override
150    public void ignorableWhitespace(char[] ch, int start, int length)
151            throws java.lang.Exception {
152    }
153
154    /**
155     * Handle a processing instruction.
156     * <p>The default implementation does nothing.
157     * @see com.microstar.xml.XmlHandler#processingInstruction
158     * @exception java.lang.Exception Derived methods may throw exceptions.
159     */
160    @Override
161    public void processingInstruction(String target, String data)
162            throws java.lang.Exception {
163    }
164
165    /**
166     * Throw an exception for a fatal error.
167     * <p>The default implementation throws <code>XmlException</code>.
168     * @see com.microstar.xml.XmlHandler#error
169     * @exception com.microstar.xml.XmlException A specific parsing error.
170     * @exception java.lang.Exception Derived methods may throw exceptions.
171     */
172    @Override
173    public void error(String message, String systemId, int line, int column)
174            throws XmlException, java.lang.Exception {
175        throw new XmlException(message, systemId, line, column);
176    }
177}