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 /** 18 * @class 19 * @name BaseRequest 20 * @memberOf myfaces._impl.xhrCore.engine 21 * @extends myfaces._impl.core.Object 22 * @description 23 * Abstract Base for all classes which simulate the xhr level2 object 24 * with a different transport 25 * 26 * <h3>Every class inheriting the interface must expose following methods and attributes</h3> 27 * 28 * <ul> 29 * <li>open(method, url, async)</li> 30 * <li>send(formData)</li> 31 * <li>setRequestHeader(key, value)</li> 32 * <li>abort()</li> 33 * <li>onloadstart()</li> 34 * <li>onprogress()</li> 35 * <li>onabort()</li> 36 * <li>onerror()</li> 37 * <li>onload()</li> 38 * <li>ontimeout()</li> 39 * <li>onloadend()</li> 40 * <li>onreadystatechange()</li> 41 * </ul> 42 * <h3>following attributes are supported</h3> 43 * <ul> 44 * <li>async</li> 45 * <li>url</li> 46 * <li>method</li> 47 * <li>timeout</li> 48 * <li>response</li> 49 * <li>responseText</li> 50 * <li>responseXML</li> 51 * <li>status</li> 52 * <li>statusText</li> 53 * </ul> 54 */ 55 _MF_CLS(_PFX_XHR + "engine.BaseRequest", _MF_OBJECT, /** @lends myfaces._impl.xhrCore.engine.BaseRequest.prototype */ { 56 /*standard attributes*/ 57 58 /** 59 * timeout attribute with a timeout for the request in miliseconds 60 */ 61 timeout:0, 62 /** 63 * readonly ready stte attribute 64 */ 65 readyState:0, 66 /** 67 * send method, allowed values POST and GET 68 */ 69 method:"POST", 70 /** 71 * the url for the call 72 */ 73 url:null, 74 /** 75 * asynchronous request, if set to true then the request happens 76 * asynchronously, if possible. 77 */ 78 async:true, 79 /** 80 * read only response object, containing the response as json/dom representation 81 */ 82 response:null, 83 /** 84 * read only plain text representation of the response 85 */ 86 responseText:null, 87 /** 88 * xml dom readonly representation of the response 89 */ 90 responseXML:null, 91 /** 92 * readonly status code of the response 93 */ 94 status:null, 95 /** 96 * readonly status text of the response 97 */ 98 statusText:null, 99 100 constructor_:function (params) { 101 this._callSuper("constructor_", params); 102 this._initDefaultFinalizableFields(); 103 104 this._XHRConst = myfaces._impl.xhrCore.engine.XhrConst; 105 this._Lang.applyArgs(this, params); 106 }, 107 108 //open send, abort etc... abstract 109 /** 110 * opens the transport element 111 * @param {String} method transport method allowed values <i>POST</i> and <i>GET</i> 112 * @param {String} url optional url 113 * @param {Boolean} async optional param asynchronous transmission if set to true 114 */ 115 open:function (method, url, async) { 116 this._implementThis(); 117 }, 118 /** 119 * send method 120 * @param {Object} formData data to be posted within the request 121 */ 122 send:function (formData) { 123 this._implementThis(); 124 }, 125 /** 126 * appends a key value pair to the request header if possible 127 * @param {String} key the key of the request header entry 128 * @param {String} value the value for the key 129 */ 130 setRequestHeader:function (key, value) { 131 this._implementThis(); 132 }, 133 /** 134 * aborts the transmission 135 */ 136 abort:function () { 137 this._implementThis(); 138 }, 139 140 //empty implementations for the callback handlers 141 /** 142 * callback once the transmission has started 143 * @param evt 144 */ 145 onloadstart:function (evt) { 146 }, 147 onprogress:function (evt) { 148 }, 149 onabort:function (evt) { 150 }, 151 onerror:function (evt) { 152 }, 153 onload:function (evt) { 154 }, 155 ontimeout:function (evt) { 156 }, 157 onloadend:function (evt) { 158 }, 159 onreadystatechange:function (evt) { 160 }, 161 162 _implementThis:function () { 163 throw Error("the function needs to be implemented"); 164 } 165 });