From e44a7e37b6c7b5961adaffc62b9042b8d442938e Mon Sep 17 00:00:00 2001 From: mensonge Date: Thu, 13 Nov 2008 09:49:11 +0000 Subject: New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f --- includes/js/dojox/jsonPath/query.js | 163 ++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 includes/js/dojox/jsonPath/query.js (limited to 'includes/js/dojox/jsonPath/query.js') diff --git a/includes/js/dojox/jsonPath/query.js b/includes/js/dojox/jsonPath/query.js new file mode 100644 index 0000000..4e24309 --- /dev/null +++ b/includes/js/dojox/jsonPath/query.js @@ -0,0 +1,163 @@ +if(!dojo._hasResource["dojox.jsonPath.query"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.jsonPath.query"] = true; +dojo.provide("dojox.jsonPath.query"); + +dojox.jsonPath.query = function(/*Object*/obj, /*String*/expr, /*Object*/arg){ + // summaRy + // Perform jsonPath query `expr` on javascript object or json string `obj` + // obj - object || json string to perform query on + // expr - jsonPath expression (string) to be evaluated + // arg - {}special arugments. + // resultType: "VALUE"||"BOTH"||"PATH"} (defaults to value) + // evalType: "RESULT"||"ITEM"} (defaults to ?) + + var re = dojox.jsonPath._regularExpressions; + if (!arg){arg={};} + + var strs = []; + function _str(i){ return strs[i];} + var acc; + if (arg.resultType == "PATH" && arg.evalType == "RESULT") throw Error("RESULT based evaluation not supported with PATH based results"); + var P = { + resultType: arg.resultType || "VALUE", + normalize: function(expr){ + var subx = []; + expr = expr.replace(/'([^']|'')*'/g, function(t){return "_str("+(strs.push(eval(t))-1)+")";}); + var ll = -1; + while(ll!=subx.length){ + ll=subx.length;//TODO: Do expression syntax checking + expr = expr.replace(/(\??\([^\(\)]*\))/g, function($0){return "#"+(subx.push($0)-1);}); + } + expr = expr.replace(/[\['](#[0-9]+)[\]']/g,'[$1]') + .replace(/'?\.'?|\['?/g, ";") + .replace(/;;;|;;/g, ";..;") + .replace(/;$|'?\]|'$/g, ""); + ll = -1; + while(ll!=expr){ + ll=expr; + expr = expr.replace(/#([0-9]+)/g, function($0,$1){return subx[$1];}); + } + return expr.split(";"); + }, + asPaths: function(paths){ + for (var j=0;j