/** Copyright (c) 2002 Neeld Tanksley. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by Neeld Tanksley (http://xfactorstudio.com)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The name Neeld Tanksley must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact neeld@xfactorstudio.com. THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NEELD TANKSLEY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. **/ _global.XPathPredicate = function(){ } XPathPredicate.Logical = new Object(); XPathPredicate.Logical["and"] = 100; XPathPredicate.Logical["or"] = 101; XPathPredicate.SureOperator = new Object(); XPathPredicate.SureOperator["="] = 202; XPathPredicate.Operator = new Object(); XPathPredicate.Operator["+"] = 200; XPathPredicate.Operator["-"] = 201; XPathPredicate.Operator["="] = 202; XPathPredicate.Operator["!"] = 203; XPathPredicate.Operator[">"] = 204; XPathPredicate.Operator["<"] = 205; XPathPredicate.Operator["!="] = 206; XPathPredicate.Operator[">="] = 207; XPathPredicate.Operator["<="] = 208; XPathPredicate.Operator["*"] = 209; XPathPredicate.OperatorName = new Object(); XPathPredicate.OperatorName["mod"] = 209; XPathPredicate.OperatorName["div"] = 210; //TODO: WTF? Move the types to the types //object as I apperantly intended XPathPredicate.types = new Object(); XPathPredicate.operatorType = 0; XPathPredicate.funcType = 1; XPathPredicate.queryType = 2; XPathPredicate.numberType = 3; XPathPredicate.stringType = 4; XPathPredicate.booleanType = 5; XPathPredicate.logicalType = 6; XPathPredicate.groupingType = 7; /** evaluate parses the predicate expression and returns the evaluated value @param (XMLNode)context the context node @param (String)expr the XPath predicate expression that's the stuff in the [] @param (Array)nodeSet the nodeSet from the previous selection, contains the context node @param (Number)contextPosition the position of the context node in the nodeSet NOTE: position is not the same as array index, it is index+1 @return the evaluated value of the expression [Number | Boolean | NodeSet | String] **/ XPathPredicate.evaluate = function(context, expr, nodeSet, steps){ var contextSize = nodeSet.length; var result; var args; for(var i=0;i": if(expr.charAt(i+1) == "="){ steps.push({type:XPathPredicate.operatorType, value:c+"=" , data:undefined}); i++; }else{ steps.push({type:XPathPredicate.operatorType, value:c, data:undefined}); } break; case "*": if (steps.length) { steps.push({type:XPathPredicate.operatorType, value:c , data:undefined}); break; } default: //catch numbers if(!isNaN(c)){ //handle numbers j=i; while(!isNaN(expr.charAt(j)) && jscanning: " +expr.charAt(i)) //trace("arguments: " +args) i++; myc = expr.charAt(i); if (myc == "(") { bracketStack.push(true); } else if (myc == ")") { bracketStack.pop(); } args += myc; //trace("arguments: " +args) //trace(bracketStack) } args = args.substr(0,args.length-1); //trace("XPath function recognized as such! args are: >" +args +"<") steps.push({type:XPathPredicate.funcType , value:collChars , data:args}); }else if(XPathPredicate.Logical[collChars] != null){ steps.push({type:XPathPredicate.operatorType , value:collChars , data:args}); }else if(XPathPredicate.OperatorName[collChars] != null){ // mod & div steps.push({type:XPathPredicate.operatorType, value:collChars, data:undefined}); }else{ steps.push({type:XPathPredicate.queryType, value:collChars , data:undefined}); } } break; } } //leave for debugging /* trace("predicate steps parsed: ["); for(var i=0;i": steps.splice(i-1,3,XPathPredicate.isGreaterThan(steps[i-1],steps[i+1])); i=i-2; break; case "<": steps.splice(i-1,3,XPathPredicate.isLessThan(steps[i-1],steps[i+1])); i=i-2; break; case ">=": steps.splice(i-1,3,XPathPredicate.isGreaterThanOrEqualTo(steps[i-1],steps[i+1])); i=i-2; break; case "<=": steps.splice(i-1,3,XPathPredicate.isLessThanOrEqualTo(steps[i-1],steps[i+1])); i=i-2; break; } } } XPathPredicate.solveEqualityExpressions = function(steps){ for(var i=0;i