Jacson

de.spieleck.net
Class URLTools

java.lang.Object
  extended byde.spieleck.net.URLTools

public class URLTools
extends java.lang.Object

XXX This is work in progress, i.e. works as long as needed so far. Part of below code has been modified from Suns JDK Sources :-( Static methods to help certain problems with urls. Some of these are rather special String functions than actually working with the datatype URL.

Author:
fsn

Field Summary
static java.lang.String defaultEncoding
          Default assumption for urlDecode (XXX should be use UTF-8?)
protected static java.util.BitSet DONT_NEED_ENC
           
protected static java.lang.String FILEPROTO
          file URL prefix.
protected static int MAXBYTESPERCHAR
           
 
Method Summary
static java.lang.String decode(java.lang.String s)
          Decode String from application/x-www-form-urlencoded to regular Java encoding.
static java.lang.String decode(java.lang.String s, java.lang.String enc)
          Decodes a application/x-www-form-urlencoded to regular Java encoding with specified URL encoding.
static java.lang.String encode(java.lang.String s)
           
static java.lang.String encodeQueryString(java.lang.String s)
          Currently a quick hack to encode certain special characters in a URL's querystring part.
static java.lang.String getFileString(java.lang.String url)
          Alternative call with String Argument
static java.lang.String getFileString(java.net.URL url)
          XXX method to obtain the absolut path of a file-url.
static java.net.URL toURL(java.lang.String fname)
          Ugly method for the hopefully most compatible way to create a URI-String from a local file identifier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultEncoding

public static java.lang.String defaultEncoding
Default assumption for urlDecode (XXX should be use UTF-8?)


FILEPROTO

protected static final java.lang.String FILEPROTO
file URL prefix.

See Also:
Constant Field Values

MAXBYTESPERCHAR

protected static final int MAXBYTESPERCHAR
See Also:
Constant Field Values

DONT_NEED_ENC

protected static final java.util.BitSet DONT_NEED_ENC
Method Detail

encode

public static java.lang.String encode(java.lang.String s)

encodeQueryString

public static java.lang.String encodeQueryString(java.lang.String s)
Currently a quick hack to encode certain special characters in a URL's querystring part. XXX Read the RFC's and do it the right way.

Parameters:
s - String to be encoded.
Returns:
"encoded" String (currently blank replaced by '+')

toURL

public static java.net.URL toURL(java.lang.String fname)
                          throws java.net.MalformedURLException
Ugly method for the hopefully most compatible way to create a URI-String from a local file identifier. Is similar to java.io.File.toURL in JDK1.2+

Parameters:
fname - File name
Returns:
a url for the given file
Throws:
java.net.MalformedURLException

getFileString

public static java.lang.String getFileString(java.net.URL url)
XXX method to obtain the absolut path of a file-url. this method is necessary due to a missing constructor File(URL url) in java.io.File (JDK1.3.1)

Parameters:
url - the URL to find a file for
Returns:
the file name for the file as a string.

getFileString

public static java.lang.String getFileString(java.lang.String url)
Alternative call with String Argument

Parameters:
url - the URL to find a file for in String form
Returns:
the file name for the file as a string.

decode

public static java.lang.String decode(java.lang.String s)
Decode String from application/x-www-form-urlencoded to regular Java encoding.


decode

public static java.lang.String decode(java.lang.String s,
                                      java.lang.String enc)
                               throws java.io.UnsupportedEncodingException
Decodes a application/x-www-form-urlencoded to regular Java encoding with specified URL encoding.

Parameters:
s - the String to decode
enc - The name of a supported encoding.
Returns:
the newly decoded String
Throws:
java.io.UnsupportedEncodingException - If the named encoding is not supported

Spieleck

Copyleft 2002 spieleck.de.