views:

323

answers:

2

Given two URLs, how can I resolve one of them against the other? I'm trying to emulate Java's URI.resolve(), which does not exist in GWT's emulation library. I've had to implement this manually, which, as you might expect has been very error-prone. Is there a GWT or Javascript library for resolving or normalizing URLs?

+1  A: 

If you want to keep it simple, create a GWT RPC to resolve urls. You can do that in 5 minutes :)

Miguel Ping
A: 

I've used Closure's Uri class to do this, which has a resolve() method. If you linked that in you could use GWT's JavaScript Native Interface (JSNI) to write a native JavaScript method -- probably something like:

native String resolve(String base, String relative) /*-{
  var baseUri = goog.Uri.parse(base);
  var relativeUri = goog.Uri.parse(relative);
  return baseUri.resolve(relativeUri).toString();
}-*/;
a paid nerd