KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > znerd > xmlenc > sax > SAXEventReceiver


1 /*
2  * $Id: SAXEventReceiver.java,v 1.5 2003/04/28 11:48:33 znerd Exp $
3  */

4 package org.znerd.xmlenc.sax;
5
6 import java.io.IOException JavaDoc;
7 import java.io.UnsupportedEncodingException JavaDoc;
8 import java.io.Writer JavaDoc;
9 import org.xml.sax.Attributes JavaDoc;
10 import org.xml.sax.ContentHandler JavaDoc;
11 import org.xml.sax.Locator JavaDoc;
12 import org.xml.sax.SAXException JavaDoc;
13 import org.znerd.xmlenc.XMLEventListener;
14
15 /**
16  * SAX handler that receives SAX events and transforms them to <em>xmlenc</em>
17  * events.
18  *
19  * @version $Revision: 1.5 $ $Date: 2003/04/28 11:48:33 $
20  * @author Ernst de Haan (<a HREF="mailto:znerd@FreeBSD.org">znerd@FreeBSD.org</a>)
21  *
22  * @since xmlenc 0.31
23  */

24 public class SAXEventReceiver
25 extends Object JavaDoc
26 implements ContentHandler JavaDoc {
27
28    //-------------------------------------------------------------------------
29
// Class functions
30
//-------------------------------------------------------------------------
31

32    //-------------------------------------------------------------------------
33
// Class fields
34
//-------------------------------------------------------------------------
35

36    //-------------------------------------------------------------------------
37
// Constructor
38
//-------------------------------------------------------------------------
39

40    /**
41     * Constructs a new <code>SAXEventReceiver</code> that sends events to the
42     * specified <code>XMLEventListener</code>.
43     *
44     * @param eventListener
45     * the {@link XMLEventListener} that should be used, cannot be
46     * <code>null</code>.
47     *
48     * @throws IllegalArgumentException
49     * if <code>eventListener == null</code>.
50     */

51    public SAXEventReceiver(XMLEventListener eventListener)
52    throws IllegalArgumentException JavaDoc {
53       if (eventListener == null) {
54          throw new IllegalArgumentException JavaDoc("eventListener == null");
55       }
56
57       _eventListener = eventListener;
58    }
59
60
61    //-------------------------------------------------------------------------
62
// Fields
63
//-------------------------------------------------------------------------
64

65    /**
66     * The <code>XMLOutputter</code> that is used.
67     */

68    private final XMLEventListener _eventListener;
69
70
71    //-------------------------------------------------------------------------
72
// Methods
73
//-------------------------------------------------------------------------
74

75    public void setDocumentLocator(Locator JavaDoc locator) {
76       // XXX: What should we do here?
77
}
78
79    public void startDocument() throws SAXException JavaDoc {
80       // XXX: Print declaration here?
81
}
82
83    public void endDocument() throws SAXException JavaDoc {
84       try {
85          _eventListener.endDocument();
86       } catch (IOException JavaDoc ioException) {
87          throw new SAXException JavaDoc(ioException);
88       }
89    }
90
91    public void startPrefixMapping(String JavaDoc prefix, String JavaDoc uri)
92    throws SAXException JavaDoc {
93       // XXX: What should we do here?
94
}
95
96    public void endPrefixMapping(String JavaDoc prefix)
97    throws SAXException JavaDoc {
98       // XXX: What should we do here?
99
}
100
101    public void startElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName, Attributes JavaDoc atts)
102    throws SAXException JavaDoc {
103       try {
104          _eventListener.startTag(qName);
105          int attributeCount = atts.getLength();
106          for (int i = 0; i < attributeCount; i++) {
107             _eventListener.attribute(atts.getQName(i), atts.getValue(i));
108          }
109       } catch (IOException JavaDoc ioException) {
110          throw new SAXException JavaDoc(ioException);
111       }
112    }
113
114    public void endElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName)
115    throws SAXException JavaDoc {
116       try {
117          _eventListener.endTag();
118       } catch (IOException JavaDoc ioException) {
119          throw new SAXException JavaDoc(ioException);
120       }
121    }
122
123    public void characters(char[] ch, int start, int length)
124    throws SAXException JavaDoc {
125       try {
126          _eventListener.pcdata(ch, start, length);
127       } catch (IOException JavaDoc ioException) {
128          throw new SAXException JavaDoc(ioException);
129       }
130    }
131
132    public void ignorableWhitespace(char[] ch, int start, int length)
133    throws SAXException JavaDoc {
134       try {
135          _eventListener.whitespace(ch, start, length);
136       } catch (IOException JavaDoc ioException) {
137          throw new SAXException JavaDoc(ioException);
138       }
139    }
140
141    public void processingInstruction(String JavaDoc target, String JavaDoc data)
142    throws SAXException JavaDoc {
143       try {
144          _eventListener.pi(target, data);
145       } catch (IOException JavaDoc ioException) {
146          throw new SAXException JavaDoc(ioException);
147       }
148    }
149
150    public void skippedEntity(String JavaDoc name)
151    throws SAXException JavaDoc {
152       // XXX: Should we do anything here?
153
}
154 }
155
Popular Tags