6
|
1 |
/*
|
|
2 |
* reserved comment block
|
|
3 |
* DO NOT REMOVE OR ALTER!
|
|
4 |
*/
|
|
5 |
/*
|
|
6 |
* Copyright 2001-2004 The Apache Software Foundation.
|
|
7 |
*
|
|
8 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9 |
* you may not use this file except in compliance with the License.
|
|
10 |
* You may obtain a copy of the License at
|
|
11 |
*
|
|
12 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13 |
*
|
|
14 |
* Unless required by applicable law or agreed to in writing, software
|
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17 |
* See the License for the specific language governing permissions and
|
|
18 |
* limitations under the License.
|
|
19 |
*/
|
|
20 |
/*
|
|
21 |
* $Id: ToTextSAXHandler.java,v 1.3 2005/09/28 13:49:08 pvedula Exp $
|
|
22 |
*/
|
|
23 |
package com.sun.org.apache.xml.internal.serializer;
|
|
24 |
|
|
25 |
import java.io.IOException;
|
|
26 |
import java.io.OutputStream;
|
|
27 |
import java.io.Writer;
|
|
28 |
import java.util.Properties;
|
|
29 |
|
|
30 |
import org.w3c.dom.Node;
|
|
31 |
import org.xml.sax.Attributes;
|
|
32 |
import org.xml.sax.ContentHandler;
|
|
33 |
import org.xml.sax.Locator;
|
|
34 |
import org.xml.sax.SAXException;
|
|
35 |
import org.xml.sax.ext.LexicalHandler;
|
|
36 |
|
|
37 |
/**
|
|
38 |
* This class converts SAX-like event to SAX events for
|
|
39 |
* xsl:output method "text".
|
|
40 |
*
|
|
41 |
* This class is only to be used internally. This class is not a public API.
|
|
42 |
*
|
|
43 |
* @xsl.usage internal
|
|
44 |
*/
|
|
45 |
public 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 |
super.setDocumentLocator(arg0);
|
|
263 |
}
|
|
264 |
|
|
265 |
/**
|
|
266 |
* @see org.xml.sax.ContentHandler#skippedEntity(String)
|
|
267 |
*/
|
|
268 |
public void skippedEntity(String arg0) throws SAXException
|
|
269 |
{
|
|
270 |
}
|
|
271 |
|
|
272 |
/**
|
|
273 |
* @see org.xml.sax.ContentHandler#startElement(String, String, String, Attributes)
|
|
274 |
*/
|
|
275 |
public void startElement(
|
|
276 |
String arg0,
|
|
277 |
String arg1,
|
|
278 |
String arg2,
|
|
279 |
Attributes arg3)
|
|
280 |
throws SAXException
|
|
281 |
{
|
|
282 |
flushPending();
|
|
283 |
super.startElement(arg0, arg1, arg2, arg3);
|
|
284 |
}
|
|
285 |
|
|
286 |
/**
|
|
287 |
* @see org.xml.sax.ext.LexicalHandler#endCDATA()
|
|
288 |
*/
|
|
289 |
public void endCDATA() throws SAXException
|
|
290 |
{
|
|
291 |
}
|
|
292 |
|
|
293 |
/**
|
|
294 |
* @see org.xml.sax.ext.LexicalHandler#endDTD()
|
|
295 |
*/
|
|
296 |
public void endDTD() throws SAXException
|
|
297 |
{
|
|
298 |
}
|
|
299 |
|
|
300 |
/**
|
|
301 |
* @see org.xml.sax.ext.LexicalHandler#startCDATA()
|
|
302 |
*/
|
|
303 |
public void startCDATA() throws SAXException
|
|
304 |
{
|
|
305 |
}
|
|
306 |
|
|
307 |
|
|
308 |
/**
|
|
309 |
* @see org.xml.sax.ext.LexicalHandler#startEntity(String)
|
|
310 |
*/
|
|
311 |
public void startEntity(String arg0) throws SAXException
|
|
312 |
{
|
|
313 |
}
|
|
314 |
|
|
315 |
|
|
316 |
/**
|
|
317 |
* From XSLTC
|
|
318 |
* @see ExtendedContentHandler#startElement(String)
|
|
319 |
*/
|
|
320 |
public void startElement(
|
|
321 |
String elementNamespaceURI,
|
|
322 |
String elementLocalName,
|
|
323 |
String elementName) throws SAXException
|
|
324 |
{
|
|
325 |
super.startElement(elementNamespaceURI, elementLocalName, elementName);
|
|
326 |
}
|
|
327 |
|
|
328 |
public void startElement(
|
|
329 |
String elementName) throws SAXException
|
|
330 |
{
|
|
331 |
super.startElement(elementName);
|
|
332 |
}
|
|
333 |
|
|
334 |
|
|
335 |
/**
|
|
336 |
* From XSLTC
|
|
337 |
* @see org.xml.sax.ContentHandler#endDocument()
|
|
338 |
*/
|
|
339 |
public void endDocument() throws SAXException {
|
|
340 |
|
|
341 |
flushPending();
|
|
342 |
m_saxHandler.endDocument();
|
|
343 |
|
|
344 |
if (m_tracer != null)
|
|
345 |
super.fireEndDoc();
|
|
346 |
}
|
|
347 |
|
|
348 |
/**
|
|
349 |
*
|
|
350 |
* @see ExtendedContentHandler#characters(String)
|
|
351 |
*/
|
|
352 |
public void characters(String characters)
|
|
353 |
throws SAXException
|
|
354 |
{
|
|
355 |
final int length = characters.length();
|
|
356 |
if (length > m_charsBuff.length)
|
|
357 |
{
|
|
358 |
m_charsBuff = new char[length*2 + 1];
|
|
359 |
}
|
|
360 |
characters.getChars(0, length, m_charsBuff, 0);
|
|
361 |
|
|
362 |
m_saxHandler.characters(m_charsBuff, 0, length);
|
|
363 |
|
|
364 |
}
|
|
365 |
/**
|
|
366 |
* @see org.xml.sax.ContentHandler#characters(char[], int, int)
|
|
367 |
*/
|
|
368 |
public void characters(char[] characters, int offset, int length)
|
|
369 |
throws SAXException
|
|
370 |
{
|
|
371 |
|
|
372 |
m_saxHandler.characters(characters, offset, length);
|
|
373 |
|
|
374 |
// time to fire off characters event
|
|
375 |
if (m_tracer != null)
|
|
376 |
super.fireCharEvent(characters, offset, length);
|
|
377 |
}
|
|
378 |
|
|
379 |
/**
|
|
380 |
* From XSLTC
|
|
381 |
*/
|
|
382 |
public void addAttribute(String name, String value)
|
|
383 |
{
|
|
384 |
// do nothing
|
|
385 |
}
|
|
386 |
|
|
387 |
|
|
388 |
public boolean startPrefixMapping(
|
|
389 |
String prefix,
|
|
390 |
String uri,
|
|
391 |
boolean shouldFlush)
|
|
392 |
throws SAXException
|
|
393 |
{
|
|
394 |
// no namespace support for HTML
|
|
395 |
return false;
|
|
396 |
}
|
|
397 |
|
|
398 |
|
|
399 |
public void startPrefixMapping(String prefix, String uri)
|
|
400 |
throws org.xml.sax.SAXException
|
|
401 |
{
|
|
402 |
// no namespace support for HTML
|
|
403 |
}
|
|
404 |
|
|
405 |
|
|
406 |
public void namespaceAfterStartElement(
|
|
407 |
final String prefix,
|
|
408 |
final String uri)
|
|
409 |
throws SAXException
|
|
410 |
{
|
|
411 |
// no namespace support for HTML
|
|
412 |
}
|
|
413 |
|
|
414 |
}
|