• 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: KeyDeclaration.java 468643 2006-10-28 06:56:03Z minchau $
20  */
21 package org.apache.xalan.templates;
22 
23 import org.apache.xml.utils.QName;
24 import org.apache.xpath.XPath;
25 
26 /**
27  * Holds the attribute declarations for the xsl:keys element.
28  * A stylesheet declares a set of keys for each document using
29  * the xsl:key element. When this set of keys contains a member
30  * with node x, name y and value z, we say that node x has a key
31  * with name y and value z.
32  * @see <a href="http://www.w3.org/TR/xslt#key">key in XSLT Specification</a>
33  * @xsl.usage internal
34  */
35 public class KeyDeclaration extends ElemTemplateElement
36 {
37     static final long serialVersionUID = 7724030248631137918L;
38 
39   /**
40    * Constructs a new element representing the xsl:key.  The parameters
41    * are needed to prioritize this key element as part of the recomposing
42    * process.  For this element, they are not automatically created
43    * because the element is never added on to the stylesheet parent.
44    */
KeyDeclaration(Stylesheet parentNode, int docOrderNumber)45   public KeyDeclaration(Stylesheet parentNode, int docOrderNumber)
46   {
47     m_parentNode = parentNode;
48     setUid(docOrderNumber);
49   }
50 
51   /**
52    * The "name" property.
53    * @serial
54    */
55   private QName m_name;
56 
57   /**
58    * Set the "name" attribute.
59    * The name attribute specifies the name of the key. The value
60    * of the name attribute is a QName, which is expanded as
61    * described in [2.4 Qualified Names].
62    *
63    * @param name Value to set for the "name" attribute.
64    */
setName(QName name)65   public void setName(QName name)
66   {
67     m_name = name;
68   }
69 
70   /**
71    * Get the "name" attribute.
72    * The name attribute specifies the name of the key. The value
73    * of the name attribute is a QName, which is expanded as
74    * described in [2.4 Qualified Names].
75    *
76    * @return Value of the "name" attribute.
77    */
getName()78   public QName getName()
79   {
80     return m_name;
81   }
82 
83   /**
84    * Return the node name.
85    *
86    * @return the element's name
87    */
getNodeName()88   public String getNodeName()
89   {
90     return Constants.ELEMNAME_KEY_STRING;
91   }
92 
93 
94   /**
95    * The "match" attribute.
96    * @serial
97    */
98   private XPath m_matchPattern = null;
99 
100   /**
101    * Set the "match" attribute.
102    * The match attribute is a Pattern; an xsl:key element gives
103    * information about the keys of any node that matches the
104    * pattern specified in the match attribute.
105    * @see <a href="http://www.w3.org/TR/xslt#patterns">patterns in XSLT Specification</a>
106    *
107    * @param v Value to set for the "match" attribute.
108    */
setMatch(XPath v)109   public void setMatch(XPath v)
110   {
111     m_matchPattern = v;
112   }
113 
114   /**
115    * Get the "match" attribute.
116    * The match attribute is a Pattern; an xsl:key element gives
117    * information about the keys of any node that matches the
118    * pattern specified in the match attribute.
119    * @see <a href="http://www.w3.org/TR/xslt#patterns">patterns in XSLT Specification</a>
120    *
121    * @return Value of the "match" attribute.
122    */
getMatch()123   public XPath getMatch()
124   {
125     return m_matchPattern;
126   }
127 
128   /**
129    * The "use" attribute.
130    * @serial
131    */
132   private XPath m_use;
133 
134   /**
135    * Set the "use" attribute.
136    * The use attribute is an expression specifying the values
137    * of the key; the expression is evaluated once for each node
138    * that matches the pattern.
139    *
140    * @param v Value to set for the "use" attribute.
141    */
setUse(XPath v)142   public void setUse(XPath v)
143   {
144     m_use = v;
145   }
146 
147   /**
148    * Get 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    * @return Value of the "use" attribute.
154    */
getUse()155   public XPath getUse()
156   {
157     return m_use;
158   }
159 
160   /**
161    * Get an int constant identifying the type of element.
162    * @see org.apache.xalan.templates.Constants
163    *
164    * @return The token ID for this element
165    */
getXSLToken()166   public int getXSLToken()
167   {
168     return Constants.ELEMNAME_KEY;
169   }
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    */
compose(StylesheetRoot sroot)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   /**
189    * This function is called during recomposition to
190    * control how this element is composed.
191    * @param root The root stylesheet for this transformation.
192    */
recompose(StylesheetRoot root)193   public void recompose(StylesheetRoot root)
194   {
195     root.recomposeKeys(this);
196   }
197 
198 }
199