info.aduna.net
Class UrlUtil

java.lang.Object
  extended by info.aduna.net.UrlUtil

public class UrlUtil
extends Object

Utility methods related to URLs, network connections, etc.


Constructor Summary
UrlUtil()
           
 
Method Summary
static String buildQueryString(Map<String,String> keyValuePairs)
          Builds a query string from the provided key-value-pairs.
static URL normalizeURL(URL url)
          Normalizes a URL.
static URL trimToDirectory(URL url)
          Trims a URL to the directory it refers.
static boolean urlsEqual(URL url1, URL url2)
          Checks whether two URLs are equal.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UrlUtil

public UrlUtil()
Method Detail

normalizeURL

public static URL normalizeURL(URL url)
Normalizes a URL. The following steps are taken to normalize a URL:


urlsEqual

public static boolean urlsEqual(URL url1,
                                URL url2)
Checks whether two URLs are equal. This is an alternative implementation for URL.equals(Object) which compares hosts by resolving their IP-addresses, which doesn't work when virtual hosts are involved. Also, this method does not take into account that the order of query parameters is irrelevant. This method fixes these issues by checking that:


buildQueryString

public static String buildQueryString(Map<String,String> keyValuePairs)
Builds a query string from the provided key-value-pairs. All spaces are substituted by '+' characters, and all non US-ASCII characters are escaped to hexadecimal notation (%xx).


trimToDirectory

public static URL trimToDirectory(URL url)
Trims a URL to the directory it refers. This means that everything after the refered directory is removed from the URL. For example, the URL http://foo.com/a/b/c/index.jsp?a=b#c will be trimmed to http://foo.com/a/b/c/, and the URL http://foo.com/a/b will be trimmed to http://foo.com/a/.

Throws:
MalformedURLException - If trimming the URL resulted in a malformed URL.


Copyright © 1997-2008 Aduna. All Rights Reserved.