001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 /* 019 * $Id: ElemText.java 468643 2006-10-28 06:56:03Z minchau $ 020 */ 021 package org.apache.xalan.templates; 022 023 import org.apache.xalan.res.XSLTErrorResources; 024 025 /** 026 * Implement xsl:template. 027 * This primarily acts as a marker on the element 028 * stack to signal that whitespace should be preserved. 029 * <pre> 030 * <!ELEMENT xsl:text (#PCDATA)> 031 * <!ATTLIST xsl:text 032 * disable-output-escaping (yes|no) "no" 033 * > 034 * </pre> 035 * @see <a href="http://www.w3.org/TR/xslt#section-Creating-Text">section-Creating-Text in XSLT Specification</a> 036 * @xsl.usage advanced 037 */ 038 public class ElemText extends ElemTemplateElement 039 { 040 static final long serialVersionUID = 1383140876182316711L; 041 042 /** 043 * Tells if this element should disable escaping. 044 * @serial 045 */ 046 private boolean m_disableOutputEscaping = false; 047 048 /** 049 * Set the "disable-output-escaping" attribute. 050 * Normally, the xml output method escapes & and < (and 051 * possibly other characters) when outputting text nodes. 052 * This ensures that the output is well-formed XML. However, 053 * it is sometimes convenient to be able to produce output 054 * that is almost, but not quite well-formed XML; for 055 * example, the output may include ill-formed sections 056 * which are intended to be transformed into well-formed 057 * XML by a subsequent non-XML aware process. For this reason, 058 * XSLT provides a mechanism for disabling output escaping. 059 * An xsl:value-of or xsl:text element may have a 060 * disable-output-escaping attribute; the allowed values 061 * are yes or no; the default is no; if the value is yes, 062 * then a text node generated by instantiating the xsl:value-of 063 * or xsl:text element should be output without any escaping. 064 * @see <a href="http://www.w3.org/TR/xslt#disable-output-escaping">disable-output-escaping in XSLT Specification</a> 065 * 066 * @param v Boolean flag indicating whether this element should disable escaping 067 */ 068 public void setDisableOutputEscaping(boolean v) 069 { 070 m_disableOutputEscaping = v; 071 } 072 073 /** 074 * Get the "disable-output-escaping" attribute. 075 * Normally, the xml output method escapes & and < (and 076 * possibly other characters) when outputting text nodes. 077 * This ensures that the output is well-formed XML. However, 078 * it is sometimes convenient to be able to produce output 079 * that is almost, but not quite well-formed XML; for 080 * example, the output may include ill-formed sections 081 * which are intended to be transformed into well-formed 082 * XML by a subsequent non-XML aware process. For this reason, 083 * XSLT provides a mechanism for disabling output escaping. 084 * An xsl:value-of or xsl:text element may have a 085 * disable-output-escaping attribute; the allowed values 086 * are yes or no; the default is no; if the value is yes, 087 * then a text node generated by instantiating the xsl:value-of 088 * or xsl:text element should be output without any escaping. 089 * @see <a href="http://www.w3.org/TR/xslt#disable-output-escaping">disable-output-escaping in XSLT Specification</a> 090 * 091 * @return Boolean flag indicating whether this element should disable escaping 092 */ 093 public boolean getDisableOutputEscaping() 094 { 095 return m_disableOutputEscaping; 096 } 097 098 /** 099 * 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 }