001: /*
002: * Copyright 1999-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: /*
017: * $Id: ElemText.java,v 1.10 2004/08/17 18:35:33 jycli Exp $
018: */
019: package org.apache.xalan.templates;
020:
021: import org.apache.xalan.res.XSLTErrorResources;
022:
023: /**
024: * Implement xsl:template.
025: * This primarily acts as a marker on the element
026: * stack to signal that whitespace should be preserved.
027: * <pre>
028: * <!ELEMENT xsl:text (#PCDATA)>
029: * <!ATTLIST xsl:text
030: * disable-output-escaping (yes|no) "no"
031: * >
032: * </pre>
033: * @see <a href="http://www.w3.org/TR/xslt#section-Creating-Text">section-Creating-Text in XSLT Specification</a>
034: * @xsl.usage advanced
035: */
036: public class ElemText extends ElemTemplateElement {
037: static final long serialVersionUID = 1383140876182316711L;
038:
039: /**
040: * Tells if this element should disable escaping.
041: * @serial
042: */
043: private boolean m_disableOutputEscaping = false;
044:
045: /**
046: * Set the "disable-output-escaping" attribute.
047: * Normally, the xml output method escapes & and < (and
048: * possibly other characters) when outputting text nodes.
049: * This ensures that the output is well-formed XML. However,
050: * it is sometimes convenient to be able to produce output
051: * that is almost, but not quite well-formed XML; for
052: * example, the output may include ill-formed sections
053: * which are intended to be transformed into well-formed
054: * XML by a subsequent non-XML aware process. For this reason,
055: * XSLT provides a mechanism for disabling output escaping.
056: * An xsl:value-of or xsl:text element may have a
057: * disable-output-escaping attribute; the allowed values
058: * are yes or no; the default is no; if the value is yes,
059: * then a text node generated by instantiating the xsl:value-of
060: * or xsl:text element should be output without any escaping.
061: * @see <a href="http://www.w3.org/TR/xslt#disable-output-escaping">disable-output-escaping in XSLT Specification</a>
062: *
063: * @param v Boolean flag indicating whether this element should disable escaping
064: */
065: public void setDisableOutputEscaping(boolean v) {
066: m_disableOutputEscaping = v;
067: }
068:
069: /**
070: * Get the "disable-output-escaping" attribute.
071: * Normally, the xml output method escapes & and < (and
072: * possibly other characters) when outputting text nodes.
073: * This ensures that the output is well-formed XML. However,
074: * it is sometimes convenient to be able to produce output
075: * that is almost, but not quite well-formed XML; for
076: * example, the output may include ill-formed sections
077: * which are intended to be transformed into well-formed
078: * XML by a subsequent non-XML aware process. For this reason,
079: * XSLT provides a mechanism for disabling output escaping.
080: * An xsl:value-of or xsl:text element may have a
081: * disable-output-escaping attribute; the allowed values
082: * are yes or no; the default is no; if the value is yes,
083: * then a text node generated by instantiating the xsl:value-of
084: * or xsl:text element should be output without any escaping.
085: * @see <a href="http://www.w3.org/TR/xslt#disable-output-escaping">disable-output-escaping in XSLT Specification</a>
086: *
087: * @return Boolean flag indicating whether this element should disable escaping
088: */
089: public boolean getDisableOutputEscaping() {
090: return m_disableOutputEscaping;
091: }
092:
093: /**
094: * Get an integer representation of the element type.
095: *
096: * @return An integer representation of the element, defined in the
097: * Constants class.
098: * @see org.apache.xalan.templates.Constants
099: */
100: public int getXSLToken() {
101: return Constants.ELEMNAME_TEXT;
102: }
103:
104: /**
105: * Return the node name.
106: *
107: * @return The element's name
108: */
109: public String getNodeName() {
110: return Constants.ELEMNAME_TEXT_STRING;
111: }
112:
113: /**
114: * Add a child to the child list.
115: *
116: * @param newChild Child to add to children list
117: *
118: * @return Child added to children list
119: *
120: * @throws DOMException
121: */
122: public ElemTemplateElement appendChild(ElemTemplateElement newChild) {
123:
124: int type = ((ElemTemplateElement) newChild).getXSLToken();
125:
126: switch (type) {
127: case Constants.ELEMNAME_TEXTLITERALRESULT:
128: break;
129: default:
130: error(XSLTErrorResources.ER_CANNOT_ADD, new Object[] {
131: newChild.getNodeName(), this .getNodeName() }); //"Can not add " +((ElemTemplateElement)newChild).m_elemName +
132:
133: //" to " + this.m_elemName);
134: }
135:
136: return super.appendChild(newChild);
137: }
138: }
|