19f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/*
29f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Licensed to the Apache Software Foundation (ASF) under one
39f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or more contributor license agreements. See the NOTICE file
49f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed with this work for additional information
59f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * regarding copyright ownership. The ASF licenses this file
69f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to you under the Apache License, Version 2.0 (the  "License");
79f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * you may not use this file except in compliance with the License.
89f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * You may obtain a copy of the License at
99f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *     http://www.apache.org/licenses/LICENSE-2.0
119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Unless required by applicable law or agreed to in writing, software
139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS,
149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * See the License for the specific language governing permissions and
169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * limitations under the License.
179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/*
199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * $Id: ElemText.java 468643 2006-10-28 06:56:03Z minchau $
209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpackage org.apache.xalan.templates;
229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.res.XSLTErrorResources;
249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/**
269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Implement xsl:template.
279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This primarily acts as a marker on the element
289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * stack to signal that whitespace should be preserved.
299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <pre>
309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <!ELEMENT xsl:text (#PCDATA)>
319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <!ATTLIST xsl:text
329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *   disable-output-escaping (yes|no) "no"
339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * >
349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * </pre>
359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see <a href="http://www.w3.org/TR/xslt#section-Creating-Text">section-Creating-Text in XSLT Specification</a>
369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage advanced
379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpublic class ElemText extends ElemTemplateElement
399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson{
409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    static final long serialVersionUID = 1383140876182316711L;
419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Tells if this element should disable escaping.
449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @serial
459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  private boolean m_disableOutputEscaping = false;
479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Set the "disable-output-escaping" attribute.
509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Normally, the xml output method escapes & and < (and
519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * possibly other characters) when outputting text nodes.
529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * This ensures that the output is well-formed XML. However,
539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * it is sometimes convenient to be able to produce output
549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * that is almost, but not quite well-formed XML; for
559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * example, the output may include ill-formed sections
569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * which are intended to be transformed into well-formed
579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * XML by a subsequent non-XML aware process. For this reason,
589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * XSLT provides a mechanism for disabling output escaping.
599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * An xsl:value-of or xsl:text element may have a
609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * disable-output-escaping attribute; the allowed values
619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * are yes or no; the default is no; if the value is yes,
629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * then a text node generated by instantiating the xsl:value-of
639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * or xsl:text element should be output without any escaping.
649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see <a href="http://www.w3.org/TR/xslt#disable-output-escaping">disable-output-escaping in XSLT Specification</a>
659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param v Boolean flag indicating whether this element should disable escaping
679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void setDisableOutputEscaping(boolean v)
699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_disableOutputEscaping = v;
719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Get the "disable-output-escaping" attribute.
759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Normally, the xml output method escapes & and < (and
769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * possibly other characters) when outputting text nodes.
779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * This ensures that the output is well-formed XML. However,
789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * it is sometimes convenient to be able to produce output
799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * that is almost, but not quite well-formed XML; for
809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * example, the output may include ill-formed sections
819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * which are intended to be transformed into well-formed
829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * XML by a subsequent non-XML aware process. For this reason,
839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * XSLT provides a mechanism for disabling output escaping.
849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * An xsl:value-of or xsl:text element may have a
859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * disable-output-escaping attribute; the allowed values
869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * are yes or no; the default is no; if the value is yes,
879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * then a text node generated by instantiating the xsl:value-of
889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * or xsl:text element should be output without any escaping.
899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see <a href="http://www.w3.org/TR/xslt#disable-output-escaping">disable-output-escaping in XSLT Specification</a>
909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return Boolean flag indicating whether this element should disable escaping
929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public boolean getDisableOutputEscaping()
949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return m_disableOutputEscaping;
969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Get an integer representation of the element type.
1009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return An integer representation of the element, defined in the
1029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *     Constants class.
1039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see org.apache.xalan.templates.Constants
1049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public int getXSLToken()
1069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return Constants.ELEMNAME_TEXT;
1089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Return the node name.
1129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return The element's name
1149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public String getNodeName()
1169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return Constants.ELEMNAME_TEXT_STRING;
1189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Add a child to the child list.
1229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param newChild Child to add to children list
1249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return Child added to children list
1269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @throws DOMException
1289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public ElemTemplateElement appendChild(ElemTemplateElement newChild)
1309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    int type = ((ElemTemplateElement) newChild).getXSLToken();
1339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    switch (type)
1359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
1369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    case Constants.ELEMNAME_TEXTLITERALRESULT :
1379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      break;
1389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    default :
1399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      error(XSLTErrorResources.ER_CANNOT_ADD,
1409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            new Object[]{ newChild.getNodeName(),
1419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                          this.getNodeName() });  //"Can not add " +((ElemTemplateElement)newChild).m_elemName +
1429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    //" to " + this.m_elemName);
1449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
1459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return super.appendChild(newChild);
1479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson}
149