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: AbsPathChecker.java 468643 2006-10-28 06:56:03Z minchau $ 20 */ 21package org.apache.xalan.templates; 22 23import org.apache.xpath.ExpressionOwner; 24import org.apache.xpath.XPathVisitor; 25import org.apache.xpath.axes.LocPathIterator; 26import org.apache.xpath.functions.FuncCurrent; 27import org.apache.xpath.functions.FuncExtFunction; 28import org.apache.xpath.functions.Function; 29import org.apache.xpath.operations.Variable; 30 31/** 32 * This class runs over a path expression that is assumed to be absolute, and 33 * checks for variables and the like that may make it context dependent. 34 */ 35public class AbsPathChecker extends XPathVisitor 36{ 37 private boolean m_isAbs = true; 38 39 /** 40 * Process the LocPathIterator to see if it contains variables 41 * or functions that may make it context dependent. 42 * @param path LocPathIterator that is assumed to be absolute, but needs checking. 43 * @return true if the path is confirmed to be absolute, false if it 44 * may contain context dependencies. 45 */ 46 public boolean checkAbsolute(LocPathIterator path) 47 { 48 m_isAbs = true; 49 path.callVisitors(null, this); 50 return m_isAbs; 51 } 52 53 /** 54 * Visit a function. 55 * @param owner The owner of the expression, to which the expression can 56 * be reset if rewriting takes place. 57 * @param func The function reference object. 58 * @return true if the sub expressions should be traversed. 59 */ 60 public boolean visitFunction(ExpressionOwner owner, Function func) 61 { 62 if((func instanceof FuncCurrent) || 63 (func instanceof FuncExtFunction)) 64 m_isAbs = false; 65 return true; 66 } 67 68 /** 69 * Visit a variable reference. 70 * @param owner The owner of the expression, to which the expression can 71 * be reset if rewriting takes place. 72 * @param var The variable reference object. 73 * @return true if the sub expressions should be traversed. 74 */ 75 public boolean visitVariableRef(ExpressionOwner owner, Variable var) 76 { 77 m_isAbs = false; 78 return true; 79 } 80} 81 82