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.apache.xml.dtm.DTM;
  60. import org.xml.sax.*;
  61. import org.apache.xalan.res.XSLTErrorResources;
  62. import org.apache.xalan.transformer.TransformerImpl;
  63. import java.io.*;
  64. import java.util.*;
  65. /**
  66. * <meta name="usage" content="advanced"/>
  67. * Implement xsl:template.
  68. * This primarily acts as a marker on the element
  69. * stack to signal that whitespace should be preserved.
  70. * <pre>
  71. * <!ELEMENT xsl:text (#PCDATA)>
  72. * <!ATTLIST xsl:text
  73. * disable-output-escaping (yes|no) "no"
  74. * >
  75. * </pre>
  76. * @see <a href="http://www.w3.org/TR/xslt#section-Creating-Text">section-Creating-Text in XSLT Specification</a>
  77. */
  78. public class ElemText extends ElemTemplateElement
  79. {
  80. /**
  81. * Tells if this element should disable escaping.
  82. * @serial
  83. */
  84. private boolean m_disableOutputEscaping = false;
  85. /**
  86. * Set the "disable-output-escaping" attribute.
  87. * Normally, the xml output method escapes & and < (and
  88. * possibly other characters) when outputting text nodes.
  89. * This ensures that the output is well-formed XML. However,
  90. * it is sometimes convenient to be able to produce output
  91. * that is almost, but not quite well-formed XML; for
  92. * example, the output may include ill-formed sections
  93. * which are intended to be transformed into well-formed
  94. * XML by a subsequent non-XML aware process. For this reason,
  95. * XSLT provides a mechanism for disabling output escaping.
  96. * An xsl:value-of or xsl:text element may have a
  97. * disable-output-escaping attribute; the allowed values
  98. * are yes or no; the default is no; if the value is yes,
  99. * then a text node generated by instantiating the xsl:value-of
  100. * or xsl:text element should be output without any escaping.
  101. * @see <a href="http://www.w3.org/TR/xslt#disable-output-escaping">disable-output-escaping in XSLT Specification</a>
  102. *
  103. * @param v Boolean flag indicating whether this element should disable escaping
  104. */
  105. public void setDisableOutputEscaping(boolean v)
  106. {
  107. m_disableOutputEscaping = v;
  108. }
  109. /**
  110. * Get the "disable-output-escaping" attribute.
  111. * Normally, the xml output method escapes & and < (and
  112. * possibly other characters) when outputting text nodes.
  113. * This ensures that the output is well-formed XML. However,
  114. * it is sometimes convenient to be able to produce output
  115. * that is almost, but not quite well-formed XML; for
  116. * example, the output may include ill-formed sections
  117. * which are intended to be transformed into well-formed
  118. * XML by a subsequent non-XML aware process. For this reason,
  119. * XSLT provides a mechanism for disabling output escaping.
  120. * An xsl:value-of or xsl:text element may have a
  121. * disable-output-escaping attribute; the allowed values
  122. * are yes or no; the default is no; if the value is yes,
  123. * then a text node generated by instantiating the xsl:value-of
  124. * or xsl:text element should be output without any escaping.
  125. * @see <a href="http://www.w3.org/TR/xslt#disable-output-escaping">disable-output-escaping in XSLT Specification</a>
  126. *
  127. * @return Boolean flag indicating whether this element should disable escaping
  128. */
  129. public boolean getDisableOutputEscaping()
  130. {
  131. return m_disableOutputEscaping;
  132. }
  133. /**
  134. * Get an integer representation of the element type.
  135. *
  136. * @return An integer representation of the element, defined in the
  137. * Constants class.
  138. * @see org.apache.xalan.templates.Constants
  139. */
  140. public int getXSLToken()
  141. {
  142. return Constants.ELEMNAME_TEXT;
  143. }
  144. /**
  145. * Return the node name.
  146. *
  147. * @return The element's name
  148. */
  149. public String getNodeName()
  150. {
  151. return Constants.ELEMNAME_TEXT_STRING;
  152. }
  153. /**
  154. * Add a child to the child list.
  155. *
  156. * @param newChild Child to add to children list
  157. *
  158. * @return Child added to children list
  159. *
  160. * @throws DOMException
  161. */
  162. public ElemTemplateElement appendChild(ElemTemplateElement newChild)
  163. {
  164. int type = ((ElemTemplateElement) newChild).getXSLToken();
  165. switch (type)
  166. {
  167. case Constants.ELEMNAME_TEXTLITERALRESULT :
  168. break;
  169. default :
  170. error(XSLTErrorResources.ER_CANNOT_ADD,
  171. new Object[]{ newChild.getNodeName(),
  172. this.getNodeName() }); //"Can not add " +((ElemTemplateElement)newChild).m_elemName +
  173. //" to " + this.m_elemName);
  174. }
  175. return super.appendChild(newChild);
  176. }
  177. }