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 String | decode(String s)
Like java.net.URLDecoder but without the hassle. |
static String | encode(String s)
Like java.net.URLEncoder but without the hassle.
|
static String | fix(String s)
Fixes up alleged URIs to be acceptable to the strict parsing of java.net.URI.
|
static URL | toURL(URI uri)
With URI#toURL(URI), safe interconversion between URI and URL, working around Java bugs.
|
static String | XXrelativeURL(URL base, URL target)
Returns target URL relative to base URL.
|
static URL | XXrobustURL(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.
|
public static String decode(String s)
Like java.net.URLDecoder but without the hassle.
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!
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:
- trim spaces from both ends, escape invalid characters (space, %, ...), ....
- convert Netscape syntax for Windows drive letters to Java syntax
public static URL toURL(URI uri)
With URI#toURL(URI), safe interconversion between URI and URL, working around Java bugs.
- URI.toURL() "jar:" protocol (#4677045)
- Java divergence from URL specification that allows spaces and other characters,
and so can't distinguish proper URL with escaped characters in path!
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
public static URL XXrobustURL(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..com")
- expands shorthand: for example, "www.cs/~phelps" => "http://www.cs.berkeley.edu/~phelps/"
- [Signature split off by RobustHyperlink behavior.]
- convert the various conventions for MS-DOS drive letters (from Netscape and so on) into Java's representation (
file://c:/...
).