1. /*
  2. * Copyright 2001-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*
  17. * $Id: ToTextSAXHandler.java,v 1.5 2004/02/17 04:18:18 minchau Exp $
  18. */
  19. package com.sun.org.apache.xml.internal.serializer;
  20. import java.io.IOException;
  21. import java.io.OutputStream;
  22. import java.io.Writer;
  23. import java.util.Properties;
  24. import org.w3c.dom.Node;
  25. import org.xml.sax.Attributes;
  26. import org.xml.sax.ContentHandler;
  27. import org.xml.sax.Locator;
  28. import org.xml.sax.SAXException;
  29. import org.xml.sax.ext.LexicalHandler;
  30. /**
  31. * @author minchau
  32. *
  33. * To change this generated comment edit the template variable "typecomment":
  34. * Window>Preferences>Java>Templates.
  35. * To enable and disable the creation of type comments go to
  36. * Window>Preferences>Java>Code Generation.
  37. * @author Santiago Pericas-Geertsen
  38. */
  39. public class ToTextSAXHandler extends ToSAXHandler
  40. {
  41. /**
  42. * From XSLTC
  43. * @see com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler#endElement(String)
  44. */
  45. public void endElement(String elemName) throws SAXException
  46. {
  47. if (m_tracer != null)
  48. super.fireEndElem(elemName);
  49. }
  50. /**
  51. * @see org.xml.sax.ContentHandler#endElement(String, String, String)
  52. */
  53. public void endElement(String arg0, String arg1, String arg2)
  54. throws SAXException
  55. {
  56. if (m_tracer != null)
  57. super.fireEndElem(arg2);
  58. }
  59. public ToTextSAXHandler(ContentHandler hdlr, LexicalHandler lex, String encoding)
  60. {
  61. super(hdlr, lex, encoding);
  62. }
  63. /**
  64. * From XSLTC
  65. */
  66. public ToTextSAXHandler(ContentHandler handler, String encoding)
  67. {
  68. super(handler,encoding);
  69. }
  70. public void comment(char ch[], int start, int length)
  71. throws org.xml.sax.SAXException
  72. {
  73. if (m_tracer != null)
  74. super.fireCommentEvent(ch, start, length);
  75. }
  76. public void comment(String data) throws org.xml.sax.SAXException
  77. {
  78. final int length = data.length();
  79. if (length > m_charsBuff.length)
  80. {
  81. m_charsBuff = new char[length*2 + 1];
  82. }
  83. data.getChars(0, length, m_charsBuff, 0);
  84. comment(m_charsBuff, 0, length);
  85. }
  86. /**
  87. * @see com.sun.org.apache.xml.internal.serializer.Serializer#getOutputFormat()
  88. */
  89. public Properties getOutputFormat()
  90. {
  91. return null;
  92. }
  93. /**
  94. * @see com.sun.org.apache.xml.internal.serializer.Serializer#getOutputStream()
  95. */
  96. public OutputStream getOutputStream()
  97. {
  98. return null;
  99. }
  100. /**
  101. * @see com.sun.org.apache.xml.internal.serializer.Serializer#getWriter()
  102. */
  103. public Writer getWriter()
  104. {
  105. return null;
  106. }
  107. /**
  108. * Does nothing because
  109. * the indent attribute is ignored for text output.
  110. *
  111. */
  112. public void indent(int n) throws SAXException
  113. {
  114. }
  115. /**
  116. * @see com.sun.org.apache.xml.internal.serializer.Serializer#reset()
  117. */
  118. public boolean reset()
  119. {
  120. return false;
  121. }
  122. /**
  123. * @see com.sun.org.apache.xml.internal.serializer.DOMSerializer#serialize(Node)
  124. */
  125. public void serialize(Node node) throws IOException
  126. {
  127. }
  128. /**
  129. * @see com.sun.org.apache.xml.internal.serializer.SerializationHandler#setEscaping(boolean)
  130. */
  131. public boolean setEscaping(boolean escape)
  132. {
  133. return false;
  134. }
  135. /**
  136. * @see com.sun.org.apache.xml.internal.serializer.SerializationHandler#setIndent(boolean)
  137. */
  138. public void setIndent(boolean indent)
  139. {
  140. }
  141. /**
  142. * @see com.sun.org.apache.xml.internal.serializer.Serializer#setOutputFormat(Properties)
  143. */
  144. public void setOutputFormat(Properties format)
  145. {
  146. }
  147. /**
  148. * @see com.sun.org.apache.xml.internal.serializer.Serializer#setOutputStream(OutputStream)
  149. */
  150. public void setOutputStream(OutputStream output)
  151. {
  152. }
  153. /**
  154. * @see com.sun.org.apache.xml.internal.serializer.Serializer#setWriter(Writer)
  155. */
  156. public void setWriter(Writer writer)
  157. {
  158. }
  159. /**
  160. * @see com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler#addAttribute(String, String, String, String, String)
  161. */
  162. public void addAttribute(
  163. String uri,
  164. String localName,
  165. String rawName,
  166. String type,
  167. String value)
  168. {
  169. }
  170. /**
  171. * @see org.xml.sax.ext.DeclHandler#attributeDecl(String, String, String, String, String)
  172. */
  173. public void attributeDecl(
  174. String arg0,
  175. String arg1,
  176. String arg2,
  177. String arg3,
  178. String arg4)
  179. throws SAXException
  180. {
  181. }
  182. /**
  183. * @see org.xml.sax.ext.DeclHandler#elementDecl(String, String)
  184. */
  185. public void elementDecl(String arg0, String arg1) throws SAXException
  186. {
  187. }
  188. /**
  189. * @see org.xml.sax.ext.DeclHandler#externalEntityDecl(String, String, String)
  190. */
  191. public void externalEntityDecl(String arg0, String arg1, String arg2)
  192. throws SAXException
  193. {
  194. }
  195. /**
  196. * @see org.xml.sax.ext.DeclHandler#internalEntityDecl(String, String)
  197. */
  198. public void internalEntityDecl(String arg0, String arg1)
  199. throws SAXException
  200. {
  201. }
  202. /**
  203. * @see org.xml.sax.ContentHandler#endPrefixMapping(String)
  204. */
  205. public void endPrefixMapping(String arg0) throws SAXException
  206. {
  207. }
  208. /**
  209. * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
  210. */
  211. public void ignorableWhitespace(char[] arg0, int arg1, int arg2)
  212. throws SAXException
  213. {
  214. }
  215. /**
  216. * From XSLTC
  217. * @see org.xml.sax.ContentHandler#processingInstruction(String, String)
  218. */
  219. public void processingInstruction(String arg0, String arg1)
  220. throws SAXException
  221. {
  222. if (m_tracer != null)
  223. super.fireEscapingEvent(arg0, arg1);
  224. }
  225. /**
  226. * @see org.xml.sax.ContentHandler#setDocumentLocator(Locator)
  227. */
  228. public void setDocumentLocator(Locator arg0)
  229. {
  230. }
  231. /**
  232. * @see org.xml.sax.ContentHandler#skippedEntity(String)
  233. */
  234. public void skippedEntity(String arg0) throws SAXException
  235. {
  236. }
  237. /**
  238. * @see org.xml.sax.ContentHandler#startElement(String, String, String, Attributes)
  239. */
  240. public void startElement(
  241. String arg0,
  242. String arg1,
  243. String arg2,
  244. Attributes arg3)
  245. throws SAXException
  246. {
  247. flushPending();
  248. super.startElement(arg0, arg1, arg2, arg3);
  249. }
  250. /**
  251. * @see org.xml.sax.ext.LexicalHandler#endCDATA()
  252. */
  253. public void endCDATA() throws SAXException
  254. {
  255. }
  256. /**
  257. * @see org.xml.sax.ext.LexicalHandler#endDTD()
  258. */
  259. public void endDTD() throws SAXException
  260. {
  261. }
  262. /**
  263. * @see org.xml.sax.ext.LexicalHandler#startCDATA()
  264. */
  265. public void startCDATA() throws SAXException
  266. {
  267. }
  268. /**
  269. * @see org.xml.sax.ext.LexicalHandler#startEntity(String)
  270. */
  271. public void startEntity(String arg0) throws SAXException
  272. {
  273. }
  274. /**
  275. * From XSLTC
  276. * @see com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler#startElement(String)
  277. */
  278. public void startElement(
  279. String elementNamespaceURI,
  280. String elementLocalName,
  281. String elementName) throws SAXException
  282. {
  283. super.startElement(elementNamespaceURI, elementLocalName, elementName);
  284. }
  285. public void startElement(
  286. String elementName) throws SAXException
  287. {
  288. super.startElement(elementName);
  289. }
  290. /**
  291. * From XSLTC
  292. * @see org.xml.sax.ContentHandler#endDocument()
  293. */
  294. public void endDocument() throws SAXException {
  295. flushPending();
  296. m_saxHandler.endDocument();
  297. if (m_tracer != null)
  298. super.fireEndDoc();
  299. }
  300. /**
  301. *
  302. * @see com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler#characters(String)
  303. */
  304. public void characters(String characters)
  305. throws SAXException
  306. {
  307. final int length = characters.length();
  308. if (length > m_charsBuff.length)
  309. {
  310. m_charsBuff = new char[length*2 + 1];
  311. }
  312. characters.getChars(0, length, m_charsBuff, 0);
  313. m_saxHandler.characters(m_charsBuff, 0, length);
  314. }
  315. /**
  316. * @see org.xml.sax.ContentHandler#characters(char[], int, int)
  317. */
  318. public void characters(char[] characters, int offset, int length)
  319. throws SAXException
  320. {
  321. m_saxHandler.characters(characters, offset, length);
  322. // time to fire off characters event
  323. if (m_tracer != null)
  324. super.fireCharEvent(characters, offset, length);
  325. }
  326. /**
  327. * From XSLTC
  328. */
  329. public void addAttribute(String name, String value)
  330. {
  331. // do nothing
  332. }
  333. public boolean startPrefixMapping(
  334. String prefix,
  335. String uri,
  336. boolean shouldFlush)
  337. throws SAXException
  338. {
  339. // no namespace support for HTML
  340. return false;
  341. }
  342. public void startPrefixMapping(String prefix, String uri)
  343. throws org.xml.sax.SAXException
  344. {
  345. // no namespace support for HTML
  346. }
  347. public void namespaceAfterStartElement(
  348. final String prefix,
  349. final String uri)
  350. throws SAXException
  351. {
  352. // no namespace support for HTML
  353. }
  354. }