KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > templates > ElemTextLiteral


1 /*
2  * Copyright 1999-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: ElemTextLiteral.java,v 1.16 2004/02/16 20:32:32 minchau Exp $
18  */

19 package org.apache.xalan.templates;
20
21 import javax.xml.transform.TransformerException JavaDoc;
22
23 import org.apache.xalan.transformer.TransformerImpl;
24 import org.apache.xml.serializer.SerializationHandler;
25 import org.xml.sax.SAXException JavaDoc;
26
27 /**
28  * Implement a text literal.
29  * @see <a HREF="http://www.w3.org/TR/xslt#section-Creating-Text">section-Creating-Text in XSLT Specification</a>
30  * @xsl.usage advanced
31  */

32 public class ElemTextLiteral extends ElemTemplateElement
33 {
34
35   /**
36    * Tell if space should be preserved.
37    * @serial
38    */

39   private boolean m_preserveSpace;
40
41   /**
42    * Set whether or not space should be preserved.
43    *
44    * @param v Boolean flag indicating whether
45    * or not space should be preserved
46    */

47   public void setPreserveSpace(boolean v)
48   {
49     m_preserveSpace = v;
50   }
51
52   /**
53    * Get whether or not space should be preserved.
54    *
55    * @return Boolean flag indicating whether
56    * or not space should be preserved
57    */

58   public boolean getPreserveSpace()
59   {
60     return m_preserveSpace;
61   }
62
63   /**
64    * The character array.
65    * @serial
66    */

67   private char m_ch[];
68   
69   /**
70    * The character array as a string.
71    * @serial
72    */

73   private String JavaDoc m_str;
74
75   /**
76    * Set the characters that will be output to the result tree..
77    *
78    * @param v Array of characters that will be output to the result tree
79    */

80   public void setChars(char[] v)
81   {
82     m_ch = v;
83   }
84
85   /**
86    * Get the characters that will be output to the result tree..
87    *
88    * @return Array of characters that will be output to the result tree
89    */

90   public char[] getChars()
91   {
92     return m_ch;
93   }
94   
95   /**
96    * Get the value of the node as a string.
97    *
98    * @return null
99    */

100   public synchronized String JavaDoc getNodeValue()
101   {
102
103     if(null == m_str)
104     {
105       m_str = new String JavaDoc(m_ch);
106     }
107
108     return m_str;
109   }
110
111
112   /**
113    * Tells if this element should disable escaping.
114    * @serial
115    */

116   private boolean m_disableOutputEscaping = false;
117
118   /**
119    * Set the "disable-output-escaping" attribute.
120    * Normally, the xml output method escapes & and < (and
121    * possibly other characters) when outputting text nodes.
122    * This ensures that the output is well-formed XML. However,
123    * it is sometimes convenient to be able to produce output
124    * that is almost, but not quite well-formed XML; for
125    * example, the output may include ill-formed sections
126    * which are intended to be transformed into well-formed
127    * XML by a subsequent non-XML aware process. For this reason,
128    * XSLT provides a mechanism for disabling output escaping.
129    * An xsl:value-of or xsl:text element may have a
130    * disable-output-escaping attribute; the allowed values
131    * are yes or no; the default is no; if the value is yes,
132    * then a text node generated by instantiating the xsl:value-of
133    * or xsl:text element should be output without any escaping.
134    * @see <a HREF="http://www.w3.org/TR/xslt#disable-output-escaping">disable-output-escaping in XSLT Specification</a>
135    *
136    * @param v Boolean value for "disable-output-escaping" attribute.
137    */

138   public void setDisableOutputEscaping(boolean v)
139   {
140     m_disableOutputEscaping = v;
141   }
142
143   /**
144    * Get the "disable-output-escaping" attribute.
145    * Normally, the xml output method escapes & and < (and
146    * possibly other characters) when outputting text nodes.
147    * This ensures that the output is well-formed XML. However,
148    * it is sometimes convenient to be able to produce output
149    * that is almost, but not quite well-formed XML; for
150    * example, the output may include ill-formed sections
151    * which are intended to be transformed into well-formed
152    * XML by a subsequent non-XML aware process. For this reason,
153    * XSLT provides a mechanism for disabling output escaping.
154    * An xsl:value-of or xsl:text element may have a
155    * disable-output-escaping attribute; the allowed values
156    * are yes or no; the default is no; if the value is yes,
157    * then a text node generated by instantiating the xsl:value-of
158    * or xsl:text element should be output without any escaping.
159    * @see <a HREF="http://www.w3.org/TR/xslt#disable-output-escaping">disable-output-escaping in XSLT Specification</a>
160    *
161    * @return Boolean value of "disable-output-escaping" attribute.
162    */

163   public boolean getDisableOutputEscaping()
164   {
165     return m_disableOutputEscaping;
166   }
167
168   /**
169    * Get an integer representation of the element type.
170    *
171    * @return An integer representation of the element, defined in the
172    * Constants class.
173    * @see org.apache.xalan.templates.Constants
174    */

175   public int getXSLToken()
176   {
177     return Constants.ELEMNAME_TEXTLITERALRESULT;
178   }
179
180   /**
181    * Return the node name.
182    *
183    * @return The element's name
184    */

185   public String JavaDoc getNodeName()
186   {
187     return "#Text";
188   }
189
190   /**
191    * Copy the text literal to the result tree.
192    *
193    * @param transformer non-null reference to the the current transform-time state.
194    * @param sourceNode non-null reference to the <a HREF="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
195    * @param mode reference, which may be null, to the <a HREF="http://www.w3.org/TR/xslt#modes">current mode</a>.
196    *
197    * @throws TransformerException
198    */

199   public void execute(
200           TransformerImpl transformer)
201             throws TransformerException JavaDoc
202   {
203     try
204     {
205       SerializationHandler rth = transformer.getResultTreeHandler();
206       if (TransformerImpl.S_DEBUG) {
207         // flush any pending cached processing before the trace event.
208
rth.flushPending();
209         transformer.getTraceManager().fireTraceEvent(this);
210       }
211
212       if (m_disableOutputEscaping)
213       {
214         rth.processingInstruction(javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, "");
215       }
216
217       rth.characters(m_ch, 0, m_ch.length);
218
219       if (m_disableOutputEscaping)
220       {
221         rth.processingInstruction(javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, "");
222       }
223     }
224     catch(SAXException JavaDoc se)
225     {
226       throw new TransformerException JavaDoc(se);
227     }
228     finally
229     {
230       if (TransformerImpl.S_DEBUG) {
231         try
232         {
233             // flush any pending cached processing before sending the trace event
234
transformer.getResultTreeHandler().flushPending();
235             transformer.getTraceManager().fireTraceEndEvent(this);
236         }
237         catch (SAXException JavaDoc se)
238         {
239             throw new TransformerException JavaDoc(se);
240         }
241       }
242     }
243   }
244 }
245
Popular Tags