KickJava   Java API By Example, From Geeks To Geeks.

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


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: ElemText.java,v 1.9 2004/02/16 20:32:32 minchau Exp $
18  */

19 package org.apache.xalan.templates;
20
21 import org.apache.xalan.res.XSLTErrorResources;
22
23 /**
24  * Implement xsl:template.
25  * This primarily acts as a marker on the element
26  * stack to signal that whitespace should be preserved.
27  * <pre>
28  * <!ELEMENT xsl:text (#PCDATA)>
29  * <!ATTLIST xsl:text
30  * disable-output-escaping (yes|no) "no"
31  * >
32  * </pre>
33  * @see <a HREF="http://www.w3.org/TR/xslt#section-Creating-Text">section-Creating-Text in XSLT Specification</a>
34  * @xsl.usage advanced
35  */

36 public class ElemText extends ElemTemplateElement
37 {
38
39   /**
40    * Tells if this element should disable escaping.
41    * @serial
42    */

43   private boolean m_disableOutputEscaping = false;
44
45   /**
46    * Set the "disable-output-escaping" attribute.
47    * Normally, the xml output method escapes & and < (and
48    * possibly other characters) when outputting text nodes.
49    * This ensures that the output is well-formed XML. However,
50    * it is sometimes convenient to be able to produce output
51    * that is almost, but not quite well-formed XML; for
52    * example, the output may include ill-formed sections
53    * which are intended to be transformed into well-formed
54    * XML by a subsequent non-XML aware process. For this reason,
55    * XSLT provides a mechanism for disabling output escaping.
56    * An xsl:value-of or xsl:text element may have a
57    * disable-output-escaping attribute; the allowed values
58    * are yes or no; the default is no; if the value is yes,
59    * then a text node generated by instantiating the xsl:value-of
60    * or xsl:text element should be output without any escaping.
61    * @see <a HREF="http://www.w3.org/TR/xslt#disable-output-escaping">disable-output-escaping in XSLT Specification</a>
62    *
63    * @param v Boolean flag indicating whether this element should disable escaping
64    */

65   public void setDisableOutputEscaping(boolean v)
66   {
67     m_disableOutputEscaping = v;
68   }
69
70   /**
71    * Get the "disable-output-escaping" attribute.
72    * Normally, the xml output method escapes & and < (and
73    * possibly other characters) when outputting text nodes.
74    * This ensures that the output is well-formed XML. However,
75    * it is sometimes convenient to be able to produce output
76    * that is almost, but not quite well-formed XML; for
77    * example, the output may include ill-formed sections
78    * which are intended to be transformed into well-formed
79    * XML by a subsequent non-XML aware process. For this reason,
80    * XSLT provides a mechanism for disabling output escaping.
81    * An xsl:value-of or xsl:text element may have a
82    * disable-output-escaping attribute; the allowed values
83    * are yes or no; the default is no; if the value is yes,
84    * then a text node generated by instantiating the xsl:value-of
85    * or xsl:text element should be output without any escaping.
86    * @see <a HREF="http://www.w3.org/TR/xslt#disable-output-escaping">disable-output-escaping in XSLT Specification</a>
87    *
88    * @return Boolean flag indicating whether this element should disable escaping
89    */

90   public boolean getDisableOutputEscaping()
91   {
92     return m_disableOutputEscaping;
93   }
94
95   /**
96    * Get an integer representation of the element type.
97    *
98    * @return An integer representation of the element, defined in the
99    * Constants class.
100    * @see org.apache.xalan.templates.Constants
101    */

102   public int getXSLToken()
103   {
104     return Constants.ELEMNAME_TEXT;
105   }
106
107   /**
108    * Return the node name.
109    *
110    * @return The element's name
111    */

112   public String JavaDoc getNodeName()
113   {
114     return Constants.ELEMNAME_TEXT_STRING;
115   }
116
117   /**
118    * Add a child to the child list.
119    *
120    * @param newChild Child to add to children list
121    *
122    * @return Child added to children list
123    *
124    * @throws DOMException
125    */

126   public ElemTemplateElement appendChild(ElemTemplateElement newChild)
127   {
128
129     int type = ((ElemTemplateElement) newChild).getXSLToken();
130
131     switch (type)
132     {
133     case Constants.ELEMNAME_TEXTLITERALRESULT :
134       break;
135     default :
136       error(XSLTErrorResources.ER_CANNOT_ADD,
137             new Object JavaDoc[]{ newChild.getNodeName(),
138                           this.getNodeName() }); //"Can not add " +((ElemTemplateElement)newChild).m_elemName +
139

140     //" to " + this.m_elemName);
141
}
142
143     return super.appendChild(newChild);
144   }
145 }
146
Popular Tags