1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the  "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18/*
19 * $Id: ToTextSAXHandler.java 475978 2006-11-16 23:31:20Z minchau $
20 */
21package org.apache.xml.serializer;
22
23import java.io.IOException;
24import java.io.OutputStream;
25import java.io.Writer;
26import java.util.Properties;
27
28import org.w3c.dom.Node;
29import org.xml.sax.Attributes;
30import org.xml.sax.ContentHandler;
31import org.xml.sax.Locator;
32import org.xml.sax.SAXException;
33import org.xml.sax.ext.LexicalHandler;
34
35/**
36 * This class converts SAX-like event to SAX events for
37 * xsl:output method "text".
38 *
39 * This class is only to be used internally. This class is not a public API.
40 *
41 * @deprecated As of Xalan 2.7.1, replaced by the use of {@link ToXMLSAXHandler}.
42 *
43 * @xsl.usage internal
44 */
45public final class ToTextSAXHandler extends ToSAXHandler
46{
47    /**
48     * From XSLTC
49     * @see ExtendedContentHandler#endElement(String)
50     */
51    public void endElement(String elemName) throws SAXException
52    {
53        if (m_tracer != null)
54            super.fireEndElem(elemName);
55    }
56
57    /**
58     * @see org.xml.sax.ContentHandler#endElement(String, String, String)
59     */
60    public void endElement(String arg0, String arg1, String arg2)
61        throws SAXException
62    {
63		if (m_tracer != null)
64            super.fireEndElem(arg2);
65    }
66
67    public ToTextSAXHandler(ContentHandler hdlr, LexicalHandler lex, String encoding)
68    {
69        super(hdlr, lex, encoding);
70    }
71
72        /**
73     * From XSLTC
74     */
75    public ToTextSAXHandler(ContentHandler handler, String encoding)
76    {
77        super(handler,encoding);
78    }
79
80    public void comment(char ch[], int start, int length)
81        throws org.xml.sax.SAXException
82    {
83        if (m_tracer != null)
84            super.fireCommentEvent(ch, start, length);
85    }
86
87    public void comment(String data) throws org.xml.sax.SAXException
88    {
89        final int length = data.length();
90        if (length > m_charsBuff.length)
91        {
92            m_charsBuff = new char[length*2 + 1];
93        }
94        data.getChars(0, length, m_charsBuff, 0);
95        comment(m_charsBuff, 0, length);
96    }
97
98    /**
99     * @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}
414