197f06937449c593a248dbbb1365e6ae408fb9decChris Lattner/* 297f06937449c593a248dbbb1365e6ae408fb9decChris Lattner * Licensed to the Apache Software Foundation (ASF) under one 37bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindola * or more contributor license agreements. See the NOTICE file 47bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindola * distributed with this work for additional information 54ee451de366474b9c228b4e5fa573795a715216dChris Lattner * regarding copyright ownership. The ASF licenses this file 67bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindola * to you under the Apache License, Version 2.0 (the "License"); 77bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindola * you may not use this file except in compliance with the License. 87bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindola * You may obtain a copy of the License at 97bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindola * 107bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindola * http://www.apache.org/licenses/LICENSE-2.0 117bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindola * 127bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindola * Unless required by applicable law or agreed to in writing, software 137bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindola * distributed under the License is distributed on an "AS IS" BASIS, 147bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindola * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1595b2c7da5e83670881270c1cd231a240be0556d9Chris Lattner * See the License for the specific language governing permissions and 167bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindola * limitations under the License. 1788ce667003a33e008d9ecc6811584681787e8150Anton Korobeynikov */ 18a8e2989ece6dc46df59b0768184028257f913843Evan Cheng/* 19a8e2989ece6dc46df59b0768184028257f913843Evan Cheng * $Id: AVTPartXPath.java 468643 2006-10-28 06:56:03Z minchau $ 20f447a5f1446d3f3ccd7f342a54f565ab02a087c8Chris Lattner */ 2197f06937449c593a248dbbb1365e6ae408fb9decChris Lattnerpackage org.apache.xalan.templates; 2297f06937449c593a248dbbb1365e6ae408fb9decChris Lattner 2397f06937449c593a248dbbb1365e6ae408fb9decChris Lattnerimport org.apache.xml.utils.FastStringBuffer; 243f282aa94b80f4a93ff3cbc37cf3cd4a851c8432Dale Johannesenimport org.apache.xpath.XPath; 257bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindolaimport org.apache.xpath.XPathContext; 267bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindolaimport org.apache.xpath.XPathFactory; 27e55b15fa4753ef08cbfa2127d2d220b77aa07d87Benjamin Kramerimport org.apache.xpath.compiler.XPathParser; 28cf20ac4fd12ea3510a8f32a24fff69eebe7b6f4aDan Gohmanimport org.apache.xpath.objects.XObject; 297bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindola 30b0f294c14b4e7098e5170ecfd528bcc9682ce0c7Chris Lattner/** 317bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindola * Simple string part of a complex AVT. 32a8e2989ece6dc46df59b0768184028257f913843Evan Cheng * @xsl.usage internal 33362dd0bef5437f85586c046bc53287b6fbe9c099Anton Korobeynikov */ 34b0f294c14b4e7098e5170ecfd528bcc9682ce0c7Chris Lattnerpublic class AVTPartXPath extends AVTPart 35b0f294c14b4e7098e5170ecfd528bcc9682ce0c7Chris Lattner{ 36becd83e3f4eb996f8e43189ce482267b3b8351a8Bill Wendling static final long serialVersionUID = -4460373807550527675L; 3797f06937449c593a248dbbb1365e6ae408fb9decChris Lattner 38f9bdeddb96043559c61f176f8077e3b91a0c544fChris Lattner /** 396c2f9e14fdf14d8c1c687c6bd9918183fa7f8a7fChris Lattner * The XPath object contained in this part. 40325d3dcfe4d5efc91db0f59b20a72a11dea024edChris Lattner * @serial 41d62f1b4168d4327c119642d28c26c836ae6717abChris Lattner */ 42b01c4bbb4573e0007444e218b683840e4519e0c8Rafael Espindola private XPath m_xpath; 437bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindola 445be54b00bdbe1abd02dde46ca2c4b0e5aaf7b537Evan Cheng /** 4551b198af83cb0080c2709b04c129a3d774c07765Daniel Dunbar * This function is used to fixup variables from QNames to stack frame 46c324ecb7bc93a1f09db29851438ec5ee72b143ebEvan Cheng * indexes at stylesheet build time. 47c40d9f9bae70c83947bf8fa5f9ee97adbf1bb0c0Jim Grosbach * @param vars List of QNames that correspond to variables. This list 4854c78ef2fed32e82e6aea8cbeb89156814eaf27cBob Wilson * should be searched backwards for the first qualified name that 4997f06937449c593a248dbbb1365e6ae408fb9decChris Lattner * corresponds to the variable reference qname. The position of the 5059135f49e1699daec9a43fc2d15715d55b910f54Devang Patel * QName in the vector from the start of the vector will be its position 513046470919e648ff7c011bda9c094163062c83dcTorok Edwin * in the stack frame (but variables above the globalsTop value will need 52b23569aff0a6d2b231cb93cc4acd0ac060ba560fChris Lattner * to be offset to the current stack frame). 537bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindola */ 547bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindola public void fixupVariables(java.util.Vector vars, int globalsSize) 557bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindola { 5697f06937449c593a248dbbb1365e6ae408fb9decChris Lattner m_xpath.fixupVariables(vars, globalsSize); 5797f06937449c593a248dbbb1365e6ae408fb9decChris Lattner } 5897f06937449c593a248dbbb1365e6ae408fb9decChris Lattner 5997f06937449c593a248dbbb1365e6ae408fb9decChris Lattner /** 60917290043f87b8efa6ba540bec5963013c517912Jim Grosbach * Tell if this expression or it's subexpressions can traverse outside 61917290043f87b8efa6ba540bec5963013c517912Jim Grosbach * the current subtree. 62917290043f87b8efa6ba540bec5963013c517912Jim Grosbach * 63917290043f87b8efa6ba540bec5963013c517912Jim Grosbach * @return true if traversal outside the context node's subtree can occur. 64917290043f87b8efa6ba540bec5963013c517912Jim Grosbach */ 65917290043f87b8efa6ba540bec5963013c517912Jim Grosbach public boolean canTraverseOutsideSubtree() 66917290043f87b8efa6ba540bec5963013c517912Jim Grosbach { 67917290043f87b8efa6ba540bec5963013c517912Jim Grosbach return m_xpath.getExpression().canTraverseOutsideSubtree(); 68917290043f87b8efa6ba540bec5963013c517912Jim Grosbach } 6995b2c7da5e83670881270c1cd231a240be0556d9Chris Lattner 704a071d667d995b00e7853243ff9c7c1269324478Chris Lattner /** 71a8e2989ece6dc46df59b0768184028257f913843Evan Cheng * Construct a simple AVT part. 72a8e2989ece6dc46df59b0768184028257f913843Evan Cheng * 73a8e2989ece6dc46df59b0768184028257f913843Evan Cheng * @param xpath Xpath section of AVT 74a8e2989ece6dc46df59b0768184028257f913843Evan Cheng */ 75a8e2989ece6dc46df59b0768184028257f913843Evan Cheng public AVTPartXPath(XPath xpath) 76a8e2989ece6dc46df59b0768184028257f913843Evan Cheng { 776d63a728586d56eb3e881905beb9db27f520f5d3Evan Cheng m_xpath = xpath; 78a8e2989ece6dc46df59b0768184028257f913843Evan Cheng } 79a8e2989ece6dc46df59b0768184028257f913843Evan Cheng 806d63a728586d56eb3e881905beb9db27f520f5d3Evan Cheng /** 816d63a728586d56eb3e881905beb9db27f520f5d3Evan Cheng * Construct a simple AVT part. 826d63a728586d56eb3e881905beb9db27f520f5d3Evan Cheng * 836d63a728586d56eb3e881905beb9db27f520f5d3Evan Cheng * @param val A pure string section of an AVT. 8457f0db833dc30404f1f5d28b23df326e520698ecBill Wendling * @param nsNode An object which can be used to determine the 85b23569aff0a6d2b231cb93cc4acd0ac060ba560fChris Lattner * Namespace Name (URI) for any Namespace prefix used in the XPath. 86b23569aff0a6d2b231cb93cc4acd0ac060ba560fChris Lattner * Usually this is based on the context where the XPath was specified, 8757f0db833dc30404f1f5d28b23df326e520698ecBill Wendling * such as a node within a Stylesheet. 8857f0db833dc30404f1f5d28b23df326e520698ecBill Wendling * @param xpathProcessor XPath parser 8957f0db833dc30404f1f5d28b23df326e520698ecBill Wendling * @param factory XPath factory 907bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindola * @param liaison An XPathContext object, providing infomation specific 917bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindola * to this invocation and this thread. Maintains SAX output state, 927bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindola * variables, error handler and so on, so the transformation/XPath 93b0739b78332275906cd5ace2ae0d65a29135667bJim Grosbach * object itself can be simultaneously invoked from multiple threads. 9497f06937449c593a248dbbb1365e6ae408fb9decChris Lattner * 95b0739b78332275906cd5ace2ae0d65a29135667bJim Grosbach * @throws javax.xml.transform.TransformerException 967bc59bc3952ad7842b1e079753deb32217a768a3Rafael Espindola * TODO: Fix or remove this unused c'tor. 9735c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner */ 98a8e2989ece6dc46df59b0768184028257f913843Evan Cheng public AVTPartXPath( 9935c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner String val, org.apache.xml.utils.PrefixResolver nsNode, 10035c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner XPathParser xpathProcessor, XPathFactory factory, 10135c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner XPathContext liaison) 10235c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner throws javax.xml.transform.TransformerException 10335c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner { 10435c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner m_xpath = new XPath(val, null, nsNode, XPath.SELECT, liaison.getErrorListener()); 10535c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner } 10635c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner 10735c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner /** 10835c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner * Get the AVT part as the original string. 10935c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner * 11035c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner * @return the AVT part as the original string. 11135c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner */ 11235c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner public String getSimpleString() 113a8e2989ece6dc46df59b0768184028257f913843Evan Cheng { 11435c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner return "{" + m_xpath.getPatternString() + "}"; 115a8e2989ece6dc46df59b0768184028257f913843Evan Cheng } 11635c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner 11735c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner /** 11835c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner * Write the value into the buffer. 11935c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner * 120055b0310f862b91f33699037ce67d3ab8137c20cEvan Cheng * @param xctxt An XPathContext object, providing infomation specific 12135c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner * to this invocation and this thread. Maintains SAX state, variables, 122a8e2989ece6dc46df59b0768184028257f913843Evan Cheng * error handler and so on, so the transformation/XPath object itself 123eaf1c98a7c38444d41d1c6dc2074736eec7d452fBob Wilson * can be simultaneously invoked from multiple threads. 124eaf1c98a7c38444d41d1c6dc2074736eec7d452fBob Wilson * @param buf Buffer to write into. 1251adc40cac314b0a77b790b094bca146a3a868452Johnny Chen * @param context The current source tree context. 1261adc40cac314b0a77b790b094bca146a3a868452Johnny Chen * @param nsNode The current namespace context (stylesheet tree context). 12722f5dc79c05d69391b17e14ed912aa8e98a63027Bob Wilson * 128eaf1c98a7c38444d41d1c6dc2074736eec7d452fBob Wilson * @throws javax.xml.transform.TransformerException 12935c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner */ 13035c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner public void evaluate( 13135c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner XPathContext xctxt, FastStringBuffer buf, int context, org.apache.xml.utils.PrefixResolver nsNode) 13235c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner throws javax.xml.transform.TransformerException 13335c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner { 13435c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner 135055b0310f862b91f33699037ce67d3ab8137c20cEvan Cheng XObject xobj = m_xpath.execute(xctxt, context, nsNode); 13635c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner 137a8e2989ece6dc46df59b0768184028257f913843Evan Cheng if (null != xobj) 13835c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner { 13935c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner xobj.appendToFsb(buf); 14035c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner } 14135c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner } 14235c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner 14335c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner /** 14435c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner * @see XSLTVisitable#callVisitors(XSLTVisitor) 14535c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner */ 14635c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner public void callVisitors(XSLTVisitor visitor) 14735c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner { 14835c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner m_xpath.getExpression().callVisitors(m_xpath, visitor); 14935c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner } 15035c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner} 15135c33bd772b3cfb34fdc6b5c9171f955454d0043Chris Lattner