phelps.net

Class URIs

public class URIs extends Object

URI-related utility classes.

Version: $Revision: 1.4 $ $Date: 2003/06/01 08:16:57 $

Method Summary
static Stringdecode(String s)
Like java.net.URLDecoder but without the hassle.
static Stringencode(String s)
Like java.net.URLEncoder but without the hassle.
static Stringfix(String s)
Fixes up alleged URIs to be acceptable to the strict parsing of java.net.URI.
static StringXXrelativeURL(URL base, URL target)
Returns target URL relative to base URL.
static URLXXrobustURL(URL url)
Takes a valid URI and tweaks it to be more likely to resolve to an actual location. => robustURI
  • "ocm"/"con"=>"com", commas in host name=>periods, single word host (assume "www.

Method Detail

decode

public static String decode(String s)
Like java.net.URLDecoder but without the hassle.

encode

public static String encode(String s)
Like java.net.URLEncoder but without the hassle. Java's URLEncode and URLDecode are too complicated. First, they are separate classes of one method each, whereas they should both be stuffed in java.net.URL or java.net.URI. Second, starting in Java 1.4, you have to explicitly supply "UTF-8" in order to meet the W3C's recommendation, which is a hassle, and you have to catch "UnsupportedEncodingException", which should never happen. Bah!

fix

public static String fix(String s)
Fixes up alleged URIs to be acceptable to the strict parsing of java.net.URI. In practice browsers have to be robust against invalid URIs.

Fixes:

XXrelativeURL

public static String XXrelativeURL(URL base, URL target)
Returns target URL relative to base URL. Like java.net.URI#relativize(URI), except actually does what you want. => URI

XXrobustURL

public static URL XXrobustURL(URL url)
Takes a valid URI and tweaks it to be more likely to resolve to an actual location. => robustURI