KickJava   Java API By Example, From Geeks To Geeks.

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


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

19 package org.apache.xalan.templates;
20
21 import javax.xml.transform.TransformerException JavaDoc;
22
23 import org.apache.xalan.res.XSLTErrorResources;
24 import org.apache.xalan.transformer.TransformerImpl;
25
26 /**
27  * Implement xsl:comment.
28  * <pre>
29  * <!ELEMENT xsl:comment %char-template;>
30  * <!ATTLIST xsl:comment %space-att;>
31  * </pre>
32  * @see <a HREF="http://www.w3.org/TR/xslt#section-Creating-Comments">section-Creating-Comments in XSLT Specification</a>
33  * @xsl.usage advanced
34  */

35 public class ElemComment extends ElemTemplateElement
36 {
37
38   /**
39    * Get an int constant identifying the type of element.
40    * @see org.apache.xalan.templates.Constants
41    *
42    * @return The token ID for this element
43    */

44   public int getXSLToken()
45   {
46     return Constants.ELEMNAME_COMMENT;
47   }
48
49   /**
50    * Return the node name.
51    *
52    * @return This element's name
53    */

54   public String JavaDoc getNodeName()
55   {
56     return Constants.ELEMNAME_COMMENT_STRING;
57   }
58
59   /**
60    * Execute the xsl:comment transformation
61    *
62    *
63    * @param transformer non-null reference to the the current transform-time state.
64    * @param sourceNode non-null reference to the <a HREF="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
65    * @param mode reference, which may be null, to the <a HREF="http://www.w3.org/TR/xslt#modes">current mode</a>.
66    *
67    * @throws TransformerException
68    */

69   public void execute(
70           TransformerImpl transformer)
71             throws TransformerException JavaDoc
72   {
73     if (TransformerImpl.S_DEBUG)
74       transformer.getTraceManager().fireTraceEvent(this);
75     try
76     {
77       // Note the content model is:
78
// <!ENTITY % instructions "
79
// %char-instructions;
80
// | xsl:processing-instruction
81
// | xsl:comment
82
// | xsl:element
83
// | xsl:attribute
84
// ">
85
String JavaDoc data = transformer.transformToString(this);
86
87       transformer.getResultTreeHandler().comment(data);
88     }
89     catch(org.xml.sax.SAXException JavaDoc se)
90     {
91       throw new TransformerException JavaDoc(se);
92     }
93     finally
94     {
95       if (TransformerImpl.S_DEBUG)
96         transformer.getTraceManager().fireTraceEndEvent(this);
97     }
98   }
99
100   /**
101    * Add a child to the child list.
102    *
103    * @param newChild Child to add to this node's child list
104    *
105    * @return Child that was just added to child list
106    *
107    * @throws DOMException
108    */

109   public ElemTemplateElement appendChild(ElemTemplateElement newChild)
110   {
111
112     int type = ((ElemTemplateElement) newChild).getXSLToken();
113
114     switch (type)
115     {
116
117     // char-instructions
118
case Constants.ELEMNAME_TEXTLITERALRESULT :
119     case Constants.ELEMNAME_APPLY_TEMPLATES :
120     case Constants.ELEMNAME_APPLY_IMPORTS :
121     case Constants.ELEMNAME_CALLTEMPLATE :
122     case Constants.ELEMNAME_FOREACH :
123     case Constants.ELEMNAME_VALUEOF :
124     case Constants.ELEMNAME_COPY_OF :
125     case Constants.ELEMNAME_NUMBER :
126     case Constants.ELEMNAME_CHOOSE :
127     case Constants.ELEMNAME_IF :
128     case Constants.ELEMNAME_TEXT :
129     case Constants.ELEMNAME_COPY :
130     case Constants.ELEMNAME_VARIABLE :
131     case Constants.ELEMNAME_MESSAGE :
132
133       // instructions
134
// case Constants.ELEMNAME_PI:
135
// case Constants.ELEMNAME_COMMENT:
136
// case Constants.ELEMNAME_ELEMENT:
137
// case Constants.ELEMNAME_ATTRIBUTE:
138
break;
139     default :
140       error(XSLTErrorResources.ER_CANNOT_ADD,
141             new Object JavaDoc[]{ newChild.getNodeName(),
142                           this.getNodeName() }); //"Can not add " +((ElemTemplateElement)newChild).m_elemName +
143

144     //" to " + this.m_elemName);
145
}
146
147     return super.appendChild(newChild);
148   }
149 }
150
Popular Tags