KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > templates > AVTPartXPath


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: AVTPartXPath.java,v 1.18 2004/02/16 20:32:32 minchau Exp $
18  */

19 package org.apache.xalan.templates;
20
21 import org.apache.xml.utils.FastStringBuffer;
22 import org.apache.xpath.XPath;
23 import org.apache.xpath.XPathContext;
24 import org.apache.xpath.XPathFactory;
25 import org.apache.xpath.compiler.XPathParser;
26 import org.apache.xpath.objects.XObject;
27
28 /**
29  * Simple string part of a complex AVT.
30  * @xsl.usage internal
31  */

32 public class AVTPartXPath extends AVTPart
33 {
34
35   /**
36    * The XPath object contained in this part.
37    * @serial
38    */

39   private XPath m_xpath;
40   
41   /**
42    * This function is used to fixup variables from QNames to stack frame
43    * indexes at stylesheet build time.
44    * @param vars List of QNames that correspond to variables. This list
45    * should be searched backwards for the first qualified name that
46    * corresponds to the variable reference qname. The position of the
47    * QName in the vector from the start of the vector will be its position
48    * in the stack frame (but variables above the globalsTop value will need
49    * to be offset to the current stack frame).
50    */

51   public void fixupVariables(java.util.Vector JavaDoc vars, int globalsSize)
52   {
53     m_xpath.fixupVariables(vars, globalsSize);
54   }
55   
56   /**
57    * Tell if this expression or it's subexpressions can traverse outside
58    * the current subtree.
59    *
60    * @return true if traversal outside the context node's subtree can occur.
61    */

62    public boolean canTraverseOutsideSubtree()
63    {
64     return m_xpath.getExpression().canTraverseOutsideSubtree();
65    }
66
67   /**
68    * Construct a simple AVT part.
69    *
70    * @param xpath Xpath section of AVT
71    */

72   public AVTPartXPath(XPath xpath)
73   {
74     m_xpath = xpath;
75   }
76
77   /**
78    * Construct a simple AVT part.
79    *
80    * @param val A pure string section of an AVT.
81    * @param nsNode An object which can be used to determine the
82    * Namespace Name (URI) for any Namespace prefix used in the XPath.
83    * Usually this is based on the context where the XPath was specified,
84    * such as a node within a Stylesheet.
85    * @param xpathProcessor XPath parser
86    * @param factory XPath factory
87    * @param liaison An XPathContext object, providing infomation specific
88    * to this invocation and this thread. Maintains SAX output state,
89    * variables, error handler and so on, so the transformation/XPath
90    * object itself can be simultaneously invoked from multiple threads.
91    *
92    * @throws javax.xml.transform.TransformerException
93    * TODO: Fix or remove this unused c'tor.
94    */

95   public AVTPartXPath(
96           String JavaDoc val, org.apache.xml.utils.PrefixResolver nsNode,
97           XPathParser xpathProcessor, XPathFactory factory,
98           XPathContext liaison)
99             throws javax.xml.transform.TransformerException JavaDoc
100   {
101     m_xpath = new XPath(val, null, nsNode, XPath.SELECT, liaison.getErrorListener());
102   }
103
104   /**
105    * Get the AVT part as the original string.
106    *
107    * @return the AVT part as the original string.
108    */

109   public String JavaDoc getSimpleString()
110   {
111     return "{" + m_xpath.getPatternString() + "}";
112   }
113
114   /**
115    * Write the value into the buffer.
116    *
117    * @param xctxt An XPathContext object, providing infomation specific
118    * to this invocation and this thread. Maintains SAX state, variables,
119    * error handler and so on, so the transformation/XPath object itself
120    * can be simultaneously invoked from multiple threads.
121    * @param buf Buffer to write into.
122    * @param context The current source tree context.
123    * @param nsNode The current namespace context (stylesheet tree context).
124    * @param NodeList The current Context Node List.
125    *
126    * @throws javax.xml.transform.TransformerException
127    */

128   public void evaluate(
129           XPathContext xctxt, FastStringBuffer buf, int context, org.apache.xml.utils.PrefixResolver nsNode)
130             throws javax.xml.transform.TransformerException JavaDoc
131   {
132
133     XObject xobj = m_xpath.execute(xctxt, context, nsNode);
134
135     if (null != xobj)
136     {
137       xobj.appendToFsb(buf);
138     }
139   }
140   
141   /**
142    * @see XSLTVisitable#callVisitors(XSLTVisitor)
143    */

144   public void callVisitors(XSLTVisitor visitor)
145   {
146     m_xpath.getExpression().callVisitors(m_xpath, visitor);
147   }
148 }
149
Popular Tags