ccs.http
Class URLCoding

java.lang.Object
  extended by ccs.http.URLCoding

public class URLCoding
extends java.lang.Object

Static members of this class allow an arbitrary terminal URL fragment (ie. a complete URL, less the protocol section and some arbitrary path prefix) to be encoded as a terminal filepath fragment (ie. a filepath less some arbitrary path prefix), and vice-versa. The encoding handles charset conversion and arbitrary query strings.


Constructor Summary
URLCoding()
           
 
Method Summary
static java.lang.String asciiEscape(java.lang.String str, java.lang.String escapes)
          Perform %xy escapes on an arbitrary set of US-ASCII non-control characters (only; this is intended for awkward punctuation).
static java.lang.String filepathToUrl(java.lang.String filepath, char separator, boolean isDelimit)
          Encode the terminal fragment of a filepath into the terminal fragment of a URL.
static java.lang.String urlDecode(java.lang.String src)
          decode URL elements.
static java.lang.String urlEncode(java.lang.String src)
          encode URL elements.
static java.lang.String urlToFilepath(java.lang.String url, char separator)
          Decode the terminal fragment of a URL into a filepath. use this version if you don't have the two already separated for you.
static java.lang.String urlToFilepath(java.lang.String urlpath, java.lang.String query, char separator)
          Decode the terminal fragment of a URL path, and an optional query string, into a filepath.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

URLCoding

public URLCoding()
Method Detail

filepathToUrl

public static java.lang.String filepathToUrl(java.lang.String filepath,
                                             char separator,
                                             boolean isDelimit)
Encode the terminal fragment of a filepath into the terminal fragment of a URL.

Parameters:
filepath - The terminal fragment of the filepath (ie. the complete path less some app-specific path prefix).
separator - The filesystem separator character. '\' for Win32, '/' for pretty much anything else.
isDelimit - If true, the return is guaranteed to start with a '/'.
Returns:
the terminal fragment of the URL, ie. the complete URL less some app-specific prefix.

urlToFilepath

public static java.lang.String urlToFilepath(java.lang.String urlpath,
                                             java.lang.String query,
                                             char separator)
Decode the terminal fragment of a URL path, and an optional query string, into a filepath. If you don't have the two components already separated, use the utility wrapper which takes a single string.

Parameters:
urlpath - The path element (optionally including the authority, but not the protocol) of the URL.
query - The query string, if any; null or the empty string are permitted.
separator - The filesystem separator character. '\' for Win32, '/' for pretty much anything else.
Returns:
The terminal filepath fragment, ie. the complete filepath less some arbitrary path prefix which is up to your app. If the URL path started with a '/', the return will start with a separator character, otherwise it won't.

urlToFilepath

public static java.lang.String urlToFilepath(java.lang.String url,
                                             char separator)
Decode the terminal fragment of a URL into a filepath. use this version if you don't have the two already separated for you.

Parameters:
url - The URL fragment. Must not include the protocol, may include the authority, must include the path, may include a query string.
separator - The filesystem separator character. '\' for Win32, '/' for pretty much anything else.
Returns:
The terminal filepath fragment, ie. the complete filepath less some arbitrary path prefix which is up to your app. If the URL path started with a '/', the return will start with a separator character, otherwise it won't.

asciiEscape

public static java.lang.String asciiEscape(java.lang.String str,
                                           java.lang.String escapes)
Perform %xy escapes on an arbitrary set of US-ASCII non-control characters (only; this is intended for awkward punctuation).

Parameters:
str - The string to encode.
escapes - The set of characters which are to be escaped.
Returns:
str with escapes. If no members of escapes appear in str, str itself is returned.

urlEncode

public static java.lang.String urlEncode(java.lang.String src)
encode URL elements. This encodes URL-illegal characters into the standard %xy method. It's a wrapper around java.net.URLEncoder.

Parameters:
src - the string to encode.
Returns:
The encoded version.

urlDecode

public static java.lang.String urlDecode(java.lang.String src)
decode URL elements. This decodes URL-illegal characters which have been encoded using the standard %xy method. It's a wrapper around java.net.URLDecoder.

Parameters:
src - the string to decode.
Returns:
The decoded version.