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