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.templates;
  58. //import org.w3c.dom.*;
  59. import org.xml.sax.*;
  60. import org.apache.xml.utils.QName;
  61. import org.apache.xalan.transformer.TransformerImpl;
  62. import org.apache.xalan.transformer.ResultTreeHandler;
  63. import javax.xml.transform.TransformerException;
  64. /**
  65. * <meta name="usage" content="advanced"/>
  66. * Implement a text literal.
  67. * @see <a href="http://www.w3.org/TR/xslt#section-Creating-Text">section-Creating-Text in XSLT Specification</a>
  68. */
  69. public class ElemTextLiteral extends ElemTemplateElement
  70. {
  71. /**
  72. * Tell if space should be preserved.
  73. * @serial
  74. */
  75. private boolean m_preserveSpace;
  76. /**
  77. * Set whether or not space should be preserved.
  78. *
  79. * @param v Boolean flag indicating whether
  80. * or not space should be preserved
  81. */
  82. public void setPreserveSpace(boolean v)
  83. {
  84. m_preserveSpace = v;
  85. }
  86. /**
  87. * Get whether or not space should be preserved.
  88. *
  89. * @return Boolean flag indicating whether
  90. * or not space should be preserved
  91. */
  92. public boolean getPreserveSpace()
  93. {
  94. return m_preserveSpace;
  95. }
  96. /**
  97. * The character array.
  98. * @serial
  99. */
  100. private char m_ch[];
  101. /**
  102. * The character array as a string.
  103. * @serial
  104. */
  105. private String m_str;
  106. /**
  107. * Set the characters that will be output to the result tree..
  108. *
  109. * @param v Array of characters that will be output to the result tree
  110. */
  111. public void setChars(char[] v)
  112. {
  113. m_ch = v;
  114. }
  115. /**
  116. * Get the characters that will be output to the result tree..
  117. *
  118. * @return Array of characters that will be output to the result tree
  119. */
  120. public char[] getChars()
  121. {
  122. return m_ch;
  123. }
  124. /**
  125. * Get the value of the node as a string.
  126. *
  127. * @return null
  128. */
  129. public synchronized String getNodeValue()
  130. {
  131. if(null == m_str)
  132. {
  133. m_str = new String(m_ch);
  134. }
  135. return m_str;
  136. }
  137. /**
  138. * Tells if this element should disable escaping.
  139. * @serial
  140. */
  141. private boolean m_disableOutputEscaping = false;
  142. /**
  143. * Set the "disable-output-escaping" attribute.
  144. * Normally, the xml output method escapes & and < (and
  145. * possibly other characters) when outputting text nodes.
  146. * This ensures that the output is well-formed XML. However,
  147. * it is sometimes convenient to be able to produce output
  148. * that is almost, but not quite well-formed XML; for
  149. * example, the output may include ill-formed sections
  150. * which are intended to be transformed into well-formed
  151. * XML by a subsequent non-XML aware process. For this reason,
  152. * XSLT provides a mechanism for disabling output escaping.
  153. * An xsl:value-of or xsl:text element may have a
  154. * disable-output-escaping attribute; the allowed values
  155. * are yes or no; the default is no; if the value is yes,
  156. * then a text node generated by instantiating the xsl:value-of
  157. * or xsl:text element should be output without any escaping.
  158. * @see <a href="http://www.w3.org/TR/xslt#disable-output-escaping">disable-output-escaping in XSLT Specification</a>
  159. *
  160. * @param v Boolean value for "disable-output-escaping" attribute.
  161. */
  162. public void setDisableOutputEscaping(boolean v)
  163. {
  164. m_disableOutputEscaping = v;
  165. }
  166. /**
  167. * Get the "disable-output-escaping" attribute.
  168. * Normally, the xml output method escapes & and < (and
  169. * possibly other characters) when outputting text nodes.
  170. * This ensures that the output is well-formed XML. However,
  171. * it is sometimes convenient to be able to produce output
  172. * that is almost, but not quite well-formed XML; for
  173. * example, the output may include ill-formed sections
  174. * which are intended to be transformed into well-formed
  175. * XML by a subsequent non-XML aware process. For this reason,
  176. * XSLT provides a mechanism for disabling output escaping.
  177. * An xsl:value-of or xsl:text element may have a
  178. * disable-output-escaping attribute; the allowed values
  179. * are yes or no; the default is no; if the value is yes,
  180. * then a text node generated by instantiating the xsl:value-of
  181. * or xsl:text element should be output without any escaping.
  182. * @see <a href="http://www.w3.org/TR/xslt#disable-output-escaping">disable-output-escaping in XSLT Specification</a>
  183. *
  184. * @return Boolean value of "disable-output-escaping" attribute.
  185. */
  186. public boolean getDisableOutputEscaping()
  187. {
  188. return m_disableOutputEscaping;
  189. }
  190. /**
  191. * Get an integer representation of the element type.
  192. *
  193. * @return An integer representation of the element, defined in the
  194. * Constants class.
  195. * @see org.apache.xalan.templates.Constants
  196. */
  197. public int getXSLToken()
  198. {
  199. return Constants.ELEMNAME_TEXTLITERALRESULT;
  200. }
  201. /**
  202. * Return the node name.
  203. *
  204. * @return The element's name
  205. */
  206. public String getNodeName()
  207. {
  208. return "#Text";
  209. }
  210. /**
  211. * Copy the text literal to the result tree.
  212. *
  213. * @param transformer non-null reference to the the current transform-time state.
  214. * @param sourceNode non-null reference to the <a href="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
  215. * @param mode reference, which may be null, to the <a href="http://www.w3.org/TR/xslt#modes">current mode</a>.
  216. *
  217. * @throws TransformerException
  218. */
  219. public void execute(
  220. TransformerImpl transformer)
  221. throws TransformerException
  222. {
  223. if (TransformerImpl.S_DEBUG)
  224. transformer.getTraceManager().fireTraceEvent(this);
  225. try
  226. {
  227. ResultTreeHandler rth = transformer.getResultTreeHandler();
  228. if (m_disableOutputEscaping)
  229. {
  230. rth.processingInstruction(javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, "");
  231. }
  232. rth.characters(m_ch, 0, m_ch.length);
  233. if (m_disableOutputEscaping)
  234. {
  235. rth.processingInstruction(javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, "");
  236. }
  237. }
  238. catch(SAXException se)
  239. {
  240. throw new TransformerException(se);
  241. }
  242. finally
  243. {
  244. if (TransformerImpl.S_DEBUG)
  245. transformer.getTraceManager().fireTraceEndEvent(this);
  246. }
  247. }
  248. }