KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > util > HandlerDecorator


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.util;
24
25 import org.xml.sax.*;
26 import org.xml.sax.ext.LexicalHandler JavaDoc;
27
28 /**
29  * This class is a kind of SAX filter to plug on a contentHandler.
30  */

31 public class HandlerDecorator implements LexicalHandler JavaDoc, ContentHandler, ErrorHandler
32 {
33     private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
34     private static final String JavaDoc RCSName = "$Name: $";
35     
36     protected LexicalHandler JavaDoc lexicalHandler = null;
37     protected ContentHandler contentHandler = null;
38     protected ErrorHandler errorHandler = null;
39     
40     /** Constructor
41      */

42     public HandlerDecorator()
43     {
44         this(null, null);
45     }
46     
47     /** Constructor
48      */

49     public HandlerDecorator(ContentHandler contentHandler, LexicalHandler JavaDoc lexicalHandler)
50     {
51         this.contentHandler = contentHandler;
52         this.lexicalHandler = lexicalHandler;
53     }
54     
55     public void setContentHandler(ContentHandler handler)
56     {
57         contentHandler = handler;
58     }
59     
60     public ContentHandler getContentHandler()
61     {
62         return contentHandler;
63     }
64     
65     public void setLexicalHandler(LexicalHandler JavaDoc handler)
66     {
67         lexicalHandler = handler;
68     }
69     
70     public LexicalHandler JavaDoc getLexicalHandler()
71     {
72         return lexicalHandler;
73     }
74     
75     public void setErrorHandler(ErrorHandler handler)
76     {
77         errorHandler = handler;
78     }
79     
80     public ErrorHandler getPluggedErrorHandler()
81     {
82         return errorHandler;
83     }
84     
85     //////////////////////////////////////////////////////
86
// Implementation of ContentHandler interface.
87
//////////////////////////////////////////////////////
88
public void startDocument() throws SAXException
89     {
90         if (contentHandler != null)
91             contentHandler.startDocument();
92     }
93     
94     public void startElement(String JavaDoc str, String JavaDoc str1, String JavaDoc str2, Attributes attributes)
95     throws SAXException
96     {
97         if (contentHandler != null)
98             contentHandler.startElement(str, str1, str2, attributes);
99     }
100     
101     public void setDocumentLocator(Locator locator)
102     {
103         if (contentHandler != null)
104             contentHandler.setDocumentLocator(locator);
105     }
106     
107     public void endDocument() throws SAXException
108     {
109         if (contentHandler != null)
110             contentHandler.endDocument();
111     }
112     
113     public void characters(char[] values, int param, int param2)
114     throws SAXException
115     {
116         if (contentHandler != null)
117             contentHandler.characters(values, param, param2);
118     }
119     
120     public void processingInstruction(String JavaDoc str, String JavaDoc str1)
121     throws SAXException
122     {
123         if (contentHandler != null)
124             contentHandler.processingInstruction(str, str1);
125     }
126     
127     public void endElement(String JavaDoc str, String JavaDoc str1, String JavaDoc str2)
128     throws SAXException
129     {
130         if (contentHandler != null)
131             contentHandler.endElement(str, str1, str2);
132     }
133     
134     public void startPrefixMapping(String JavaDoc str, String JavaDoc str1) throws SAXException
135     {
136         if (contentHandler != null)
137             contentHandler.startPrefixMapping(str, str1);
138     }
139     
140     public void ignorableWhitespace(char[] values, int param, int param2)
141     throws SAXException
142     {
143         if (contentHandler != null)
144             contentHandler.ignorableWhitespace(values, param, param2);
145     }
146     
147     public void endPrefixMapping(String JavaDoc str) throws SAXException
148     {
149         if (contentHandler != null)
150             contentHandler.endPrefixMapping(str);
151     }
152     
153     public void skippedEntity(String JavaDoc str) throws SAXException
154     {
155         if (contentHandler != null)
156             contentHandler.skippedEntity(str);
157     }
158     
159     //////////////////////////////////////////////////////
160
// Implementation of LexicalHandler interface.
161
//////////////////////////////////////////////////////
162
public void startDTD(String JavaDoc name, String JavaDoc publicId, String JavaDoc systemId)
163     throws SAXException
164     {
165         if (lexicalHandler != null)
166             lexicalHandler.startDTD(name, publicId, systemId);
167     }
168     
169     public void endDTD() throws SAXException
170     {
171         if (lexicalHandler != null)
172             lexicalHandler.endDTD();
173     }
174     
175     public void startEntity(String JavaDoc name) throws SAXException
176     {
177         if (lexicalHandler != null)
178             lexicalHandler.startEntity(name);
179     }
180     
181     public void endEntity(String JavaDoc name) throws SAXException
182     {
183         if (lexicalHandler != null)
184             lexicalHandler.endEntity(name);
185     }
186     
187     public void startCDATA() throws SAXException
188     {
189         if (lexicalHandler != null)
190             lexicalHandler.startCDATA();
191     }
192     
193     public void endCDATA() throws SAXException
194     {
195         if (lexicalHandler != null)
196             lexicalHandler.endCDATA();
197     }
198     
199     public void comment(char ch[], int start, int length) throws SAXException
200     {
201         if (lexicalHandler != null)
202             lexicalHandler.comment(ch, start, length);
203     }
204     
205     //////////////////////////////////////////////////////
206
// Implementation of EventHandler interface.
207
//////////////////////////////////////////////////////
208
/**
209      * Filter a warning event.
210      *
211      * @param e The warning as an exception.
212      * @exception org.xml.sax.SAXException The client may throw
213      * an exception during processing.
214      * @see org.xml.sax.ErrorHandler#warning
215      */

216     public void warning(SAXParseException e)
217     throws SAXException
218     {
219         if (errorHandler != null)
220         {
221             errorHandler.warning(e);
222         }
223     }
224     
225     
226     /**
227      * Filter an error event.
228      *
229      * @param e The error as an exception.
230      * @exception org.xml.sax.SAXException The client may throw
231      * an exception during processing.
232      * @see org.xml.sax.ErrorHandler#error
233      */

234     public void error(SAXParseException e)
235     throws SAXException
236     {
237         if (errorHandler != null)
238         {
239             errorHandler.error(e);
240         }
241     }
242     
243     
244     /**
245      * Filter a fatal error event.
246      *
247      * @param e The error as an exception.
248      * @exception org.xml.sax.SAXException The client may throw
249      * an exception during processing.
250      * @see org.xml.sax.ErrorHandler#fatalError
251      */

252     public void fatalError(SAXParseException e)
253     throws SAXException
254     {
255         if (errorHandler != null)
256         {
257             errorHandler.fatalError(e);
258         }
259     }
260     
261 }
262
263
264
265
266
Popular Tags