[Slashhack-cvs] slashhack/resources/js/jslib/network/parts bodyParametersPart.js,NONE,1.1 filePart.j
Brought to you by:
fletch
|
From: Dave F. <fl...@us...> - 2004-10-21 03:49:26
|
Update of /cvsroot/slashhack/slashhack/resources/js/jslib/network/parts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4907/network/parts Added Files: bodyParametersPart.js filePart.js textPart.js urlParametersPart.js Log Message: Task #106454 - include jslib. --- NEW FILE: filePart.js --- /*** -*- Mode: Javascript; tab-width: 2; The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is jslib code. The Initial Developer of the Original Code is jslib team. Portions created by jslib team are Copyright (C) 2000 jslib team. All Rights Reserved. Contributor(s): Rajeev J Sebastian <raj...@ya...)> (original author) *************************************/ if (typeof(JS_LIB_LOADED)=='boolean') { const JS_FILEPART_FILE = "filePart.js"; const JS_FILEPART_LOADED = true; function FilePart() { } FilePart.prototype = { _name: null, _file: null, _cnttype: null, setFile: function( name, jsFile, contenttype ) { this._name = name; this._cnttype = contenttype; this._file = jsFile.nsIFile; }, //not applicable _getRequestUriParams: function() { return null; }, _getRequestHeaders: function() { var list = new Dictionary(); list.put("Content-type",_cnttype); if( _name != null ) list.put("Content-disposition","form-data; name=\""+_name+"\";"); return list; }, _getBody: function() { var nsIFileInStrm = Components.interfaces.nsIFileInputStream; var nsIBufInStrm = Components.interfaces.nsIBufferedInputStream; var finstrm = Components.classes["@mozilla.org/network/file-input-stream;1"]. createInstance( nsIFileInStrm ); finstrm.init(_file, 1, 1, finstrm.CLOSE_ON_EOF); this.instrm = Components.classes["@mozilla.org/network/buffered-input-stream;1"]. createInstance( nsIBufInStrm ); this.instrm.init(finstrm, 4096); return fstrm; } } jslibDebug('*** load: '+JS_FILEPART_FILE+' OK'); } // END BLOCK JS_LIB_LOADED CHECK // If jslib base library is not loaded, dump this error. else { dump("JS_BASE library not loaded:\n" + " \tTo load use: chrome://slashhack/content/resources/js/jslib/jslib.js\n" + " \tThen: include(jslib_filepart);\n\n"); }; --- NEW FILE: textPart.js --- /*** -*- Mode: Javascript; tab-width: 2; The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is jslib code. The Initial Developer of the Original Code is jslib team. Portions created by jslib team are Copyright (C) 2000 jslib team. All Rights Reserved. Contributor(s): Rajeev J Sebastian <raj...@ya...)> (original author) *************************************/ if (typeof(JS_LIB_LOADED)=='boolean') { const JS_TEXTPART_FILE = "textPart.js"; const JS_TEXTPART_LOADED = true; function TextPart() { } TextPart.prototype = { _name: null, _txt: null, _cnttype: null, setText: function( name, text, contenttype ) { this._name = name; this._cnttype = contenttype; this._txt = text; }, //not applicable _getRequestUriParams: function() { return null; }, _getRequestHeaders: function() { var list = new Dictionary(); list.put("Content-type",_cnttype); if( _name != null ) list.put("Content-disposition","form-data; name=\""+_name+"\";"); return list; }, _getBody: function() { var body = Components.classes["@mozilla.org/io/string-input-stream;1"]. createInstance( Components.interfaces.nsIStringInputStream ); body.setData(_txt,-1); return body; } } jslibDebug('*** load: '+JS_TEXTPART_FILE+' OK'); } // END BLOCK JS_LIB_LOADED CHECK // If jslib base library is not loaded, dump this error. else { dump("JS_BASE library not loaded:\n" + " \tTo load use: chrome://slashhack/content/resources/js/jslib/jslib.js\n" + " \tThen: include(jslib_textpart);\n\n"); }; --- NEW FILE: urlParametersPart.js --- /*** -*- Mode: Javascript; tab-width: 2; The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is jslib code. The Initial Developer of the Original Code is jslib team. Portions created by jslib team are Copyright (C) 2000 jslib team. All Rights Reserved. Contributor(s): Rajeev J Sebastian <raj...@ya...)> (original author) *************************************/ //this Part also accepts headers for the main multipart request if (typeof(JS_LIB_LOADED)=='boolean') { const JS_URLPARAMETERSPART_FILE = "urlParametersPart.js"; const JS_URLPARAMETERSPART_LOADED = true; if (typeof(JS_DICTIONARY_LOADED)!='boolean') include(jslib_dictionary); function URLParametersPart() { this._params = new Dictionary(); this._headers = new Dictionary(); } URLParametersPart.prototype = { _params: null, _headers: null, put: function( key, value, isHeader ) { if( isHeader == null ) isHeader = false; if( typeof(key) != "string" && typeof(value) !="string" ) return this; if(isHeader) this._params.put(key,value); else this._headers.put(key,value); }, _getRequestUriParams: function() { return this._params; }, //not applicable _getRequestHeaders: function() { return this._headers; }, //not applicable _getBody: function() { return null; } } jslibDebug('*** load: '+JS_URLPARAMETERSPART_FILE+' OK'); } // END BLOCK JS_LIB_LOADED CHECK // If jslib base library is not loaded, dump this error. else { dump("JS_BASE library not loaded:\n" + " \tTo load use: chrome://slashhack/content/resources/js/jslib/jslib.js\n" + " \tThen: include(jslib_urlparameterspart);\n\n"); }; --- NEW FILE: bodyParametersPart.js --- /*** -*- Mode: Javascript; tab-width: 2; The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is jslib code. The Initial Developer of the Original Code is jslib team. Portions created by jslib team are Copyright (C) 2000 jslib team. All Rights Reserved. Contributor(s): Rajeev J Sebastian <raj...@ya...)> (original author) *************************************/ if (typeof(JS_LIB_LOADED)=='boolean') { const JS_BODYPARAMETERSPART_FILE = "bodyParametersPart.js"; const JS_BODYPARAMETERSPART_LOADED = true; if (typeof(JS_DICTIONARY_LOADED)!='boolean') include(jslib_dictionary); function BodyParametersPart() { this._params = new Dictionary(); } BodyParametersPart.prototype = { _params: null, _name: null, setName: function( name ) { _name = name; }, put: function( key, value ) { if( typeof(key) != "string" && typeof(value) !="string" ) return this; this._params.put(key,value); }, //not applicable _getRequestUriParams: function() { return null; }, _getRequestHeaders: function() { var list = new Dictionary(); list.put("Content-type","application/x-www-form-urlencoded"); if( _name != null ) list.put("Content-disposition","form-data; name=\""+_name+"\";"); return list; }, _getBody: function() { var uri = ""; this.params.resetIterator(); while( this.params.hasMoreElements() ) { var param = this.params.getNext(); if( this.params.hasMoreElements() ) uri+= escape(param.key)+"="+escape(param.value)+"&"; else uri+= escape(param.key)+"="+escape(param.value); } var body = Components.classes["@mozilla.org/io/string-input-stream;1"]. createInstance( Components.interfaces.nsIStringInputStream ); body.setData(uri,-1); return body; } } jslibDebug('*** load: '+JS_BODYPARAMETERSPART_FILE+' OK'); } // END BLOCK JS_LIB_LOADED CHECK // If jslib base library is not loaded, dump this error. else { dump("JS_BASE library not loaded:\n" + " \tTo load use: chrome://slashhack/content/resources/js/jslib/jslib.js\n" + " \tThen: include(jslib_bodyparameterspart);\n\n"); }; |