1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xalan" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, Lotus
  53. * Development Corporation., http://www.lotus.com. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package org.apache.xalan.templates;
  58. import org.w3c.dom.*;
  59. import org.xml.sax.*;
  60. import org.apache.xpath.*;
  61. import org.apache.xalan.res.XSLTErrorResources;
  62. import org.apache.xalan.transformer.TransformerImpl;
  63. /**
  64. * <meta name="usage" content="advanced"/>
  65. * Implement xsl:when.
  66. * <pre>
  67. * <!ELEMENT xsl:when %template;>
  68. * <!ATTLIST xsl:when
  69. * test %expr; #REQUIRED
  70. * %space-att;
  71. * >
  72. * </pre>
  73. * @see <a href="http://www.w3.org/TR/xslt#section-Conditional-Processing-with-xsl:choose">XXX in XSLT Specification</a>
  74. */
  75. public class ElemWhen extends ElemTemplateElement
  76. {
  77. /**
  78. * Each xsl:when element has a single attribute, test,
  79. * which specifies an expression.
  80. * @serial
  81. */
  82. private XPath m_test;
  83. /**
  84. * Set the "test" attribute.
  85. * Each xsl:when element has a single attribute, test,
  86. * which specifies an expression.
  87. *
  88. * @param v Value to set for the "test" attribute.
  89. */
  90. public void setTest(XPath v)
  91. {
  92. m_test = v;
  93. }
  94. /**
  95. * Get the "test" attribute.
  96. * Each xsl:when element has a single attribute, test,
  97. * which specifies an expression.
  98. *
  99. * @return Value of the "test" attribute.
  100. */
  101. public XPath getTest()
  102. {
  103. return m_test;
  104. }
  105. /**
  106. * Get an integer representation of the element type.
  107. *
  108. * @return An integer representation of the element, defined in the
  109. * Constants class.
  110. * @see org.apache.xalan.templates.Constants
  111. */
  112. public int getXSLToken()
  113. {
  114. return Constants.ELEMNAME_WHEN;
  115. }
  116. /**
  117. * This function is called after everything else has been
  118. * recomposed, and allows the template to set remaining
  119. * values that may be based on some other property that
  120. * depends on recomposition.
  121. */
  122. public void compose(StylesheetRoot sroot)
  123. throws javax.xml.transform.TransformerException
  124. {
  125. super.compose(sroot);
  126. java.util.Vector vnames = sroot.getComposeState().getVariableNames();
  127. if(null != m_test)
  128. m_test.fixupVariables(vnames, sroot.getComposeState().getGlobalsSize());
  129. }
  130. /**
  131. * Return the node name.
  132. *
  133. * @return The node name
  134. */
  135. public String getNodeName()
  136. {
  137. return Constants.ELEMNAME_WHEN_STRING;
  138. }
  139. /**
  140. * Constructor ElemWhen
  141. *
  142. */
  143. public ElemWhen(){}
  144. /**
  145. * Call the children visitors.
  146. * @param visitor The visitor whose appropriate method will be called.
  147. */
  148. protected void callChildVisitors(XSLTVisitor visitor, boolean callAttrs)
  149. {
  150. if(callAttrs)
  151. m_test.getExpression().callVisitors(m_test, visitor);
  152. super.callChildVisitors(visitor, callAttrs);
  153. }
  154. }