1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xalan" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, Lotus
  53. * Development Corporation., http://www.lotus.com. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package org.apache.xalan.trace;
  58. import org.xml.sax.*;
  59. import java.util.*;
  60. import java.io.*;
  61. import org.apache.xalan.transformer.TransformerImpl;
  62. /**
  63. * <meta name="usage" content="advanced"/>
  64. * Event generated by the XSL processor after it generates a new node in the result tree.
  65. * This event responds to and is modeled on the SAX events that are sent to the
  66. * formatter listener FormatterToXXX)classes.
  67. *
  68. * @see org.apache.xml.utils.DOMBuilder
  69. * @see org.apache.xalan.serialize.SerializerToHTML
  70. * @see org.apache.xalan.serialize.SerializerToText
  71. * @see org.apache.xalan.serialize.SerializerToXML
  72. *
  73. */
  74. public class GenerateEvent implements java.util.EventListener
  75. {
  76. /**
  77. * The XSLT Transformer, which either directly or indirectly contains most needed information.
  78. *
  79. * @see org.apache.xalan.transformer.TransformerImpl
  80. */
  81. public TransformerImpl m_processor;
  82. /**
  83. * The type of SAX event that was generated, as enumerated in the EVENTTYPE_XXX constants below.
  84. */
  85. public int m_eventtype;
  86. /**
  87. * Event type generated when a document begins.
  88. *
  89. */
  90. public static final int EVENTTYPE_STARTDOCUMENT = 1;
  91. /**
  92. * Event type generated when a document ends.
  93. */
  94. public static final int EVENTTYPE_ENDDOCUMENT = 2;
  95. /**
  96. * Event type generated when an element begins (after the attributes have been processed but before the children have been added).
  97. */
  98. public static final int EVENTTYPE_STARTELEMENT = 3;
  99. /**
  100. * Event type generated when an element ends, after it's children have been added.
  101. */
  102. public static final int EVENTTYPE_ENDELEMENT = 4;
  103. /**
  104. * Event type generated for character data (CDATA and Ignorable Whitespace have their own events).
  105. */
  106. public static final int EVENTTYPE_CHARACTERS = 5;
  107. /**
  108. * Event type generated for ignorable whitespace (I'm not sure how much this is actually called.
  109. */
  110. public static final int EVENTTYPE_IGNORABLEWHITESPACE = 6;
  111. /**
  112. * Event type generated for processing instructions.
  113. */
  114. public static final int EVENTTYPE_PI = 7;
  115. /**
  116. * Event type generated after a comment has been added.
  117. */
  118. public static final int EVENTTYPE_COMMENT = 8;
  119. /**
  120. * Event type generate after an entity ref is created.
  121. */
  122. public static final int EVENTTYPE_ENTITYREF = 9;
  123. /**
  124. * Event type generated after CDATA is generated.
  125. */
  126. public static final int EVENTTYPE_CDATA = 10;
  127. /**
  128. * Character data from a character or cdata event.
  129. */
  130. public char m_characters[];
  131. /**
  132. * The start position of the current data in m_characters.
  133. */
  134. public int m_start;
  135. /**
  136. * The length of the current data in m_characters.
  137. */
  138. public int m_length;
  139. /**
  140. * The name of the element or PI.
  141. */
  142. public String m_name;
  143. /**
  144. * The string data in the element (comments and PIs).
  145. */
  146. public String m_data;
  147. /**
  148. * The current attribute list.
  149. */
  150. public Attributes m_atts;
  151. /**
  152. * Constructor for startDocument, endDocument events.
  153. *
  154. * @param processor The XSLT TransformerFactory instance.
  155. * @param eventType One of the EVENTTYPE_XXX constants.
  156. */
  157. public GenerateEvent(TransformerImpl processor, int eventType)
  158. {
  159. m_processor = processor;
  160. m_eventtype = eventType;
  161. }
  162. /**
  163. * Constructor for startElement, endElement events.
  164. *
  165. * @param processor The XSLT TransformerFactory Instance.
  166. * @param eventType One of the EVENTTYPE_XXX constants.
  167. * @param name The name of the element.
  168. * @param atts The SAX attribute list.
  169. */
  170. public GenerateEvent(TransformerImpl processor, int eventType, String name,
  171. Attributes atts)
  172. {
  173. m_name = name;
  174. m_atts = atts;
  175. m_processor = processor;
  176. m_eventtype = eventType;
  177. }
  178. /**
  179. * Constructor for characters, cdate events.
  180. *
  181. * @param processor The XSLT TransformerFactory instance.
  182. * @param eventType One of the EVENTTYPE_XXX constants.
  183. * @param ch The char array from the SAX event.
  184. * @param start The start offset to be used in the char array.
  185. * @param length The end offset to be used in the chara array.
  186. */
  187. public GenerateEvent(TransformerImpl processor, int eventType, char ch[],
  188. int start, int length)
  189. {
  190. m_characters = ch;
  191. m_start = start;
  192. m_length = length;
  193. m_processor = processor;
  194. m_eventtype = eventType;
  195. }
  196. /**
  197. * Constructor for processingInstruction events.
  198. *
  199. * @param processor The instance of the XSLT processor.
  200. * @param eventType One of the EVENTTYPE_XXX constants.
  201. * @param name The name of the processing instruction.
  202. * @param data The processing instruction data.
  203. */
  204. public GenerateEvent(TransformerImpl processor, int eventType, String name,
  205. String data)
  206. {
  207. m_name = name;
  208. m_data = data;
  209. m_processor = processor;
  210. m_eventtype = eventType;
  211. }
  212. /**
  213. * Constructor for comment and entity ref events.
  214. *
  215. * @param processor The XSLT processor instance.
  216. * @param eventType One of the EVENTTYPE_XXX constants.
  217. * @param data The comment or entity ref data.
  218. */
  219. public GenerateEvent(TransformerImpl processor, int eventType, String data)
  220. {
  221. m_data = data;
  222. m_processor = processor;
  223. m_eventtype = eventType;
  224. }
  225. }