1 16 package com.google.gwt.http.client; 17 18 import com.google.gwt.core.client.JavaScriptObject; 19 20 24 final class XMLHTTPRequest { 25 26 public static final int UNITIALIZED = 0; 27 public static final int OPEN = 1; 28 public static final int SENT = 2; 29 public static final int RECEIVING = 3; 30 public static final int LOADED = 4; 31 32 39 static native void abort(JavaScriptObject xmlHttpRequest) ; 44 45 static native String getAllResponseHeaders(JavaScriptObject xmlHttpRequest) ; 48 49 69 static native String getBrowserSpecificFailure( 70 JavaScriptObject xmlHttpRequest) ; 85 86 93 static Header[] getHeaders(JavaScriptObject xmlHttpRequest) { 94 String allHeaders = getAllResponseHeaders(xmlHttpRequest); 95 String [] unparsedHeaders = allHeaders.split("\n"); 96 Header[] parsedHeaders = new Header[unparsedHeaders.length]; 97 98 for (int i = 0, n = unparsedHeaders.length; i < n; ++i) { 99 String unparsedHeader = unparsedHeaders[i]; 100 101 if (unparsedHeader.length() == 0) { 102 continue; 103 } 104 105 int endOfNameIdx = unparsedHeader.indexOf(':'); 106 if (endOfNameIdx < 0) { 107 continue; 108 } 109 110 final String name = unparsedHeader.substring(0, endOfNameIdx).trim(); 111 final String value = unparsedHeader.substring(endOfNameIdx + 1).trim(); 112 Header header = new Header() { 113 public String getName() { 114 return name; 115 } 116 117 public String getValue() { 118 return value; 119 } 120 121 public String toString() { 122 return name + " : " + value; 123 } 124 }; 125 126 parsedHeaders[i] = header; 127 } 128 129 return parsedHeaders; 130 } 131 132 static native int getReadyState(JavaScriptObject xmlHttpRequest) ; 135 136 static native String getResponseHeader(JavaScriptObject xmlHttpRequest, 137 String header) ; 146 147 static native String getResponseText(JavaScriptObject xmlHttpRequest) ; 150 151 static native int getStatusCode(JavaScriptObject xmlHttpRequest) ; 154 155 static native String getStatusText(JavaScriptObject xmlHttpRequest) ; 158 159 static boolean isResponseReady(JavaScriptObject xmlHttpRequest) { 160 return getReadyState(xmlHttpRequest) == LOADED; 161 } 162 163 176 static native String open(JavaScriptObject xmlHttpRequest, String httpMethod, 177 String url, boolean async, String user, String password) ; 186 187 191 static native String send(JavaScriptObject xmlHttpRequest, 192 Request httpRequest, String requestData, RequestCallback callback) ; 211 212 static native String setRequestHeader(JavaScriptObject xmlHttpRequest, 213 String header, String value) ; 222 223 private XMLHTTPRequest() { 224 } 225 } 226 | Popular Tags |