public void onSuccess(JavaScriptObject jso) { if (jso == null) { callback.onError(new ResourceException( ExternalTextResourcePrototype.this, "eval() returned null")); return; } // Populate the TextResponse cache array final String resourceText = extractString(jso, index); cache[index] = new TextResource() { public String getName() { return name; } public String getText() { return resourceText; } }; // Finish by invoking the callback callback.onSuccess(cache[index]); } }
/** * Possibly fire off an HTTPRequest for the text resource. */ @SuppressIsTrustedResourceUriCastCheck public void getText(ResourceCallback<TextResource> callback) throws ResourceException { // If we've already parsed the JSON bundle, short-circuit. if (cache[index] != null) { callback.onSuccess(cache[index]); return; } if (md5Hash != null) { // If we have an md5Hash, we should be using JSONP JsonpRequestBuilder rb = new JsonpRequestBuilder(); rb.setPredeterminedId(md5Hash); rb.requestObject(url.asString(), new ETRCallback(callback)); } else { RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url.asString()); try { rb.sendRequest("", new ETRCallback(callback)); } catch (RequestException e) { throw new ResourceException(this, "Unable to initiate request for external resource", e); } } } }
public void onFailure(Throwable exception) { callback.onError(new ResourceException( ExternalTextResourcePrototype.this, "Unable to retrieve external resource", exception)); }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Exception { Class<?> returnType = method.getReturnType(); if (returnType == String.class) { return name; } else if (returnType == SafeHtml.class) { return SafeHtmlUtils.fromTrustedString(name); } else if (returnType == SafeUri.class) { return UriUtils.fromTrustedString(name); } else if (returnType == boolean.class) { return false; } else if (returnType == int.class) { return 0; } else if (method.getParameterTypes()[0] == ResourceCallback.class) { // Read the underlying resource type out of the generic parameter // in the method's argument Class<?> resourceType = (Class<?>) ((ParameterizedType) args[0].getClass().getGenericInterfaces()[0]) .getActualTypeArguments()[0]; ((ResourceCallback<ResourcePrototype>) args[0]).onSuccess( (ResourcePrototype) createFakeResource(resourceType, name)); return null; } else { throw new IllegalArgumentException( "Unexpected return type for method " + method.getName()); } } });
public void onFailure(Throwable exception) { callback.onError(new ResourceException( ExternalTextResourcePrototype.this, "Unable to retrieve external resource", exception)); }
public void onSuccess(JavaScriptObject jso) { if (jso == null) { callback.onError(new ResourceException( ExternalTextResourcePrototype.this, "eval() returned null")); return; } // Populate the TextResponse cache array final String resourceText = extractString(jso, index); cache[index] = new TextResource() { public String getName() { return name; } public String getText() { return resourceText; } }; // Finish by invoking the callback callback.onSuccess(cache[index]); } }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Exception { Class<?> returnType = method.getReturnType(); if (returnType == String.class) { return name; } else if (returnType == SafeHtml.class) { return SafeHtmlUtils.fromTrustedString(name); } else if (returnType == SafeUri.class) { return UriUtils.fromTrustedString(name); } else if (returnType == boolean.class) { return false; } else if (returnType == int.class) { return 0; } else if (method.getParameterTypes()[0] == ResourceCallback.class) { // Read the underlying resource type out of the generic parameter // in the method's argument Class<?> resourceType = (Class<?>) ((ParameterizedType) args[0].getClass().getGenericInterfaces()[0]) .getActualTypeArguments()[0]; ((ResourceCallback<ResourcePrototype>) args[0]).onSuccess( (ResourcePrototype) createFakeResource(resourceType, name)); return null; } else { throw new IllegalArgumentException( "Unexpected return type for method " + method.getName()); } } });
public void onFailure(Throwable exception) { callback.onError(new ResourceException( ExternalTextResourcePrototype.this, "Unable to retrieve external resource", exception)); }
public void onSuccess(JavaScriptObject jso) { if (jso == null) { callback.onError(new ResourceException( ExternalTextResourcePrototype.this, "eval() returned null")); return; } // Populate the TextResponse cache array final String resourceText = extractString(jso, index); cache[index] = new TextResource() { public String getName() { return name; } public String getText() { return resourceText; } }; // Finish by invoking the callback callback.onSuccess(cache[index]); } }
/** * Possibly fire off an HTTPRequest for the SVG resource. * @param callback The request callback */ public void getSvg(ResourceCallback<SVGResource> callback) throws ResourceException { // If we've already parsed the JSON bundle, short-circuit. if (cache[index] != null) { callback.onSuccess(cache[index]); return; } // Otherwise, fire an HTTP request. RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url); try { rb.sendRequest("", new ESRCallback(callback)); } catch (RequestException e) { throw new ResourceException(this, "Unable to initiate request for external resource", e); } } }
public void onError(Request request, Throwable exception) { callback.onError(new ResourceException( ExternalSVGResourcePrototype.this, "Unable to retrieve external resource", exception)); }
/** * Possibly fire off an HTTPRequest for the SVG resource. * @param callback The request callback */ public void getSvg(ResourceCallback<SVGResource> callback) throws ResourceException { // If we've already parsed the JSON bundle, short-circuit. if (cache[index] != null) { callback.onSuccess(cache[index]); return; } // Otherwise, fire an HTTP request. RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url); try { rb.sendRequest("", new ESRCallback(callback)); } catch (RequestException e) { throw new ResourceException(this, "Unable to initiate request for external resource", e); } } }
public void onError(Request request, Throwable exception) { callback.onError(new ResourceException( ExternalSVGResourcePrototype.this, "Unable to retrieve external resource", exception)); }
/** * Possibly fire off an HTTPRequest for the text resource. */ public void getText(ResourceCallback<TextResource> callback) throws ResourceException { // If we've already parsed the JSON bundle, short-circuit. if (cache[index] != null) { callback.onSuccess(cache[index]); return; } if (md5Hash != null) { // If we have an md5Hash, we should be using JSONP JsonpRequestBuilder rb = new JsonpRequestBuilder(); rb.setPredeterminedId(md5Hash); rb.requestObject(url.asString(), new ETRCallback(callback)); } else { RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url.asString()); try { rb.sendRequest("", new ETRCallback(callback)); } catch (RequestException e) { throw new ResourceException(this, "Unable to initiate request for external resource", e); } } } }
/** * Possibly fire off an HTTPRequest for the text resource. */ public void getText(ResourceCallback<TextResource> callback) throws ResourceException { // If we've already parsed the JSON bundle, short-circuit. if (cache[index] != null) { callback.onSuccess(cache[index]); return; } if (md5Hash != null) { // If we have an md5Hash, we should be using JSONP JsonpRequestBuilder rb = new JsonpRequestBuilder(); rb.setPredeterminedId(md5Hash); rb.requestObject(url.asString(), new ETRCallback(callback)); } else { RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url.asString()); try { rb.sendRequest("", new ETRCallback(callback)); } catch (RequestException e) { throw new ResourceException(this, "Unable to initiate request for external resource", e); } } } }