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.apache.xpath.XPath;
  59. import org.apache.xml.utils.QName;
  60. /**
  61. * <meta name="usage" content="internal"/>
  62. * Holds the attribute declarations for the xsl:keys element.
  63. * A stylesheet declares a set of keys for each document using
  64. * the xsl:key element. When this set of keys contains a member
  65. * with node x, name y and value z, we say that node x has a key
  66. * with name y and value z.
  67. * @see <a href="http://www.w3.org/TR/xslt#key">key in XSLT Specification</a>
  68. */
  69. public class KeyDeclaration extends ElemTemplateElement
  70. {
  71. /**
  72. * Constructs a new element representing the xsl:key. The parameters
  73. * are needed to prioritize this key element as part of the recomposing
  74. * process. For this element, they are not automatically created
  75. * because the element is never added on to the stylesheet parent.
  76. */
  77. public KeyDeclaration(Stylesheet parentNode, int docOrderNumber)
  78. {
  79. m_parentNode = parentNode;
  80. setUid(docOrderNumber);
  81. }
  82. /**
  83. * The "name" property.
  84. * @serial
  85. */
  86. private QName m_name;
  87. /**
  88. * Set the "name" attribute.
  89. * The name attribute specifies the name of the key. The value
  90. * of the name attribute is a QName, which is expanded as
  91. * described in [2.4 Qualified Names].
  92. *
  93. * @param name Value to set for the "name" attribute.
  94. */
  95. public void setName(QName name)
  96. {
  97. m_name = name;
  98. }
  99. /**
  100. * Get the "name" attribute.
  101. * The name attribute specifies the name of the key. The value
  102. * of the name attribute is a QName, which is expanded as
  103. * described in [2.4 Qualified Names].
  104. *
  105. * @return Value of the "name" attribute.
  106. */
  107. public QName getName()
  108. {
  109. return m_name;
  110. }
  111. /**
  112. * The "match" attribute.
  113. * @serial
  114. */
  115. private XPath m_matchPattern = null;
  116. /**
  117. * Set the "match" attribute.
  118. * The match attribute is a Pattern; an xsl:key element gives
  119. * information about the keys of any node that matches the
  120. * pattern specified in the match attribute.
  121. * @see <a href="http://www.w3.org/TR/xslt#patterns">patterns in XSLT Specification</a>
  122. *
  123. * @param v Value to set for the "match" attribute.
  124. */
  125. public void setMatch(XPath v)
  126. {
  127. m_matchPattern = v;
  128. }
  129. /**
  130. * Get the "match" attribute.
  131. * The match attribute is a Pattern; an xsl:key element gives
  132. * information about the keys of any node that matches the
  133. * pattern specified in the match attribute.
  134. * @see <a href="http://www.w3.org/TR/xslt#patterns">patterns in XSLT Specification</a>
  135. *
  136. * @return Value of the "match" attribute.
  137. */
  138. public XPath getMatch()
  139. {
  140. return m_matchPattern;
  141. }
  142. /**
  143. * The "use" attribute.
  144. * @serial
  145. */
  146. private XPath m_use;
  147. /**
  148. * Set the "use" attribute.
  149. * The use attribute is an expression specifying the values
  150. * of the key; the expression is evaluated once for each node
  151. * that matches the pattern.
  152. *
  153. * @param v Value to set for the "use" attribute.
  154. */
  155. public void setUse(XPath v)
  156. {
  157. m_use = v;
  158. }
  159. /**
  160. * Get the "use" attribute.
  161. * The use attribute is an expression specifying the values
  162. * of the key; the expression is evaluated once for each node
  163. * that matches the pattern.
  164. *
  165. * @return Value of the "use" attribute.
  166. */
  167. public XPath getUse()
  168. {
  169. return m_use;
  170. }
  171. /**
  172. * This function is called after everything else has been
  173. * recomposed, and allows the template to set remaining
  174. * values that may be based on some other property that
  175. * depends on recomposition.
  176. */
  177. public void compose(StylesheetRoot sroot)
  178. throws javax.xml.transform.TransformerException
  179. {
  180. super.compose(sroot);
  181. java.util.Vector vnames = sroot.getComposeState().getVariableNames();
  182. if(null != m_matchPattern)
  183. m_matchPattern.fixupVariables(vnames, sroot.getComposeState().getGlobalsSize());
  184. if(null != m_use)
  185. m_use.fixupVariables(vnames, sroot.getComposeState().getGlobalsSize());
  186. }
  187. /**
  188. * This function is called during recomposition to
  189. * control how this element is composed.
  190. * @param root The root stylesheet for this transformation.
  191. */
  192. public void recompose(StylesheetRoot root)
  193. {
  194. root.recomposeKeys(this);
  195. }
  196. }