* Create a {@link UrlBuilder} based on this {@link Location}.
*
* @return the new builder
*/
public static UrlBuilder createUrlBuilder() {
UrlBuilder builder = new UrlBuilder();
builder.setProtocol(getProtocol());
builder.setHost(getHost());
String path = getPath();
if (path != null && path.length() > 0) {
builder.setPath(path);
}
String hash = getHash();
if (hash != null && hash.length() > 0) {
builder.setHash(hash);
}
String port = getPort();
if (port != null && port.length() > 0) {
builder.setPort(Integer.parseInt(port));
}
// Add query parameters.
Map<String, List<String>> params = getParameterMap();
for (Map.Entry<String, List<String>> entry : params.entrySet()) {
List<String> values = new ArrayList<String>(entry.getValue());
builder.setParameter(entry.getKey(),
values.toArray(new String[values.size()]));
}
return builder;
}