diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/api/ActionContext.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/api/ActionContext.java index 2b40954eec..5533313650 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/api/ActionContext.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/api/ActionContext.java @@ -157,6 +157,14 @@ public class ActionContext extends JavaScriptObject { api.get(wrap(cb)); } + /** + * The same as {@link #get(RestApi, JavaScriptObject)} but without converting + * a {@link NativeString} result to String. + */ + static final void getRaw(RestApi api, final JavaScriptObject cb) { + api.get(wrapRaw(cb)); + } + static final void post(RestApi api, JavaScriptObject in, JavaScriptObject cb) { if (NativeString.is(in)) { post(api, ((NativeString) in).asString(), cb); @@ -165,14 +173,42 @@ public class ActionContext extends JavaScriptObject { } } + /** + * The same as {@link #post(RestApi, JavaScriptObject, JavaScriptObject)} but + * without converting a {@link NativeString} result to String. + */ + static final void postRaw(RestApi api, JavaScriptObject in, JavaScriptObject cb) { + if (NativeString.is(in)) { + postRaw(api, ((NativeString) in).asString(), cb); + } else { + api.post(in, wrapRaw(cb)); + } + } + static final void post(RestApi api, String in, JavaScriptObject cb) { api.post(in, wrap(cb)); } + /** + * The same as {@link #post(RestApi, String, JavaScriptObject)} but without + * converting a {@link NativeString} result to String. + */ + static final void postRaw(RestApi api, String in, JavaScriptObject cb) { + api.post(in, wrapRaw(cb)); + } + static final void put(RestApi api, JavaScriptObject cb) { api.put(wrap(cb)); } + /** + * The same as {@link #put(RestApi, JavaScriptObject)} but without converting + * a {@link NativeString} result to String. + */ + static final void putRaw(RestApi api, JavaScriptObject cb) { + api.put(wrapRaw(cb)); + } + static final void put(RestApi api, JavaScriptObject in, JavaScriptObject cb) { if (NativeString.is(in)) { put(api, ((NativeString) in).asString(), cb); @@ -181,14 +217,42 @@ public class ActionContext extends JavaScriptObject { } } + /** + * The same as {@link #put(RestApi, JavaScriptObject, JavaScriptObject)} but + * without converting a {@link NativeString} result to String. + */ + static final void putRaw(RestApi api, JavaScriptObject in, JavaScriptObject cb) { + if (NativeString.is(in)) { + putRaw(api, ((NativeString) in).asString(), cb); + } else { + api.put(in, wrapRaw(cb)); + } + } + static final void put(RestApi api, String in, JavaScriptObject cb) { api.put(in, wrap(cb)); } + /** + * The same as {@link #put(RestApi, String, JavaScriptObject)} but without + * converting a {@link NativeString} result to String. + */ + static final void putRaw(RestApi api, String in, JavaScriptObject cb) { + api.put(in, wrapRaw(cb)); + } + static final void delete(RestApi api, JavaScriptObject cb) { api.delete(wrap(cb)); } + /** + * The same as {@link #delete(RestApi, JavaScriptObject)} but without + * converting a {@link NativeString} result to String. + */ + static final void deleteRaw(RestApi api, JavaScriptObject cb) { + api.delete(wrapRaw(cb)); + } + private static GerritCallback wrap(final JavaScriptObject cb) { return new GerritCallback() { @Override @@ -202,4 +266,13 @@ public class ActionContext extends JavaScriptObject { } }; } + + private static GerritCallback wrapRaw(final JavaScriptObject cb) { + return new GerritCallback() { + @Override + public void onSuccess(JavaScriptObject result) { + ApiGlue.invoke(cb, result); + } + }; + } } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/api/ApiGlue.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/api/ApiGlue.java index b52efe8565..e4a5446f74 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/api/ApiGlue.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/api/ApiGlue.java @@ -102,6 +102,12 @@ public class ApiGlue { Lcom/google/gwt/core/client/JavaScriptObject;) (this._api(u), b); }, + get_raw: function(u,b) { + @com.google.gerrit.client.api.ActionContext::getRaw( + Lcom/google/gerrit/client/rpc/RestApi; + Lcom/google/gwt/core/client/JavaScriptObject;) + (this._api(u), b); + }, post: function(u,i,b) { if (typeof i == 'string') { @com.google.gerrit.client.api.ActionContext::post( @@ -117,6 +123,21 @@ public class ApiGlue { (this._api(u), i, b); } }, + post_raw: function(u,i,b) { + if (typeof i == 'string') { + @com.google.gerrit.client.api.ActionContext::postRaw( + Lcom/google/gerrit/client/rpc/RestApi; + Ljava/lang/String; + Lcom/google/gwt/core/client/JavaScriptObject;) + (this._api(u), i, b); + } else { + @com.google.gerrit.client.api.ActionContext::postRaw( + Lcom/google/gerrit/client/rpc/RestApi; + Lcom/google/gwt/core/client/JavaScriptObject; + Lcom/google/gwt/core/client/JavaScriptObject;) + (this._api(u), i, b); + } + }, put: function(u,i,b) { if (b) { if (typeof i == 'string') { @@ -139,6 +160,28 @@ public class ApiGlue { (this._api(u), i); } }, + put_raw: function(u,i,b) { + if (b) { + if (typeof i == 'string') { + @com.google.gerrit.client.api.ActionContext::putRaw( + Lcom/google/gerrit/client/rpc/RestApi; + Ljava/lang/String; + Lcom/google/gwt/core/client/JavaScriptObject;) + (this._api(u), i, b); + } else { + @com.google.gerrit.client.api.ActionContext::putRaw( + Lcom/google/gerrit/client/rpc/RestApi; + Lcom/google/gwt/core/client/JavaScriptObject; + Lcom/google/gwt/core/client/JavaScriptObject;) + (this._api(u), i, b); + } + } else { + @com.google.gerrit.client.api.ActionContext::putRaw( + Lcom/google/gerrit/client/rpc/RestApi; + Lcom/google/gwt/core/client/JavaScriptObject;) + (this._api(u), i); + } + }, 'delete': function(u,b) { @com.google.gerrit.client.api.ActionContext::delete( Lcom/google/gerrit/client/rpc/RestApi; @@ -151,6 +194,12 @@ public class ApiGlue { Lcom/google/gwt/core/client/JavaScriptObject;) (this._api(u), b); }, + del_raw: function(u,b) { + @com.google.gerrit.client.api.ActionContext::deleteRaw( + Lcom/google/gerrit/client/rpc/RestApi; + Lcom/google/gwt/core/client/JavaScriptObject;) + (this._api(u), b); + }, }; }-*/; diff --git a/gerrit-plugin-gwtui/src/main/java/com/google/gerrit/plugin/client/rpc/RestApi.java b/gerrit-plugin-gwtui/src/main/java/com/google/gerrit/plugin/client/rpc/RestApi.java index 8b2a6b8786..8d408fb261 100644 --- a/gerrit-plugin-gwtui/src/main/java/com/google/gerrit/plugin/client/rpc/RestApi.java +++ b/gerrit-plugin-gwtui/src/main/java/com/google/gerrit/plugin/client/rpc/RestApi.java @@ -110,7 +110,7 @@ public class RestApi { } private static native void get(String p, JavaScriptObject r) - /*-{ $wnd.Gerrit.get(p, r) }-*/; + /*-{ $wnd.Gerrit.get_raw(p, r) }-*/; public void put(AsyncCallback cb) { @@ -118,7 +118,7 @@ public class RestApi { } private static native void put(String p, JavaScriptObject r) - /*-{ $wnd.Gerrit.put(p, r) }-*/; + /*-{ $wnd.Gerrit.put_raw(p, r) }-*/; public void put(String content, AsyncCallback cb) { @@ -127,7 +127,7 @@ public class RestApi { private static native void put(String p, String c, JavaScriptObject r) - /*-{ $wnd.Gerrit.put(p, c, r) }-*/; + /*-{ $wnd.Gerrit.put_raw(p, c, r) }-*/; public void put(JavaScriptObject content, AsyncCallback cb) { @@ -136,7 +136,7 @@ public class RestApi { private static native void put(String p, JavaScriptObject c, JavaScriptObject r) - /*-{ $wnd.Gerrit.put(p, c, r) }-*/; + /*-{ $wnd.Gerrit.put_raw(p, c, r) }-*/; public void post(String content, AsyncCallback cb) { @@ -145,7 +145,7 @@ public class RestApi { private static native void post(String p, String c, JavaScriptObject r) - /*-{ $wnd.Gerrit.post(p, c, r) }-*/; + /*-{ $wnd.Gerrit.post_raw(p, c, r) }-*/; public void post(JavaScriptObject content, AsyncCallback cb) { @@ -154,14 +154,14 @@ public class RestApi { private static native void post(String p, JavaScriptObject c, JavaScriptObject r) - /*-{ $wnd.Gerrit.post(p, c, r) }-*/; + /*-{ $wnd.Gerrit.post_raw(p, c, r) }-*/; public void delete(AsyncCallback cb) { delete(path(), wrap(cb)); } private static native void delete(String p, JavaScriptObject r) - /*-{ $wnd.Gerrit.del(p, r) }-*/; + /*-{ $wnd.Gerrit.del_raw(p, r) }-*/; private static native JavaScriptObject wrap(AsyncCallback b) /*-{