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: AVTPartXPath.java 468643 2006-10-28 06:56:03Z minchau $ 20 */ 21 package org.apache.xalan.templates; 22 23 import org.apache.xml.utils.FastStringBuffer; 24 import org.apache.xpath.XPath; 25 import org.apache.xpath.XPathContext; 26 import org.apache.xpath.XPathFactory; 27 import org.apache.xpath.compiler.XPathParser; 28 import org.apache.xpath.objects.XObject; 29 30 /** 31 * Simple string part of a complex AVT. 32 * @xsl.usage internal 33 */ 34 public class AVTPartXPath extends AVTPart 35 { 36 static final long serialVersionUID = -4460373807550527675L; 37 38 /** 39 * The XPath object contained in this part. 40 * @serial 41 */ 42 private XPath m_xpath; 43 44 /** 45 * This function is used to fixup variables from QNames to stack frame 46 * indexes at stylesheet build time. 47 * @param vars List of QNames that correspond to variables. This list 48 * should be searched backwards for the first qualified name that 49 * corresponds to the variable reference qname. The position of the 50 * QName in the vector from the start of the vector will be its position 51 * in the stack frame (but variables above the globalsTop value will need 52 * to be offset to the current stack frame). 53 */ fixupVariables(java.util.Vector vars, int globalsSize)54 public void fixupVariables(java.util.Vector vars, int globalsSize) 55 { 56 m_xpath.fixupVariables(vars, globalsSize); 57 } 58 59 /** 60 * Tell if this expression or it's subexpressions can traverse outside 61 * the current subtree. 62 * 63 * @return true if traversal outside the context node's subtree can occur. 64 */ canTraverseOutsideSubtree()65 public boolean canTraverseOutsideSubtree() 66 { 67 return m_xpath.getExpression().canTraverseOutsideSubtree(); 68 } 69 70 /** 71 * Construct a simple AVT part. 72 * 73 * @param xpath Xpath section of AVT 74 */ AVTPartXPath(XPath xpath)75 public AVTPartXPath(XPath xpath) 76 { 77 m_xpath = xpath; 78 } 79 80 /** 81 * Construct a simple AVT part. 82 * 83 * @param val A pure string section of an AVT. 84 * @param nsNode An object which can be used to determine the 85 * Namespace Name (URI) for any Namespace prefix used in the XPath. 86 * Usually this is based on the context where the XPath was specified, 87 * such as a node within a Stylesheet. 88 * @param xpathProcessor XPath parser 89 * @param factory XPath factory 90 * @param liaison An XPathContext object, providing infomation specific 91 * to this invocation and this thread. Maintains SAX output state, 92 * variables, error handler and so on, so the transformation/XPath 93 * object itself can be simultaneously invoked from multiple threads. 94 * 95 * @throws javax.xml.transform.TransformerException 96 * TODO: Fix or remove this unused c'tor. 97 */ AVTPartXPath( String val, org.apache.xml.utils.PrefixResolver nsNode, XPathParser xpathProcessor, XPathFactory factory, XPathContext liaison)98 public AVTPartXPath( 99 String val, org.apache.xml.utils.PrefixResolver nsNode, 100 XPathParser xpathProcessor, XPathFactory factory, 101 XPathContext liaison) 102 throws javax.xml.transform.TransformerException 103 { 104 m_xpath = new XPath(val, null, nsNode, XPath.SELECT, liaison.getErrorListener()); 105 } 106 107 /** 108 * Get the AVT part as the original string. 109 * 110 * @return the AVT part as the original string. 111 */ getSimpleString()112 public String getSimpleString() 113 { 114 return "{" + m_xpath.getPatternString() + "}"; 115 } 116 117 /** 118 * Write the value into the buffer. 119 * 120 * @param xctxt An XPathContext object, providing infomation specific 121 * to this invocation and this thread. Maintains SAX state, variables, 122 * error handler and so on, so the transformation/XPath object itself 123 * can be simultaneously invoked from multiple threads. 124 * @param buf Buffer to write into. 125 * @param context The current source tree context. 126 * @param nsNode The current namespace context (stylesheet tree context). 127 * 128 * @throws javax.xml.transform.TransformerException 129 */ evaluate( XPathContext xctxt, FastStringBuffer buf, int context, org.apache.xml.utils.PrefixResolver nsNode)130 public void evaluate( 131 XPathContext xctxt, FastStringBuffer buf, int context, org.apache.xml.utils.PrefixResolver nsNode) 132 throws javax.xml.transform.TransformerException 133 { 134 135 XObject xobj = m_xpath.execute(xctxt, context, nsNode); 136 137 if (null != xobj) 138 { 139 xobj.appendToFsb(buf); 140 } 141 } 142 143 /** 144 * @see XSLTVisitable#callVisitors(XSLTVisitor) 145 */ callVisitors(XSLTVisitor visitor)146 public void callVisitors(XSLTVisitor visitor) 147 { 148 m_xpath.getExpression().callVisitors(m_xpath, visitor); 149 } 150 } 151