• 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: ElemWhen.java 468643 2006-10-28 06:56:03Z minchau $
20  */
21 package org.apache.xalan.templates;
22 
23 import org.apache.xpath.XPath;
24 
25 /**
26  * Implement xsl:when.
27  * <pre>
28  * <!ELEMENT xsl:when %template;>
29  * <!ATTLIST xsl:when
30  *   test %expr; #REQUIRED
31  *   %space-att;
32  * >
33  * </pre>
34  * @see <a href="http://www.w3.org/TR/xslt#section-Conditional-Processing-with-xsl:choose">XXX in XSLT Specification</a>
35  * @xsl.usage advanced
36  */
37 public class ElemWhen extends ElemTemplateElement
38 {
39     static final long serialVersionUID = 5984065730262071360L;
40 
41   /**
42    * Each xsl:when element has a single attribute, test,
43    * which specifies an expression.
44    * @serial
45    */
46   private XPath m_test;
47 
48   /**
49    * Set the "test" attribute.
50    * Each xsl:when element has a single attribute, test,
51    * which specifies an expression.
52    *
53    * @param v Value to set for the "test" attribute.
54    */
setTest(XPath v)55   public void setTest(XPath v)
56   {
57     m_test = v;
58   }
59 
60   /**
61    * Get the "test" attribute.
62    * Each xsl:when element has a single attribute, test,
63    * which specifies an expression.
64    *
65    * @return Value of the "test" attribute.
66    */
getTest()67   public XPath getTest()
68   {
69     return m_test;
70   }
71 
72   /**
73    * Get an integer representation of the element type.
74    *
75    * @return An integer representation of the element, defined in the
76    *     Constants class.
77    * @see org.apache.xalan.templates.Constants
78    */
getXSLToken()79   public int getXSLToken()
80   {
81     return Constants.ELEMNAME_WHEN;
82   }
83 
84   /**
85    * This function is called after everything else has been
86    * recomposed, and allows the template to set remaining
87    * values that may be based on some other property that
88    * depends on recomposition.
89    */
compose(StylesheetRoot sroot)90   public void compose(StylesheetRoot sroot)
91     throws javax.xml.transform.TransformerException
92   {
93     super.compose(sroot);
94     java.util.Vector vnames = sroot.getComposeState().getVariableNames();
95     if(null != m_test)
96       m_test.fixupVariables(vnames, sroot.getComposeState().getGlobalsSize());
97   }
98 
99   /**
100    * Return the node name.
101    *
102    * @return The node name
103    */
getNodeName()104   public String getNodeName()
105   {
106     return Constants.ELEMNAME_WHEN_STRING;
107   }
108 
109   /**
110    * Constructor ElemWhen
111    *
112    */
ElemWhen()113   public ElemWhen(){}
114 
115   /**
116    * Call the children visitors.
117    * @param visitor The visitor whose appropriate method will be called.
118    */
callChildVisitors(XSLTVisitor visitor, boolean callAttrs)119   protected void callChildVisitors(XSLTVisitor visitor, boolean callAttrs)
120   {
121   	if(callAttrs)
122   		m_test.getExpression().callVisitors(m_test, visitor);
123     super.callChildVisitors(visitor, callAttrs);
124   }
125 
126 }
127