1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 /* 19 * $Id: ElemText.java 468643 2006-10-28 06:56:03Z minchau $ 20 */ 21 package org.apache.xalan.templates; 22 23 import org.apache.xalan.res.XSLTErrorResources; 24 25 /** 26 * Implement xsl:template. 27 * This primarily acts as a marker on the element 28 * stack to signal that whitespace should be preserved. 29 * <pre> 30 * <!ELEMENT xsl:text (#PCDATA)> 31 * <!ATTLIST xsl:text 32 * disable-output-escaping (yes|no) "no" 33 * > 34 * </pre> 35 * @see <a href="http://www.w3.org/TR/xslt#section-Creating-Text">section-Creating-Text in XSLT Specification</a> 36 * @xsl.usage advanced 37 */ 38 public class ElemText extends ElemTemplateElement 39 { 40 static final long serialVersionUID = 1383140876182316711L; 41 42 /** 43 * Tells if this element should disable escaping. 44 * @serial 45 */ 46 private boolean m_disableOutputEscaping = false; 47 48 /** 49 * Set the "disable-output-escaping" attribute. 50 * Normally, the xml output method escapes & and < (and 51 * possibly other characters) when outputting text nodes. 52 * This ensures that the output is well-formed XML. However, 53 * it is sometimes convenient to be able to produce output 54 * that is almost, but not quite well-formed XML; for 55 * example, the output may include ill-formed sections 56 * which are intended to be transformed into well-formed 57 * XML by a subsequent non-XML aware process. For this reason, 58 * XSLT provides a mechanism for disabling output escaping. 59 * An xsl:value-of or xsl:text element may have a 60 * disable-output-escaping attribute; the allowed values 61 * are yes or no; the default is no; if the value is yes, 62 * then a text node generated by instantiating the xsl:value-of 63 * or xsl:text element should be output without any escaping. 64 * @see <a href="http://www.w3.org/TR/xslt#disable-output-escaping">disable-output-escaping in XSLT Specification</a> 65 * 66 * @param v Boolean flag indicating whether this element should disable escaping 67 */ 68 public void setDisableOutputEscaping(boolean v) 69 { 70 m_disableOutputEscaping = v; 71 } 72 73 /** 74 * Get the "disable-output-escaping" attribute. 75 * Normally, the xml output method escapes & and < (and 76 * possibly other characters) when outputting text nodes. 77 * This ensures that the output is well-formed XML. However, 78 * it is sometimes convenient to be able to produce output 79 * that is almost, but not quite well-formed XML; for 80 * example, the output may include ill-formed sections 81 * which are intended to be transformed into well-formed 82 * XML by a subsequent non-XML aware process. For this reason, 83 * XSLT provides a mechanism for disabling output escaping. 84 * An xsl:value-of or xsl:text element may have a 85 * disable-output-escaping attribute; the allowed values 86 * are yes or no; the default is no; if the value is yes, 87 * then a text node generated by instantiating the xsl:value-of 88 * or xsl:text element should be output without any escaping. 89 * @see <a href="http://www.w3.org/TR/xslt#disable-output-escaping">disable-output-escaping in XSLT Specification</a> 90 * 91 * @return Boolean flag indicating whether this element should disable escaping 92 */ 93 public boolean getDisableOutputEscaping() 94 { 95 return m_disableOutputEscaping; 96 } 97 98 /** 99 * Get an integer representation of the element type. 100 * 101 * @return An integer representation of the element, defined in the 102 * Constants class. 103 * @see org.apache.xalan.templates.Constants 104 */ 105 public int getXSLToken() 106 { 107 return Constants.ELEMNAME_TEXT; 108 } 109 110 /** 111 * Return the node name. 112 * 113 * @return The element's name 114 */ 115 public String getNodeName() 116 { 117 return Constants.ELEMNAME_TEXT_STRING; 118 } 119 120 /** 121 * Add a child to the child list. 122 * 123 * @param newChild Child to add to children list 124 * 125 * @return Child added to children list 126 * 127 * @throws DOMException 128 */ 129 public ElemTemplateElement appendChild(ElemTemplateElement newChild) 130 { 131 132 int type = ((ElemTemplateElement) newChild).getXSLToken(); 133 134 switch (type) 135 { 136 case Constants.ELEMNAME_TEXTLITERALRESULT : 137 break; 138 default : 139 error(XSLTErrorResources.ER_CANNOT_ADD, 140 new Object[]{ newChild.getNodeName(), 141 this.getNodeName() }); //"Can not add " +((ElemTemplateElement)newChild).m_elemName + 142 143 //" to " + this.m_elemName); 144 } 145 146 return super.appendChild(newChild); 147 } 148 } 149