3
Copyright 2011 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('datasource-xmlschema', function(Y) {
10
* Extends DataSource with schema-parsing on XML data.
13
* @submodule datasource-xmlschema
17
* Adds schema-parsing to the DataSource Utility.
18
* @class DataSourceXMLSchema
19
* @extends Plugin.Base
21
var DataSourceXMLSchema = function() {
22
DataSourceXMLSchema.superclass.constructor.apply(this, arguments);
25
Y.mix(DataSourceXMLSchema, {
27
* The namespace for the plugin. This will be the property on the host which
28
* references the plugin instance.
45
* @value "dataSourceXMLSchema"
47
NAME: "dataSourceXMLSchema",
49
/////////////////////////////////////////////////////////////////////////////
51
// DataSourceXMLSchema Attributes
53
/////////////////////////////////////////////////////////////////////////////
62
Y.extend(DataSourceXMLSchema, Y.Plugin.Base, {
64
* Internal init() handler.
67
* @param config {Object} Config object.
70
initializer: function(config) {
71
this.doBefore("_defDataFn", this._beforeDefDataFn);
75
* Parses raw data into a normalized response.
77
* @method _beforeDefDataFn
78
* @param tId {Number} Unique transaction ID.
79
* @param request {Object} The request.
80
* @param callback {Object} The callback object with the following properties:
82
* <dt>success (Function)</dt> <dd>Success handler.</dd>
83
* <dt>failure (Function)</dt> <dd>Failure handler.</dd>
85
* @param data {Object} Raw data.
88
_beforeDefDataFn: function(e) {
89
var schema = this.get('schema'),
90
payload = e.details[0],
91
// TODO: Do I need to sniff for DS.IO + responseXML.nodeType 9?
92
data = e.data.responseXML || e.data;
94
payload.response = Y.DataSchema.XML.apply.call(this, schema, data) || {
99
this.get("host").fire("response", payload);
101
return new Y.Do.Halt("DataSourceXMLSchema plugin halted _defDataFn");
105
Y.namespace('Plugin').DataSourceXMLSchema = DataSourceXMLSchema;
108
}, '3.4.1' ,{requires:['datasource-local', 'plugin', 'dataschema-xml']});