001: /*
002: * GWT-Ext Widget Library
003: * Copyright(c) 2007-2008, GWT-Ext.
004: * licensing@gwt-ext.com
005: *
006: * http://www.gwt-ext.com/license
007: */
008:
009: package com.gwtext.client.data;
010:
011: import com.google.gwt.core.client.JavaScriptObject;
012: import com.gwtext.client.core.Connection;
013: import com.gwtext.client.util.JavaScriptObjectHelper;
014:
015: /**
016: * An implementation of {@link DataProxy} that reads a data object from the specified URL.
017: * Note that this class cannot be used to retrieve data from a domain other than the domain from which the
018: * running page was served.
019: * For cross-domain access to remote data, use an {@link ScriptTagProxy}.
020: * Be aware that to enable the browser to parse an XML document, the server must set the Content-Type header in the
021: * HTTP response to "text/xml".
022: *
023: * @author Sanjiv Jivan
024: * @see com.gwtext.client.data.ScriptTagProxy
025: * @since 0.9
026: */
027: public class HttpProxy extends DataProxy {
028:
029: /**
030: * Construct a new HttpProxy to the specified URL
031: *
032: * @param url data url, defaults to POST
033: */
034: public HttpProxy(String url) {
035: this (url, (Connection.Method) null);
036: }
037:
038: /**
039: * Construct a new HttpProxy using the specified URL and method. A Singleton Connection object, {@link com.gwtext.client.core.Ajax}, will be used to make the
040: * http request.
041: *
042: * @param url data url
043: * @param method GET or POST
044: * @see com.gwtext.client.core.Ajax
045: * @deprecated Use {@link #HttpProxy(String, com.gwtext.client.core.Connection.Method)} instead
046: */
047: public HttpProxy(String url, String method) {
048: JavaScriptObject config = JavaScriptObjectHelper.createObject();
049: JavaScriptObjectHelper.setAttribute(config, "url", url);
050: if (method != null)
051: JavaScriptObjectHelper.setAttribute(config, "method",
052: method);
053: jsObj = create(config);
054: }
055:
056: /**
057: * Construct a new HttpProxy using the specified URL and method. A Singleton Connection object, {@link com.gwtext.client.core.Ajax}, will be used to make the
058: * http request.
059: *
060: * @param url data url
061: * @param method GET or POST
062: * @see com.gwtext.client.core.Ajax
063: * @see Connection#GET
064: * @see Connection#POST
065: */
066: public HttpProxy(String url, Connection.Method method) {
067: JavaScriptObject config = JavaScriptObjectHelper.createObject();
068: JavaScriptObjectHelper.setAttribute(config, "url", url);
069: if (method != null)
070: JavaScriptObjectHelper.setAttribute(config, "method",
071: method.getMethod());
072: jsObj = create(config);
073: }
074:
075: /**
076: * Construct a new HttpProxy using the specified Connection.
077: *
078: * @param conn connection to use to make the http call
079: */
080: public HttpProxy(Connection conn) {
081: jsObj = create(conn.getJsObj());
082: }
083:
084: private native JavaScriptObject create(JavaScriptObject config) /*-{
085: return new $wnd.Ext.data.HttpProxy(config);
086: }-*/;
087:
088: /**
089: * Return the Connection object being used by this Proxy.
090: *
091: * @return the Connection object. This object may be used to subscribe to events on a finer-grained basis.
092: */
093: public Connection getConnection() {
094: return new Connection(getConnection(jsObj));
095: }
096:
097: private native JavaScriptObject getConnection(JavaScriptObject proxy) /*-{
098: return proxy.getConnection();
099: }-*/;
100: }
|