diff options
Diffstat (limited to 'netx/net/sourceforge')
-rw-r--r-- | netx/net/sourceforge/jnlp/cache/ResourceUrlCreator.java | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/netx/net/sourceforge/jnlp/cache/ResourceUrlCreator.java b/netx/net/sourceforge/jnlp/cache/ResourceUrlCreator.java index 0da5466..fad2d00 100644 --- a/netx/net/sourceforge/jnlp/cache/ResourceUrlCreator.java +++ b/netx/net/sourceforge/jnlp/cache/ResourceUrlCreator.java @@ -41,8 +41,11 @@ import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.net.URLDecoder; +import java.net.URLEncoder; import java.util.LinkedList; import java.util.List; +import java.io.UnsupportedEncodingException; import net.sourceforge.jnlp.DownloadOptions; @@ -91,7 +94,7 @@ public class ResourceUrlCreator { } } - url = getVersionedUrl(resource); + url = getVersionedUrl(); urls.add(url); urls.add(resource.getLocation()); @@ -148,29 +151,47 @@ public class ResourceUrlCreator { } /** - * Returns the URL for a resource, including the resource's version number in the query string - * - * @param resource the resource to get the url for + * Returns the URL for this resource, including the resource's version number in the query string */ - protected URL getVersionedUrl(Resource resource) { + protected URL getVersionedUrl() { URL resourceUrl = resource.getLocation(); - try { - String query = resourceUrl.getQuery(); // returns null if there was no query string - if (resource.requestVersion != null && resource.requestVersion.isVersionId()) { - if (query == null) { - query = ""; - } else { - query += "&"; - } - query += "version-id=" + resource.requestVersion; + String protocol = uriPartToString(resourceUrl.getProtocol()) + "://"; + String userInfo = uriPartToString(resourceUrl.getUserInfo()); + if (!userInfo.isEmpty()) { + userInfo += "@"; + } + String host = uriPartToString(resourceUrl.getHost()); + String port; + if (resourceUrl.getPort() == -1) { + port = ""; + } else { + port = ":" + String.valueOf(resourceUrl.getPort()); + } + String path = uriPartToString(resourceUrl.getPath()); + String query = uriPartToString(resourceUrl.getQuery()); + if (!query.isEmpty()) { + query = "?" + query; + } + if (resource.requestVersion != null && resource.requestVersion.isVersionId()) { + if (!query.isEmpty()) { + query += "&"; + } else { + query = "?" + query; } - URI uri = new URI(resourceUrl.getProtocol(), resourceUrl.getUserInfo(), resourceUrl.getHost(), resourceUrl.getPort(), resourceUrl.getPath(), query, null); - return uri.toURL(); + query += "version-id=" + resource.requestVersion; + } + try { + URL url = new URL(protocol + userInfo + host + port + path + query); + return url; } catch (MalformedURLException e) { return resourceUrl; - } catch (URISyntaxException e) { - return resourceUrl; } } + private static String uriPartToString(String part) { + if (part == null) + return ""; + return part; + } + } |