• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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: ElemComment.java 468643 2006-10-28 06:56:03Z minchau $
20  */
21 package org.apache.xalan.templates;
22 
23 import javax.xml.transform.TransformerException;
24 
25 import org.apache.xalan.res.XSLTErrorResources;
26 import org.apache.xalan.transformer.TransformerImpl;
27 
28 /**
29  * Implement xsl:comment.
30  * <pre>
31  * <!ELEMENT xsl:comment %char-template;>
32  * <!ATTLIST xsl:comment %space-att;>
33  * </pre>
34  * @see <a href="http://www.w3.org/TR/xslt#section-Creating-Comments">section-Creating-Comments in XSLT Specification</a>
35  * @xsl.usage advanced
36  */
37 public class ElemComment extends ElemTemplateElement
38 {
39     static final long serialVersionUID = -8813199122875770142L;
40 
41   /**
42    * Get an int constant identifying the type of element.
43    * @see org.apache.xalan.templates.Constants
44    *
45    * @return The token ID for this element
46    */
getXSLToken()47   public int getXSLToken()
48   {
49     return Constants.ELEMNAME_COMMENT;
50   }
51 
52   /**
53    * Return the node name.
54    *
55    * @return This element's name
56    */
getNodeName()57   public String getNodeName()
58   {
59     return Constants.ELEMNAME_COMMENT_STRING;
60   }
61 
62   /**
63    * Execute the xsl:comment transformation
64    *
65    *
66    * @param transformer non-null reference to the the current transform-time state.
67    *
68    * @throws TransformerException
69    */
execute( TransformerImpl transformer)70   public void execute(
71           TransformerImpl transformer)
72             throws TransformerException
73   {
74     try
75     {
76       // Note the content model is:
77       // <!ENTITY % instructions "
78       // %char-instructions;
79       // | xsl:processing-instruction
80       // | xsl:comment
81       // | xsl:element
82       // | xsl:attribute
83       // ">
84       String data = transformer.transformToString(this);
85 
86       transformer.getResultTreeHandler().comment(data);
87     }
88     catch(org.xml.sax.SAXException se)
89     {
90       throw new TransformerException(se);
91     }
92   }
93 
94   /**
95    * Add a child to the child list.
96    *
97    * @param newChild Child to add to this node's child list
98    *
99    * @return Child that was just added to child list
100    *
101    * @throws DOMException
102    */
appendChild(ElemTemplateElement newChild)103   public ElemTemplateElement appendChild(ElemTemplateElement newChild)
104   {
105 
106     int type = ((ElemTemplateElement) newChild).getXSLToken();
107 
108     switch (type)
109     {
110 
111     // char-instructions
112     case Constants.ELEMNAME_TEXTLITERALRESULT :
113     case Constants.ELEMNAME_APPLY_TEMPLATES :
114     case Constants.ELEMNAME_APPLY_IMPORTS :
115     case Constants.ELEMNAME_CALLTEMPLATE :
116     case Constants.ELEMNAME_FOREACH :
117     case Constants.ELEMNAME_VALUEOF :
118     case Constants.ELEMNAME_COPY_OF :
119     case Constants.ELEMNAME_NUMBER :
120     case Constants.ELEMNAME_CHOOSE :
121     case Constants.ELEMNAME_IF :
122     case Constants.ELEMNAME_TEXT :
123     case Constants.ELEMNAME_COPY :
124     case Constants.ELEMNAME_VARIABLE :
125     case Constants.ELEMNAME_MESSAGE :
126 
127       // instructions
128       // case Constants.ELEMNAME_PI:
129       // case Constants.ELEMNAME_COMMENT:
130       // case Constants.ELEMNAME_ELEMENT:
131       // case Constants.ELEMNAME_ATTRIBUTE:
132       break;
133     default :
134       error(XSLTErrorResources.ER_CANNOT_ADD,
135             new Object[]{ newChild.getNodeName(),
136                           this.getNodeName() });  //"Can not add " +((ElemTemplateElement)newChild).m_elemName +
137 
138     //" to " + this.m_elemName);
139     }
140 
141     return super.appendChild(newChild);
142   }
143 }
144