]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/yui3/build/dataschema/dataschema.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / include / javascript / yui3 / build / dataschema / dataschema.js
1 /*
2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
5 version: 3.3.0
6 build: 3167
7 */
8 YUI.add('dataschema-base', function(Y) {
9
10 /**
11  * The DataSchema utility provides a common configurable interface for widgets to
12  * apply a given schema to a variety of data.
13  *
14  * @module dataschema
15  */
16
17 /**
18  * Provides the base DataSchema implementation, which can be extended to 
19  * create DataSchemas for specific data formats, such XML, JSON, text and
20  * arrays.
21  *
22  * @module dataschema
23  * @submodule dataschema-base
24  */
25
26 var LANG = Y.Lang,
27 /**
28  * Base class for the YUI DataSchema Utility.
29  * @class DataSchema.Base
30  * @static
31  */
32     SchemaBase = {
33     /**
34      * Overridable method returns data as-is.
35      *
36      * @method apply
37      * @param schema {Object} Schema to apply.
38      * @param data {Object} Data.
39      * @return {Object} Schema-parsed data.
40      * @static
41      */
42     apply: function(schema, data) {
43         return data;
44     },
45     
46     /**
47      * Applies field parser, if defined
48      *
49      * @method parse
50      * @param value {Object} Original value.
51      * @param field {Object} Field.
52      * @return {Object} Type-converted value.
53      */
54     parse: function(value, field) {
55         if(field.parser) {
56             var parser = (LANG.isFunction(field.parser)) ?
57             field.parser : Y.Parsers[field.parser+''];
58             if(parser) {
59                 value = parser.call(this, value);
60             }
61             else {
62             }
63         }
64         return value;
65     }
66 };
67
68 Y.namespace("DataSchema").Base = SchemaBase;
69 Y.namespace("Parsers");
70
71
72
73 }, '3.3.0' ,{requires:['base']});
74
75 YUI.add('dataschema-json', function(Y) {
76
77 /**
78  * Provides a DataSchema implementation which can be used to work with JSON data.
79  *
80  * @module dataschema
81  * @submodule dataschema-json
82  */
83
84 /**
85  * JSON subclass for the DataSchema Utility.
86  * @class DataSchema.JSON
87  * @extends DataSchema.Base
88  * @static
89  */
90 var LANG = Y.Lang,
91
92     SchemaJSON = {
93
94         /////////////////////////////////////////////////////////////////////////////
95         //
96         // DataSchema.JSON static methods
97         //
98         /////////////////////////////////////////////////////////////////////////////
99         /**
100          * Utility function converts JSON locator strings into walkable paths
101          *
102          * @method DataSchema.JSON.getPath
103          * @param locator {String} JSON value locator.
104          * @return {String[]} Walkable path to data value.
105          * @static
106          */
107         getPath: function(locator) {
108             var path = null,
109                 keys = [],
110                 i = 0;
111
112             if (locator) {
113                 // Strip the ["string keys"] and [1] array indexes
114                 locator = locator.
115                     replace(/\[(['"])(.*?)\1\]/g,
116                     function (x,$1,$2) {keys[i]=$2;return '.@'+(i++);}).
117                     replace(/\[(\d+)\]/g,
118                     function (x,$1) {keys[i]=parseInt($1,10)|0;return '.@'+(i++);}).
119                     replace(/^\./,''); // remove leading dot
120
121                 // Validate against problematic characters.
122                 if (!/[^\w\.\$@]/.test(locator)) {
123                     path = locator.split('.');
124                     for (i=path.length-1; i >= 0; --i) {
125                         if (path[i].charAt(0) === '@') {
126                             path[i] = keys[parseInt(path[i].substr(1),10)];
127                         }
128                     }
129                 }
130                 else {
131                 }
132             }
133             return path;
134         },
135
136         /**
137          * Utility function to walk a path and return the value located there.
138          *
139          * @method DataSchema.JSON.getLocationValue
140          * @param path {String[]} Locator path.
141          * @param data {String} Data to traverse.
142          * @return {Object} Data value at location.
143          * @static
144          */
145         getLocationValue: function (path, data) {
146             var i = 0,
147                 len = path.length;
148             for (;i<len;i++) {
149                 if(
150                     LANG.isObject(data) &&
151                     (path[i] in data)
152                 ) {
153                     data = data[path[i]];
154                 }
155                 else {
156                     data = undefined;
157                     break;
158                 }
159             }
160             return data;
161         },
162
163         /**
164          * Applies a given schema to given JSON data.
165          *
166          * @method apply
167          * @param schema {Object} Schema to apply.
168          * @param data {Object} JSON data.
169          * @return {Object} Schema-parsed data.
170          * @static
171          */
172         apply: function(schema, data) {
173             var data_in = data,
174                 data_out = {results:[],meta:{}};
175
176             // Convert incoming JSON strings
177             if(!LANG.isObject(data)) {
178                 try {
179                     data_in = Y.JSON.parse(data);
180                 }
181                 catch(e) {
182                     data_out.error = e;
183                     return data_out;
184                 }
185             }
186
187             if(LANG.isObject(data_in) && schema) {
188                 // Parse results data
189                 if(!LANG.isUndefined(schema.resultListLocator)) {
190                     data_out = SchemaJSON._parseResults.call(this, schema, data_in, data_out);
191                 }
192
193                 // Parse meta data
194                 if(!LANG.isUndefined(schema.metaFields)) {
195                     data_out = SchemaJSON._parseMeta(schema.metaFields, data_in, data_out);
196                 }
197             }
198             else {
199                 data_out.error = new Error("JSON schema parse failure");
200             }
201
202             return data_out;
203         },
204
205         /**
206          * Schema-parsed list of results from full data
207          *
208          * @method _parseResults
209          * @param schema {Object} Schema to parse against.
210          * @param json_in {Object} JSON to parse.
211          * @param data_out {Object} In-progress parsed data to update.
212          * @return {Object} Parsed data object.
213          * @static
214          * @protected
215          */
216         _parseResults: function(schema, json_in, data_out) {
217             var results = [],
218                 path,
219                 error;
220
221             if(schema.resultListLocator) {
222                 path = SchemaJSON.getPath(schema.resultListLocator);
223                 if(path) {
224                     results = SchemaJSON.getLocationValue(path, json_in);
225                     if (results === undefined) {
226                         data_out.results = [];
227                         error = new Error("JSON results retrieval failure");
228                     }
229                     else {
230                         if(LANG.isArray(results)) {
231                             // if no result fields are passed in, then just take the results array whole-hog
232                             // Sometimes you're getting an array of strings, or want the whole object,
233                             // so resultFields don't make sense.
234                             if (LANG.isArray(schema.resultFields)) {
235                                 data_out = SchemaJSON._getFieldValues.call(this, schema.resultFields, results, data_out);
236                             }
237                             else {
238                                 data_out.results = results;
239                             }
240                         }
241                         else {
242                             data_out.results = [];
243                             error = new Error("JSON Schema fields retrieval failure");
244                         }
245                     }
246                 }
247                 else {
248                     error = new Error("JSON Schema results locator failure");
249                 }
250
251                 if (error) {
252                     data_out.error = error;
253                 }
254
255             }
256             return data_out;
257         },
258
259         /**
260          * Get field data values out of list of full results
261          *
262          * @method _getFieldValues
263          * @param fields {Array} Fields to find.
264          * @param array_in {Array} Results to parse.
265          * @param data_out {Object} In-progress parsed data to update.
266          * @return {Object} Parsed data object.
267          * @static
268          * @protected
269          */
270         _getFieldValues: function(fields, array_in, data_out) {
271             var results = [],
272                 len = fields.length,
273                 i, j,
274                 field, key, locator, path, parser,
275                 simplePaths = [], complexPaths = [], fieldParsers = [],
276                 result, record;
277
278             // First collect hashes of simple paths, complex paths, and parsers
279             for (i=0; i<len; i++) {
280                 field = fields[i]; // A field can be a simple string or a hash
281                 key = field.key || field; // Find the key
282                 locator = field.locator || key; // Find the locator
283
284                 // Validate and store locators for later
285                 path = SchemaJSON.getPath(locator);
286                 if (path) {
287                     if (path.length === 1) {
288                         simplePaths[simplePaths.length] = {key:key, path:path[0]};
289                     } else {
290                         complexPaths[complexPaths.length] = {key:key, path:path};
291                     }
292                 } else {
293                 }
294
295                 // Validate and store parsers for later
296                 //TODO: use Y.DataSchema.parse?
297                 parser = (LANG.isFunction(field.parser)) ? field.parser : Y.Parsers[field.parser+''];
298                 if (parser) {
299                     fieldParsers[fieldParsers.length] = {key:key, parser:parser};
300                 }
301             }
302
303             // Traverse list of array_in, creating records of simple fields,
304             // complex fields, and applying parsers as necessary
305             for (i=array_in.length-1; i>=0; --i) {
306                 record = {};
307                 result = array_in[i];
308                 if(result) {
309                     // Cycle through simpleLocators
310                     for (j=simplePaths.length-1; j>=0; --j) {
311                         // Bug 1777850: The result might be an array instead of object
312                         record[simplePaths[j].key] = Y.DataSchema.Base.parse.call(this,
313                                 (LANG.isUndefined(result[simplePaths[j].path]) ?
314                                 result[j] : result[simplePaths[j].path]), simplePaths[j]);
315                     }
316
317                     // Cycle through complexLocators
318                     for (j=complexPaths.length - 1; j>=0; --j) {
319                         record[complexPaths[j].key] = Y.DataSchema.Base.parse.call(this,
320                             (SchemaJSON.getLocationValue(complexPaths[j].path, result)), complexPaths[j] );
321                     }
322
323                     // Cycle through fieldParsers
324                     for (j=fieldParsers.length-1; j>=0; --j) {
325                         key = fieldParsers[j].key;
326                         record[key] = fieldParsers[j].parser.call(this, record[key]);
327                         // Safety net
328                         if (LANG.isUndefined(record[key])) {
329                             record[key] = null;
330                         }
331                     }
332                     results[i] = record;
333                 }
334             }
335             data_out.results = results;
336             return data_out;
337         },
338
339         /**
340          * Parses results data according to schema
341          *
342          * @method _parseMeta
343          * @param metaFields {Object} Metafields definitions.
344          * @param json_in {Object} JSON to parse.
345          * @param data_out {Object} In-progress parsed data to update.
346          * @return {Object} Schema-parsed meta data.
347          * @static
348          * @protected
349          */
350         _parseMeta: function(metaFields, json_in, data_out) {
351             if(LANG.isObject(metaFields)) {
352                 var key, path;
353                 for(key in metaFields) {
354                     if (metaFields.hasOwnProperty(key)) {
355                         path = SchemaJSON.getPath(metaFields[key]);
356                         if (path && json_in) {
357                             data_out.meta[key] = SchemaJSON.getLocationValue(path, json_in);
358                         }
359                     }
360                 }
361             }
362             else {
363                 data_out.error = new Error("JSON meta data retrieval failure");
364             }
365             return data_out;
366         }
367     };
368
369 Y.DataSchema.JSON = Y.mix(SchemaJSON, Y.DataSchema.Base);
370
371
372
373 }, '3.3.0' ,{requires:['dataschema-base','json']});
374
375 YUI.add('dataschema-xml', function(Y) {
376
377 /**
378  * Provides a DataSchema implementation which can be used to work with XML data.
379  *
380  * @module dataschema
381  * @submodule dataschema-xml
382  */
383 var LANG = Y.Lang,
384
385     /**
386      * XML subclass for the DataSchema Utility.
387      * @class DataSchema.XML
388      * @extends DataSchema.Base
389      * @static
390      */
391     SchemaXML = {
392
393         /////////////////////////////////////////////////////////////////////////////
394         //
395         // DataSchema.XML static methods
396         //
397         /////////////////////////////////////////////////////////////////////////////
398         /**
399          * Applies a given schema to given XML data.
400          *
401          * @method apply
402          * @param schema {Object} Schema to apply.
403          * @param data {XMLDoc} XML document.
404          * @return {Object} Schema-parsed data.
405          * @static
406          */
407         apply: function(schema, data) {
408             var xmldoc = data, // unnecessary variables
409                 data_out = {results:[],meta:{}};
410
411             if(xmldoc && xmldoc.nodeType && (9 === xmldoc.nodeType || 1 === xmldoc.nodeType || 11 === xmldoc.nodeType) && schema) {
412                 // Parse results data
413                 data_out = SchemaXML._parseResults.call(this, schema, xmldoc, data_out);
414
415                 // Parse meta data
416                 data_out = SchemaXML._parseMeta.call(this, schema.metaFields, xmldoc, data_out);
417             }
418             else {
419                 data_out.error = new Error("XML schema parse failure");
420             }
421
422             return data_out;
423         },
424
425         /**
426          * Get an XPath-specified value for a given field from an XML node or document.
427          *
428          * @method _getLocationValue
429          * @param field {String | Object} Field definition.
430          * @param context {Object} XML node or document to search within.
431          * @return {Object} Data value or null.
432          * @static
433          * @protected
434          */
435         _getLocationValue: function(field, context) {
436             var locator = field.locator || field.key || field,
437                 xmldoc = context.ownerDocument || context,
438                 result, res, value = null;
439
440             try {
441                 result = SchemaXML._getXPathResult(locator, context, xmldoc);
442                 while(res = result.iterateNext()) {
443                     value = res.textContent || res.value || res.text || res.innerHTML || null;
444                 }
445
446                 return Y.DataSchema.Base.parse.call(this, value, field);
447             }
448             catch(e) {
449             }
450
451             return null;
452         },
453
454         /**
455          * Fetches the XPath-specified result for a given location in an XML node or document.
456          *
457          * @param locator {String} The XPath location.
458          * @param context {Object} XML node or document to search within.
459          * @param xmldoc {Object} XML document to resolve namespace.
460          * @return {Object} Data collection or null.
461          * @static
462          * @protected
463          */
464         _getXPathResult: function(locator, context, xmldoc) {
465             // Standards mode
466             if (! LANG.isUndefined(xmldoc.evaluate)) {
467                 return xmldoc.evaluate(locator, context, xmldoc.createNSResolver(context.ownerDocument ? context.ownerDocument.documentElement : context.documentElement), 0, null);
468             }
469             // IE mode
470             else {
471                 var values=[], locatorArray = locator.split(/\b\/\b/), i=0, l=locatorArray.length, location, subloc, m, isNth;
472                 
473                 // XPath is supported
474                 try {
475                     // this fixes the IE 5.5+ issue where childnode selectors begin at 0 instead of 1
476                     xmldoc.setProperty("SelectionLanguage", "XPath");
477                     values = context.selectNodes(locator);
478                 }
479                 // Fallback for DOM nodes and fragments
480                 catch (e) {
481                     // Iterate over each locator piece
482                     for (; i<l && context; i++) {
483                         location = locatorArray[i];
484
485                         // grab nth child []
486                         if ((location.indexOf("[") > -1) && (location.indexOf("]") > -1)) {
487                             subloc = location.slice(location.indexOf("[")+1, location.indexOf("]"));
488                             //XPath is 1-based while DOM is 0-based
489                             subloc--;
490                             context = context.children[subloc];
491                             isNth = true;
492                         }
493                         // grab attribute value @
494                         else if (location.indexOf("@") > -1) {
495                             subloc = location.substr(location.indexOf("@"));
496                             context = subloc ? context.getAttribute(subloc.replace('@', '')) : context;
497                         }
498                         // grab that last instance of tagName
499                         else if (-1 < location.indexOf("//")) {
500                             subloc = context.getElementsByTagName(location.substr(2));
501                             context = subloc.length ? subloc[subloc.length - 1] : null;
502                         }
503                         // find the last matching location in children
504                         else if (l != i + 1) {
505                             for (m=context.childNodes.length-1; 0 <= m; m-=1) {
506                                 if (location === context.childNodes[m].tagName) {
507                                     context = context.childNodes[m];
508                                     m = -1;
509                                 }
510                             }
511                         }
512                     }
513                     
514                     if (context) {
515                         // attribute
516                         if (LANG.isString(context)) {
517                             values[0] = {value: context};
518                         }
519                         // nth child
520                         else if (isNth) {
521                             values[0] = {value: context.innerHTML};
522                         }
523                         // all children
524                         else {
525                             values = Y.Array(context.childNodes, 0, true);
526                         }
527                     }
528                 }
529
530                 // returning a mock-standard object for IE
531                 return {
532                     index: 0,
533                     
534                     iterateNext: function() {
535                         if (this.index >= this.values.length) {return undefined;}
536                         var result = this.values[this.index];
537                         this.index += 1;
538                         return result;
539                     },
540
541                     values: values
542                 };
543             }
544         },
545
546         /**
547          * Schema-parsed result field.
548          *
549          * @method _parseField
550          * @param field {String | Object} Required. Field definition.
551          * @param result {Object} Required. Schema parsed data object.
552          * @param context {Object} Required. XML node or document to search within.
553          * @static
554          * @protected
555          */
556         _parseField: function(field, result, context) {
557             if (field.schema) {
558                 result[field.key] = SchemaXML._parseResults.call(this, field.schema, context, {results:[],meta:{}}).results;
559             }
560             else {
561                 result[field.key || field] = SchemaXML._getLocationValue.call(this, field, context);
562             }
563         },
564
565         /**
566          * Parses results data according to schema
567          *
568          * @method _parseMeta
569          * @param xmldoc_in {Object} XML document parse.
570          * @param data_out {Object} In-progress schema-parsed data to update.
571          * @return {Object} Schema-parsed data.
572          * @static
573          * @protected
574          */
575         _parseMeta: function(metaFields, xmldoc_in, data_out) {
576             if(LANG.isObject(metaFields)) {
577                 var key,
578                     xmldoc = xmldoc_in.ownerDocument || xmldoc_in;
579
580                 for(key in metaFields) {
581                     if (metaFields.hasOwnProperty(key)) {
582                         data_out.meta[key] = SchemaXML._getLocationValue.call(this, metaFields[key], xmldoc);
583                     }
584                 }
585             }
586             return data_out;
587         },
588
589         /**
590          * Schema-parsed result to add to results list.
591          *
592          * @method _parseResult
593          * @param fields {Array} Required. A collection of field definition.
594          * @param context {Object} Required. XML node or document to search within.
595          * @return {Object} Schema-parsed data.
596          * @static
597          * @protected
598          */
599         _parseResult: function(fields, context) {
600             var result = {}, j;
601
602             // Find each field value
603             for (j=fields.length-1; 0 <= j; j--) {
604                 SchemaXML._parseField.call(this, fields[j], result, context);
605             }
606
607             return result;
608         },
609
610         /**
611          * Schema-parsed list of results from full data
612          *
613          * @method _parseResults
614          * @param schema {Object} Schema to parse against.
615          * @param context {Object} XML node or document to parse.
616          * @param data_out {Object} In-progress schema-parsed data to update.
617          * @return {Object} Schema-parsed data.
618          * @static
619          * @protected
620          */
621         _parseResults: function(schema, context, data_out) {
622             if (schema.resultListLocator && LANG.isArray(schema.resultFields)) {
623                 var xmldoc = context.ownerDocument || context,
624                     fields = schema.resultFields,
625                     results = [],
626                     node, result, nodeList, i=0;
627
628                 if (schema.resultListLocator.match(/^[:\-\w]+$/)) {
629                     nodeList = context.getElementsByTagName(schema.resultListLocator);
630                     
631                     // loop through each result node
632                     for (i=nodeList.length-1; 0 <= i; i--) {
633                         results[i] = SchemaXML._parseResult.call(this, fields, nodeList[i]);
634                     }
635                 }
636                 else {
637                     nodeList = SchemaXML._getXPathResult(schema.resultListLocator, context, xmldoc);
638
639                     // loop through the nodelist
640                     while (node = nodeList.iterateNext()) {
641                         results[i] = SchemaXML._parseResult.call(this, fields, node);
642                         i += 1;
643                     }
644                 }
645
646                 if (results.length) {
647                     data_out.results = results;
648                 }
649                 else {
650                     data_out.error = new Error("XML schema result nodes retrieval failure");
651                 }
652             }
653             return data_out;
654         }
655     };
656
657 Y.DataSchema.XML = Y.mix(SchemaXML, Y.DataSchema.Base);
658
659
660
661 }, '3.3.0' ,{requires:['dataschema-base']});
662
663 YUI.add('dataschema-array', function(Y) {
664
665 /**
666  * Provides a DataSchema implementation which can be used to work with data stored in arrays.
667  *
668  * @module dataschema
669  * @submodule dataschema-array
670  */
671
672 /**
673  * Array subclass for the DataSchema Utility.
674  * @class DataSchema.Array
675  * @extends DataSchema.Base
676  * @static
677  */
678 var LANG = Y.Lang,
679
680     SchemaArray = {
681
682         /////////////////////////////////////////////////////////////////////////////
683         //
684         // DataSchema.Array static methods
685         //
686         /////////////////////////////////////////////////////////////////////////////
687         /**
688          * Applies a given schema to given Array data.
689          *
690          * @method apply
691          * @param schema {Object} Schema to apply.
692          * @param data {Object} Array data.
693          * @return {Object} Schema-parsed data.
694          * @static
695          */
696         apply: function(schema, data) {
697             var data_in = data,
698                 data_out = {results:[],meta:{}};
699
700             if(LANG.isArray(data_in)) {
701                 if(LANG.isArray(schema.resultFields)) {
702                     // Parse results data
703                     data_out = SchemaArray._parseResults.call(this, schema.resultFields, data_in, data_out);
704                 }
705                 else {
706                     data_out.results = data_in;
707                 }
708             }
709             else {
710                 data_out.error = new Error("Array schema parse failure");
711             }
712
713             return data_out;
714         },
715
716         /**
717          * Schema-parsed list of results from full data
718          *
719          * @method _parseResults
720          * @param fields {Array} Schema to parse against.
721          * @param array_in {Array} Array to parse.
722          * @param data_out {Object} In-progress parsed data to update.
723          * @return {Object} Parsed data object.
724          * @static
725          * @protected
726          */
727         _parseResults: function(fields, array_in, data_out) {
728             var results = [],
729                 result, item, type, field, key, value, i, j;
730
731             for(i=array_in.length-1; i>-1; i--) {
732                 result = {};
733                 item = array_in[i];
734                 type = (LANG.isObject(item) && !LANG.isFunction(item)) ? 2 : (LANG.isArray(item)) ? 1 : (LANG.isString(item)) ? 0 : -1;
735                 if(type > 0) {
736                     for(j=fields.length-1; j>-1; j--) {
737                         field = fields[j];
738                         key = (!LANG.isUndefined(field.key)) ? field.key : field;
739                         value = (!LANG.isUndefined(item[key])) ? item[key] : item[j];
740                         result[key] = Y.DataSchema.Base.parse.call(this, value, field);
741                     }
742                 }
743                 else if(type === 0) {
744                     result = item;
745                 }
746                 else {
747                     //TODO: null or {}?
748                     result = null;
749                 }
750                 results[i] = result;
751             }
752             data_out.results = results;
753
754             return data_out;
755         }
756     };
757
758 Y.DataSchema.Array = Y.mix(SchemaArray, Y.DataSchema.Base);
759
760
761
762 }, '3.3.0' ,{requires:['dataschema-base']});
763
764 YUI.add('dataschema-text', function(Y) {
765
766 /**
767  * Provides a DataSchema implementation which can be used to work with delimited text data.
768  *
769  * @module dataschema
770  * @submodule dataschema-text
771  */
772
773 /**
774  * Text subclass for the DataSchema Utility.
775  * @class DataSchema.Text
776  * @extends DataSchema.Base
777  * @static
778  */
779
780 var LANG = Y.Lang,
781
782     SchemaText = {
783
784         /////////////////////////////////////////////////////////////////////////////
785         //
786         // DataSchema.Text static methods
787         //
788         /////////////////////////////////////////////////////////////////////////////
789         /**
790          * Applies a given schema to given delimited text data.
791          *
792          * @method apply
793          * @param schema {Object} Schema to apply.
794          * @param data {Object} Text data.
795          * @return {Object} Schema-parsed data.
796          * @static
797          */
798         apply: function(schema, data) {
799             var data_in = data,
800                 data_out = {results:[],meta:{}};
801
802             if(LANG.isString(data_in) && LANG.isString(schema.resultDelimiter)) {
803                 // Parse results data
804                 data_out = SchemaText._parseResults.call(this, schema, data_in, data_out);
805             }
806             else {
807                 data_out.error = new Error("Text schema parse failure");
808             }
809
810             return data_out;
811         },
812
813         /**
814          * Schema-parsed list of results from full data
815          *
816          * @method _parseResults
817          * @param schema {Array} Schema to parse against.
818          * @param text_in {String} Text to parse.
819          * @param data_out {Object} In-progress parsed data to update.
820          * @return {Object} Parsed data object.
821          * @static
822          * @protected
823          */
824         _parseResults: function(schema, text_in, data_out) {
825             var resultDelim = schema.resultDelimiter,
826                 results = [],
827                 results_in, fields_in, result, item, fields, field, key, value, i, j,
828
829             // Delete final delimiter at end of string if there
830             tmpLength = text_in.length-resultDelim.length;
831             if(text_in.substr(tmpLength) == resultDelim) {
832                 text_in = text_in.substr(0, tmpLength);
833             }
834
835             // Split into results
836             results_in = text_in.split(schema.resultDelimiter);
837
838             for(i=results_in.length-1; i>-1; i--) {
839                 result = {};
840                 item = results_in[i];
841
842                 if(LANG.isString(schema.fieldDelimiter)) {
843                     fields_in = item.split(schema.fieldDelimiter);
844
845                     if(LANG.isArray(schema.resultFields)) {
846                         fields = schema.resultFields;
847                         for(j=fields.length-1; j>-1; j--) {
848                             field = fields[j];
849                             key = (!LANG.isUndefined(field.key)) ? field.key : field;
850                             value = (!LANG.isUndefined(fields_in[key])) ? fields_in[key] : fields_in[j];
851                             result[key] = Y.DataSchema.Base.parse.call(this, value, field);
852                         }
853                     }
854
855                 }
856                 else {
857                     result = item;
858                 }
859
860                 results[i] = result;
861             }
862             data_out.results = results;
863
864             return data_out;
865         }
866     };
867
868 Y.DataSchema.Text = Y.mix(SchemaText, Y.DataSchema.Base);
869
870
871
872 }, '3.3.0' ,{requires:['dataschema-base']});
873
874
875
876 YUI.add('dataschema', function(Y){}, '3.3.0' ,{use:['dataschema-base','dataschema-json','dataschema-xml','dataschema-array','dataschema-text']});
877