public class HttpRequestXmlLoader implements AsyncXmlLoader {
@Override
public void loadResource(final String resourceUrl, final AsyncXmlLoaderCallback callback) {
String currentResourceUrl = resourceUrl + ((resourceUrl.indexOf("?") == -1) ? ("?ts=" + System.currentTimeMillis()) : ("&ts=" + + System.currentTimeMillis()));
RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, currentResourceUrl);
requestBuilder.setCallback(new RequestCallback() {
public void onError(Request request, Throwable exception) {
callback.onError(resourceUrl, exception);
}
private void onSuccess(Request request, Response response) {
SVGParserImpl impl = GWT.create(SVGParserImpl.class);
Element root = impl.parse(response.getText());
callback.onSuccess(resourceUrl, root);
}
public void onResponseReceived(Request request, Response response) {
if (response.getStatusCode() == Response.SC_OK) {
onSuccess(request, response);
} else {
onError(request, null);
}
}
});
try {
requestBuilder.send();
} catch (RequestException e) {
GWT.log("Cannot fetch " + resourceUrl, e);
}
}