~crf-team/crf-irp/crf-irp

« back to all changes in this revision

Viewing changes to WebContent/js/extjs-2/docs/output/XmlReader.jss.html

  • Committer: Thomas
  • Date: 2010-03-10 23:55:46 UTC
  • Revision ID: thomas@daisybox-port-20100310235546-23635dk6x5asb1ca
Upgrade ExtJs 3.1.1
Upgrade Spring 3.0.1 + dependencies
Change Jawr JS post processor : YUI
Upgrade to last build of dwr 3 trunk 69 revision 3019(after build 116), upgrade jawr-dwr plugin 1.4 unofficiale from jose noheda, Jawr 3.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<html><head><title>XmlReader.js</title><link rel="stylesheet" type="text/css" href="../resources/style.css" media="screen"/></head><body><h1>XmlReader.js</h1><pre class="highlighted"><code><i>/**
2
 
 * @class Ext.data.XmlReader
3
 
 * @extends Ext.data.DataReader
4
 
 * Data reader class to create an Array of {@link Ext.data.Record} objects from an XML document
5
 
 * based on mappings <b>in</b> a provided {@link Ext.data.Record} constructor.&lt;br&gt;&lt;br&gt;
6
 
 * &lt;p&gt;
7
 
 * &lt;em&gt;Note that <b>in</b> order <b>for</b> the browser to parse a returned XML document, the Content-Type
8
 
 * header <b>in</b> the HTTP response must be set to &quot;text/xml&quot; or &quot;application/xml&quot;.&lt;/em&gt;
9
 
 * &lt;p&gt;
10
 
 * Example code:
11
 
 * &lt;pre&gt;&lt;code&gt;
12
 
<b>var</b> Employee = Ext.data.Record.create([
13
 
   {name: <em>'name'</em>, mapping: <em>'name'</em>},     <i>// &quot;mapping&quot; property not needed <b>if</b> it's the same as &quot;name&quot;</i>
14
 
   {name: <em>'occupation'</em>}                 <i>// This field will use &quot;occupation&quot; as the mapping.</i>
15
 
]);
16
 
<b>var</b> myReader = <b>new</b> Ext.data.XmlReader({
17
 
   totalRecords: &quot;results&quot;, <i>// The element which contains the total dataset size (optional)</i>
18
 
   record: &quot;row&quot;,           <i>// The repeated element which contains row information</i>
19
 
   id: &quot;id&quot;                 <i>// The element within the row that provides an ID <b>for</b> the record (optional)</i>
20
 
}, Employee);
21
 
&lt;/code&gt;&lt;/pre&gt;
22
 
 * &lt;p&gt;
23
 
 * This would consume an XML file like <b>this</b>:
24
 
 * &lt;pre&gt;&lt;code&gt;
25
 
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
26
 
&amp;lt;dataset&gt;
27
 
 &amp;lt;results&gt;2&amp;lt;/results&gt;
28
 
 &amp;lt;row&gt;
29
 
   &amp;lt;id&gt;1&amp;lt;/id&gt;
30
 
   &amp;lt;name&gt;Bill&amp;lt;/name&gt;
31
 
   &amp;lt;occupation&gt;Gardener&amp;lt;/occupation&gt;
32
 
 &amp;lt;/row&gt;
33
 
 &amp;lt;row&gt;
34
 
   &amp;lt;id&gt;2&amp;lt;/id&gt;
35
 
   &amp;lt;name&gt;Ben&amp;lt;/name&gt;
36
 
   &amp;lt;occupation&gt;Horticulturalist&amp;lt;/occupation&gt;
37
 
 &amp;lt;/row&gt;
38
 
&amp;lt;/dataset&gt;
39
 
&lt;/code&gt;&lt;/pre&gt;
40
 
 * @cfg {String} totalRecords The DomQuery path from which to retrieve the total number of records
41
 
 * <b>in</b> the dataset. This is only needed <b>if</b> the whole dataset is not passed <b>in</b> one go, but is being
42
 
 * paged from the remote server.
43
 
 * @cfg {String} record The DomQuery path to the repeated element which contains record information.
44
 
 * @cfg {String} success The DomQuery path to the success attribute used by forms.
45
 
 * @cfg {String} id The DomQuery path relative from the record element to the element that contains
46
 
 * a record identifier value.
47
 
 * @constructor
48
 
 * Create a <b>new</b> XmlReader.
49
 
 * @param {Object} meta Metadata configuration options
50
 
 * @param {Object} recordType Either an Array of field definition objects as passed to
51
 
 * {@link Ext.data.Record#create}, or a Record constructor object created using {@link Ext.data.Record#create}.
52
 
 */</i>
53
 
Ext.data.XmlReader = <b>function</b>(meta, recordType){
54
 
    meta = meta || {};
55
 
    Ext.data.XmlReader.superclass.constructor.call(<b>this</b>, meta, recordType || meta.fields);
56
 
};
57
 
Ext.extend(Ext.data.XmlReader, Ext.data.DataReader, {
58
 
    <i>/**
59
 
     * This method is only used by a DataProxy which has retrieved data from a remote server.
60
 
         * @param {Object} response The XHR object which contains the parsed XML document.  The response is expected
61
 
         * to contain a property called &lt;tt&gt;responseXML&lt;/tt&gt; which refers to an XML document object.
62
 
     * @<b>return</b> {Object} records A data block which is used by an {@link Ext.data.Store} as
63
 
     * a cache of Ext.data.Records.
64
 
     */</i>
65
 
    read : <b>function</b>(response){
66
 
        <b>var</b> doc = response.responseXML;
67
 
        <b>if</b>(!doc) {
68
 
            throw {message: &quot;XmlReader.read: XML Document not available&quot;};
69
 
        }
70
 
        <b>return</b> this.readRecords(doc);
71
 
    },
72
 
 
73
 
    <i>/**
74
 
     * Create a data block containing Ext.data.Records from an XML document.
75
 
         * @param {Object} doc A parsed XML document.
76
 
     * @<b>return</b> {Object} records A data block which is used by an {@link Ext.data.Store} as
77
 
     * a cache of Ext.data.Records.
78
 
     */</i>
79
 
    readRecords : <b>function</b>(doc){
80
 
        <i>/**
81
 
         * After any data loads/reads, the raw XML Document is available <b>for</b> further custom processing.
82
 
         * @type XMLDocument
83
 
         */</i>
84
 
        <b>this</b>.xmlData = doc;
85
 
        <b>var</b> root = doc.documentElement || doc;
86
 
        <b>var</b> q = Ext.DomQuery;
87
 
        <b>var</b> recordType = <b>this</b>.recordType, fields = recordType.prototype.fields;
88
 
        <b>var</b> sid = <b>this</b>.meta.id;
89
 
        <b>var</b> totalRecords = 0, success = true;
90
 
        <b>if</b>(this.meta.totalRecords){
91
 
            totalRecords = q.selectNumber(<b>this</b>.meta.totalRecords, root, 0);
92
 
        }
93
 
 
94
 
        <b>if</b>(this.meta.success){
95
 
            <b>var</b> sv = q.selectValue(<b>this</b>.meta.success, root, true);
96
 
            success = sv !== false &amp;&amp; sv !== <em>'false'</em>;
97
 
        }
98
 
        <b>var</b> records = [];
99
 
        <b>var</b> ns = q.select(<b>this</b>.meta.record, root);
100
 
        <b>for</b>(var i = 0, len = ns.length; i &lt; len; i++) {
101
 
                <b>var</b> n = ns[i];
102
 
                <b>var</b> values = {};
103
 
                <b>var</b> id = sid ? q.selectValue(sid, n) : undefined;
104
 
                <b>for</b>(var j = 0, jlen = fields.length; j &lt; jlen; j++){
105
 
                    <b>var</b> f = fields.items[j];
106
 
                <b>var</b> v = q.selectValue(Ext.isEmpty(f.mapping, true) ? f.name : f.mapping, n, f.defaultValue);
107
 
                    v = f.convert(v, n);
108
 
                    values[f.name] = v;
109
 
                }
110
 
                <b>var</b> record = <b>new</b> recordType(values, id);
111
 
                record.node = n;
112
 
                records[records.length] = record;
113
 
            }
114
 
 
115
 
            <b>return</b> {
116
 
                success : success,
117
 
                records : records,
118
 
                totalRecords : totalRecords || records.length
119
 
            };
120
 
    }
121
 
});</code></pre><hr><div style="font-size:10px;text-align:center;color:gray;">Ext - Copyright &copy; 2006-2007 Ext JS, LLC<br />All rights reserved.</div>
122
 
    </body></html>
 
 
b'\\ No newline at end of file'