dataschema-json-min.js revision 0d6d1a2d994933a68a100ec3dcdc7c7a0eeeae6c
YUI.add("dataschema-json",function(C){var A=C.Lang,B={toString:function(){return"DataSchema.JSON";},buildPath:function(D){var G=null,F=[],E=0;if(D){D=D.replace(/\[(['"])(.*?)\1\]/g,function(I,H,J){F[E]=J;return".@"+(E++);}).replace(/\[(\d+)\]/g,function(I,H){F[E]=parseInt(H,10)|0;return".@"+(E++);}).replace(/^\./,"");if(!/[^\w\.\$@]/.test(D)){G=D.split(".");for(E=G.length-1;E>=0;--E){if(G[E].charAt(0)==="@"){G[E]=F[parseInt(G[E].substr(1),10)];}}}else{}}return G;},getLocationValue:function(G,F){var E=0,D=G.length;for(;E<D;E++){F=F[G[E]];}return F;},apply:function(F,G){var D=G,E={results:[],meta:{}};if(!A.isObject(G)){try{D=C.JSON.parse(G);}catch(H){E.error=H;return E;}}if(A.isObject(D)&&F){if(!A.isUndefined(F.resultsLocator)){E=B._parseResults(F,D,E);}if(!A.isUndefined(F.metaFields)){E=B._parseMeta(F.metaFields,D,E);}}else{E.error=true;}return E;},_parseResults:function(H,E,G){var F=[],I,D;if(H.resultsLocator){I=B.buildPath(H.resultsLocator);if(I){F=B.getLocationValue(I,E);if(F===undefined){G.results=[];D=new Error(this.toString()+" Results retrieval failure");}if(A.isArray(H.resultsFields)&&A.isArray(F)){G=B._getFieldValues(H.resultsFields,F,G);}else{G.results=[];D=new Error(this.toString()+" Fields retrieval failure");}}else{D=new Error(this.toString()+" Results locator failure");}if(D){G.error=D;}}return G;},_getFieldValues:function(K,Q,E){var G=[],M=K.length,H,F,O,P,S,D,J=[],N=[],L=[],R,I;for(H=0;H<M;H++){O=K[H];P=O.key||O;S=B.buildPath(P);if(S){if(S.length===1){J[J.length]={key:P,path:S[0]};}else{N[N.length]={key:P,path:S};}}else{}D=(A.isFunction(O.parser))?O.parser:C.DataSchema[O.parser+""];if(D){L[L.length]={key:P,parser:D};}}for(H=Q.length-1;H>=0;--H){I={};R=Q[H];if(R){for(F=J.length-1;F>=0;--F){I[J[F].key]=A.isUndefined(R[J[F].path])?R[F]:R[J[F].path];}for(F=N.length-1;F>=0;--F){I[N[F].key]=B.getLocationValue(N[F].path,R);}for(F=L.length-1;F>=0;--F){P=L[F].key;I[P]=L[F].parser(I[P]);if(A.isUndefined(I[P])){I[P]=null;}}}G[H]=I;}E.results=G;return E;},_parseMeta:function(G,D,F){if(A.isObject(G)){var E,H;for(E in G){if(G.hasOwnProperty(E)){H=B.buildPath(G[E]);if(H&&D){F.meta[E]=B.getLocationValue(H,D);}}}}else{F.error=new Error(this.toString()+" Meta retrieval failure");}return F;}};C.DataSchema.JSON=C.mix(B,C.DataSchema.Base);},"@VERSION@",{requires:["dataschema-base"]});