JSVM核心类库,收集了JAVA进行JSVM开发必用技术进行归纳,在实际项目应用中直接引用相关类库即可现实JSVM相关功能!

源代码在线查看: request.js

软件大小: 44 K
上传用户: ac3698
关键词: JSVM JAVA 核心
下载地址: 免注册下载 普通下载 VIP

相关代码

				// Description:	js.net.http.Request 类
				// Author:	Changhua.Wan
				// Version:	2004.03.06.01
				
				
				_package("js.net.http");
				
				_import("js.io.Serializable");
				_import("js.net.Encoder");
				_import("js.util.Hashtable");
				_import("js.lang.IllegalArgumentException");
				
				function js.net.http.Request() {
					
					this.map=new js.util.Hashtable();
				
					this.contentType = 0;
				
					this.set = function(n,v) {this.map.put(n,v);}
					this.get = function(n) {return this.map.get(n);}
					
					this.setString = function(n,v) {
						this.set(n,String(v));
					};
					this.getString = function(n) {
						return String(this.get(n));
					};
					this.setFile = function(_name,_file) {
						if (_file.instanceOf("js.io.File")) {
							this.set(_name,_file);
						} else {
							_throw(new js.lang.IllegalArgumentException("setFile 参数不是有效的 js.io.File 对象"));
						}
					};
					this.getFile = function(_name) {
						var _file = this.get(_name);
						if (_file != null && _file.instanceOf("js.io.File")) {
							return _file;
						}
						return null;
					};
					
					this.setObject = function(n,v) {}
					this.getObject = function(n,v) {}
					
					this.clear = function() {this.map.clear();};
					this.removeParameter = function(n) {this.map.remove(n);};
					this.paramCount = function() {return this.map.size();};
					
					var separator = null;
					var getSeparator = function() {
						if (separator == null)
							separator = "----------" + Math.round(Math.random() * 0x10000000).toString(16);
						return separator;
					};
					this.getContentType = function() {
						if (this.contentType == 0)
							return "application/x-www-form-urlencoded";
						else if (this.contentType == 1)
							return 'text/xml; charset="UTF-8"';
						else if (this.contentType == 2)
							return "multipart/form-data; boundary=" + getSeparator();
						else ;
					}
					this.toData = function() {
						if (this.contentType == 0)
							return this.toUrlString();
						else if (this.contentType == 1)
							return this.toXmlString();
						else if (this.contentType == 2)
							return this.toFormData();
						else
							return this.toUrlString();
					}
					this.toXmlString = function() {
						var xmldom = new ActiveXObject("Microsoft.XMLDOM");
						xmldom.async = false;
						xmldom.loadXML("");
						var root = xmldom.documentElement;
						var em = this.map.keys();
						while(em.hasMoreElements()) {
							var key = em.nextElement();
							var itm = this.map.get(key);
							var para = xmldom.createElement("js:param");
							para.setAttribute("name", key);
							var text = xmldom.createTextNode(itm.toString());
							para.appendChild(text);
							root.appendChild(para);
						}
						return xmldom.xml;
					};
					this.toUrlString = function() {
						var str="";
						var em = this.map.keys();
						while(em.hasMoreElements()) {
							var key = em.nextElement();
							var itm = this.map.get(key);
							str += key + "=" + js.net.Encoder.encodeURIComponent(itm.toString()) + "&";
						}
						return str;		
					};
					this.toFormData = function() {
						var str = "";
						var em = this.map.keys();
						while(em.hasMoreElements()) {
							var key = em.nextElement();
							var itm = this.map.get(key);
							str += js.net.Encoder.strToHex('--' + getSeparator() + '\r\n');
							str += js.net.Encoder.strToHex('Content-Disposition: form-data; name="' + key + '"');
							if (itm.instanceOf("js.io.File")) {
								str += js.net.Encoder.strToHex('; filename="' + itm.path + '"\r\n');
								str += js.net.Encoder.strToHex('Content-Transfer-Encoding: binary\r\n\r\n');
								str += js.net.Encoder.byteToHex(itm.getData()); // TODO
							}
							else
								str += js.net.Encoder.strToHex('\r\n\r\n' + itm);
							str += js.net.Encoder.strToHex('\r\n');
						}
						str += js.net.Encoder.strToHex('--' + getSeparator() + '\r\n');
						return(js.net.Encoder.hexToByte(str));
					}
				
				}
				js.net.http.Request._extends("js.io.Serializable");
							

相关资源