001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 /*
019 * $Id: ToTextSAXHandler.java 475978 2006-11-16 23:31:20Z minchau $
020 */
021 package org.apache.xml.serializer;
022
023 import java.io.IOException;
024 import java.io.OutputStream;
025 import java.io.Writer;
026 import java.util.Properties;
027
028 import org.w3c.dom.Node;
029 import org.xml.sax.Attributes;
030 import org.xml.sax.ContentHandler;
031 import org.xml.sax.Locator;
032 import org.xml.sax.SAXException;
033 import org.xml.sax.ext.LexicalHandler;
034
035 /**
036 * This class converts SAX-like event to SAX events for
037 * xsl:output method "text".
038 *
039 * This class is only to be used internally. This class is not a public API.
040 *
041 * @deprecated As of Xalan 2.7.1, replaced by the use of {@link ToXMLSAXHandler}.
042 *
043 * @xsl.usage internal
044 */
045 public final class ToTextSAXHandler extends ToSAXHandler
046 {
047 /**
048 * From XSLTC
049 * @see ExtendedContentHandler#endElement(String)
050 */
051 public void endElement(String elemName) throws SAXException
052 {
053 if (m_tracer != null)
054 super.fireEndElem(elemName);
055 }
056
057 /**
058 * @see org.xml.sax.ContentHandler#endElement(String, String, String)
059 */
060 public void endElement(String arg0, String arg1, String arg2)
061 throws SAXException
062 {
063 if (m_tracer != null)
064 super.fireEndElem(arg2);
065 }
066
067 public ToTextSAXHandler(ContentHandler hdlr, LexicalHandler lex, String encoding)
068 {
069 super(hdlr, lex, encoding);
070 }
071
072 /**
073 * From XSLTC
074 */
075 public ToTextSAXHandler(ContentHandler handler, String encoding)
076 {
077 super(handler,encoding);
078 }
079
080 public void comment(char ch[], int start, int length)
081 throws org.xml.sax.SAXException
082 {
083 if (m_tracer != null)
084 super.fireCommentEvent(ch, start, length);
085 }
086
087 public void comment(String data) throws org.xml.sax.SAXException
088 {
089 final int length = data.length();
090 if (length > m_charsBuff.length)
091 {
092 m_charsBuff = new char[length*2 + 1];
093 }
094 data.getChars(0, length, m_charsBuff, 0);
095 comment(m_charsBuff, 0, length);
096 }
097
098 /**
099 * @see Serializer#getOutputFormat()
100 */
101 public Properties getOutputFormat()
102 {
103 return null;
104 }
105
106 /**
107 * @see Serializer#getOutputStream()
108 */
109 public OutputStream getOutputStream()
110 {
111 return null;
112 }
113
114 /**
115 * @see Serializer#getWriter()
116 */
117 public Writer getWriter()
118 {
119 return null;
120 }
121
122 /**
123 * Does nothing because
124 * the indent attribute is ignored for text output.
125 *
126 */
127 public void indent(int n) throws SAXException
128 {
129 }
130
131 /**
132 * @see Serializer#reset()
133 */
134 public boolean reset()
135 {
136 return false;
137 }
138
139 /**
140 * @see DOMSerializer#serialize(Node)
141 */
142 public void serialize(Node node) throws IOException
143 {
144 }
145
146 /**
147 * @see SerializationHandler#setEscaping(boolean)
148 */
149 public boolean setEscaping(boolean escape)
150 {
151 return false;
152 }
153
154 /**
155 * @see SerializationHandler#setIndent(boolean)
156 */
157 public void setIndent(boolean indent)
158 {
159 }
160
161 /**
162 * @see Serializer#setOutputFormat(Properties)
163 */
164 public void setOutputFormat(Properties format)
165 {
166 }
167
168 /**
169 * @see Serializer#setOutputStream(OutputStream)
170 */
171 public void setOutputStream(OutputStream output)
172 {
173 }
174
175 /**
176 * @see Serializer#setWriter(Writer)
177 */
178 public void setWriter(Writer writer)
179 {
180 }
181
182 /**
183 * @see ExtendedContentHandler#addAttribute(String, String, String, String, String)
184 */
185 public void addAttribute(
186 String uri,
187 String localName,
188 String rawName,
189 String type,
190 String value,
191 boolean XSLAttribute)
192 {
193 }
194
195 /**
196 * @see org.xml.sax.ext.DeclHandler#attributeDecl(String, String, String, String, String)
197 */
198 public void attributeDecl(
199 String arg0,
200 String arg1,
201 String arg2,
202 String arg3,
203 String arg4)
204 throws SAXException
205 {
206 }
207
208 /**
209 * @see org.xml.sax.ext.DeclHandler#elementDecl(String, String)
210 */
211 public void elementDecl(String arg0, String arg1) throws SAXException
212 {
213 }
214
215 /**
216 * @see org.xml.sax.ext.DeclHandler#externalEntityDecl(String, String, String)
217 */
218 public void externalEntityDecl(String arg0, String arg1, String arg2)
219 throws SAXException
220 {
221 }
222
223 /**
224 * @see org.xml.sax.ext.DeclHandler#internalEntityDecl(String, String)
225 */
226 public void internalEntityDecl(String arg0, String arg1)
227 throws SAXException
228 {
229 }
230
231 /**
232 * @see org.xml.sax.ContentHandler#endPrefixMapping(String)
233 */
234 public void endPrefixMapping(String arg0) throws SAXException
235 {
236 }
237
238 /**
239 * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
240 */
241 public void ignorableWhitespace(char[] arg0, int arg1, int arg2)
242 throws SAXException
243 {
244 }
245
246 /**
247 * From XSLTC
248 * @see org.xml.sax.ContentHandler#processingInstruction(String, String)
249 */
250 public void processingInstruction(String arg0, String arg1)
251 throws SAXException
252 {
253 if (m_tracer != null)
254 super.fireEscapingEvent(arg0, arg1);
255 }
256
257 /**
258 * @see org.xml.sax.ContentHandler#setDocumentLocator(Locator)
259 */
260 public void setDocumentLocator(Locator arg0)
261 {
262 }
263
264 /**
265 * @see org.xml.sax.ContentHandler#skippedEntity(String)
266 */
267 public void skippedEntity(String arg0) throws SAXException
268 {
269 }
270
271 /**
272 * @see org.xml.sax.ContentHandler#startElement(String, String, String, Attributes)
273 */
274 public void startElement(
275 String arg0,
276 String arg1,
277 String arg2,
278 Attributes arg3)
279 throws SAXException
280 {
281 flushPending();
282 super.startElement(arg0, arg1, arg2, arg3);
283 }
284
285 /**
286 * @see org.xml.sax.ext.LexicalHandler#endCDATA()
287 */
288 public void endCDATA() throws SAXException
289 {
290 }
291
292 /**
293 * @see org.xml.sax.ext.LexicalHandler#endDTD()
294 */
295 public void endDTD() throws SAXException
296 {
297 }
298
299 /**
300 * @see org.xml.sax.ext.LexicalHandler#startCDATA()
301 */
302 public void startCDATA() throws SAXException
303 {
304 }
305
306
307 /**
308 * @see org.xml.sax.ext.LexicalHandler#startEntity(String)
309 */
310 public void startEntity(String arg0) throws SAXException
311 {
312 }
313
314
315 /**
316 * From XSLTC
317 * @see ExtendedContentHandler#startElement(String)
318 */
319 public void startElement(
320 String elementNamespaceURI,
321 String elementLocalName,
322 String elementName) throws SAXException
323 {
324 super.startElement(elementNamespaceURI, elementLocalName, elementName);
325 }
326
327 public void startElement(
328 String elementName) throws SAXException
329 {
330 super.startElement(elementName);
331 }
332
333
334 /**
335 * From XSLTC
336 * @see org.xml.sax.ContentHandler#endDocument()
337 */
338 public void endDocument() throws SAXException {
339
340 flushPending();
341 m_saxHandler.endDocument();
342
343 if (m_tracer != null)
344 super.fireEndDoc();
345 }
346
347 /**
348 *
349 * @see ExtendedContentHandler#characters(String)
350 */
351 public void characters(String characters)
352 throws SAXException
353 {
354 final int length = characters.length();
355 if (length > m_charsBuff.length)
356 {
357 m_charsBuff = new char[length*2 + 1];
358 }
359 characters.getChars(0, length, m_charsBuff, 0);
360
361 m_saxHandler.characters(m_charsBuff, 0, length);
362
363 }
364 /**
365 * @see org.xml.sax.ContentHandler#characters(char[], int, int)
366 */
367 public void characters(char[] characters, int offset, int length)
368 throws SAXException
369 {
370
371 m_saxHandler.characters(characters, offset, length);
372
373 // time to fire off characters event
374 if (m_tracer != null)
375 super.fireCharEvent(characters, offset, length);
376 }
377
378 /**
379 * From XSLTC
380 */
381 public void addAttribute(String name, String value)
382 {
383 // do nothing
384 }
385
386
387 public boolean startPrefixMapping(
388 String prefix,
389 String uri,
390 boolean shouldFlush)
391 throws SAXException
392 {
393 // no namespace support for HTML
394 return false;
395 }
396
397
398 public void startPrefixMapping(String prefix, String uri)
399 throws org.xml.sax.SAXException
400 {
401 // no namespace support for HTML
402 }
403
404
405 public void namespaceAfterStartElement(
406 final String prefix,
407 final String uri)
408 throws SAXException
409 {
410 // no namespace support for HTML
411 }
412
413 }