1 /* Licensed to the Apache Software Foundation (ASF) under one or more
  2  * contributor license agreements.  See the NOTICE file distributed with
  3  * this work for additional information regarding copyright ownership.
  4  * The ASF licenses this file to you under the Apache License, Version 2.0
  5  * (the "License"); you may not use this file except in compliance with
  6  * the License.  You may obtain a copy of the License at
  7  *
  8  *      http://www.apache.org/licenses/LICENSE-2.0
  9  *
 10  * Unless required by applicable law or agreed to in writing, software
 11  * distributed under the License is distributed on an "AS IS" BASIS,
 12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  * See the License for the specific language governing permissions and
 14  * limitations under the License.
 15  */
 16 /**
 17  * Abstract Base for all classes which simulate the xhr level2 object
 18  * with a different transport
 19  *
 20  * <h3>Every class inheriting the interface must expose following methods and attributes</h3>
 21  *
 22  * <ul>
 23  *      <li>open(method, url, async)</li>
 24  *      <li>send(formData)</li>
 25  *      <li>setRequestHeader(key, value)</li>
 26  *      <li>abort()</li>
 27  *      <li>onloadstart()</li>
 28  *      <li>onprogress()</li>
 29  *      <li>onabort()</li>
 30  *      <li>onerror()</li>
 31  *      <li>onload()</li>
 32  *      <li>ontimeout()</li>
 33  *      <li>onloadend()</li>
 34  *      <li>onreadystatechange()</li>
 35  * </ul>
 36  * <h3>following attributes are supported</h3>
 37  * <ul>
 38  *      <li>async</li>
 39  *      <li>url</li>
 40  *      <li>method</li>
 41  *      <li>timeout</li>
 42  *      <li>response</li>
 43  *      <li>responseText</li>
 44  *      <li>responseXML</li>
 45  *      <li>status</li>
 46  *      <li>statusText</li>
 47  * </ul>
 48  */
 49 /**
 50  * @class
 51  * @name BaseRequest
 52  * @memberOf myfaces._impl.xhrCore.engine
 53  * @extends myfaces._impl.core.Object
 54  * @description
 55  * Abstract Base for all classes which simulate the xhr level2 object
 56  * with a different transport
 57  *
 58  * <h3>Every class inheriting the interface must expose following methods and attributes</h3>
 59  *
 60  * <ul>
 61  *      <li>open(method, url, async)</li>
 62  *      <li>send(formData)</li>
 63  *      <li>setRequestHeader(key, value)</li>
 64  *      <li>abort()</li>
 65  *      <li>onloadstart()</li>
 66  *      <li>onprogress()</li>
 67  *      <li>onabort()</li>
 68  *      <li>onerror()</li>
 69  *      <li>onload()</li>
 70  *      <li>ontimeout()</li>
 71  *      <li>onloadend()</li>
 72  *      <li>onreadystatechange()</li>
 73  * </ul>
 74  * <h3>following attributes are supported</h3>
 75  * <ul>
 76  *      <li>async</li>
 77  *      <li>url</li>
 78  *      <li>method</li>
 79  *      <li>timeout</li>
 80  *      <li>response</li>
 81  *      <li>responseText</li>
 82  *      <li>responseXML</li>
 83  *      <li>status</li>
 84  *      <li>statusText</li>
 85  * </ul>
 86  */
 87 _MF_CLS(_PFX_XHR + "engine.BaseRequest", _MF_OBJECT, /** @lends myfaces._impl.xhrCore.engine.BaseRequest.prototype */ {
 88     /*standard attributes*/
 89 
 90     /**
 91      * timeout attribute with a timeout for the request in miliseconds
 92      */
 93     timeout:0,
 94     /**
 95      * readonly ready stte attribute
 96      */
 97     readyState:0,
 98     /**
 99      * send method, allowed values POST and GET
100      */
101     method:"POST",
102     /**
103      * the url for the call
104      */
105     url:null,
106     /**
107      * asynchronous request, if set to true then the request happens
108      * asynchronously, if possible.
109      */
110     async:true,
111     /**
112      * read only response object, containing the response as json/dom representation
113      */
114     response:null,
115     /**
116      * read only plain text representation of the response
117      */
118     responseText:null,
119     /**
120      * xml dom readonly representation of the response
121      */
122     responseXML:null,
123     /**
124      * readonly status code of the response
125      */
126     status:null,
127     /**
128      * readonly status text of the response
129      */
130     statusText:null,
131 
132     constructor_:function (params) {
133         this._callSuper("constructor_", params);
134         this._initDefaultFinalizableFields();
135 
136         this._XHRConst = myfaces._impl.xhrCore.engine.XhrConst;
137         this._Lang.applyArgs(this, params);
138     },
139 
140     //open send, abort etc... abstract
141     /**
142      * opens the transport element
143      * @param {String} method transport method allowed values <i>POST</i> and <i>GET</i>
144      * @param {String} url optional url
145      * @param {Boolean} async optional param asynchronous transmission if set to true
146      */
147     open:function (method, url, async) {
148         this._implementThis();
149     },
150     /**
151      * send method
152      * @param {Object} formData data to be posted within the request
153      */
154     send:function (formData) {
155         this._implementThis();
156     },
157     /**
158      * appends a key value pair to the request header if possible
159      * @param {String} key the key of the request header entry
160      * @param {String} value  the value for the key
161      */
162     setRequestHeader:function (key, value) {
163         this._implementThis();
164     },
165     /**
166      * aborts the transmission
167      */
168     abort:function () {
169         this._implementThis();
170     },
171 
172     //empty implementations for the callback handlers
173     /**
174      * callback once the transmission has started
175      * @param evt
176      */
177     onloadstart:function (evt) {
178     },
179     onprogress:function (evt) {
180     },
181     onabort:function (evt) {
182     },
183     onerror:function (evt) {
184     },
185     onload:function (evt) {
186     },
187     ontimeout:function (evt) {
188     },
189     onloadend:function (evt) {
190     },
191     onreadystatechange:function (evt) {
192     },
193 
194     _implementThis:function () {
195         throw Error("the function needs to be implemented");
196     }
197 });
198