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