URI Holder.
This class assists with the decoding and encoding or HTTP URI's.
It differs from the java.net.URL class as it does not provide
communications ability, but it does assist with query string
formatting.
ISO_8859_1 encoding is used by default for % encoded characters. This
may be overridden with the org.mortbay.util.URI.charset system property.
addPaths
public static String addPaths(String p1,
String p2)
Add two URI path segments.
Handles null and empty paths, path and query params (eg ?a=b or
;JSESSIONID=xxx) and avoids duplicate '/'
p1
- URI path segmentp2
- URI path segment
- Legally combined path segments.
canonicalPath
public static String canonicalPath(String path)
Convert a path to a cananonical form.
All instances of "." and ".." are factored out. Null is returned
if the path tries to .. above it's root.
clearParameters
public void clearParameters()
Clear the URI _parameters.
clone
public Object clone()
throws CloneNotSupportedException
Clone URI.
decodePath
public static String decodePath(String path)
encodePath
public static String encodePath(String path)
Encode a URI path.
This is the same encoding offered by URLEncoder, except that
the '/' character is not encoded.
path
- The path the encode
encodePath
public static StringBuffer encodePath(StringBuffer buf,
String path)
Encode a URI path.
buf
- StringBuffer to encode path into (or null)path
- The path the encode
- The StringBuffer or null if no substitutions required.
encodeString
public static StringBuffer encodeString(StringBuffer buf,
String path,
String encode)
Encode a URI path.
buf
- StringBuffer to encode path into (or null)path
- The path the encodeencode
- String of characters to encode. % is always encoded.
- The StringBuffer or null if no substitutions required.
get
public String get(String name)
Get named value
getEncodedPath
public String getEncodedPath()
Get the encoded uri path.
getHost
public String getHost()
Get the uri host.
getParameterNames
public Set getParameterNames()
Get the uri query _parameters names.
- Unmodifiable set of URI query _parameters names
getParameters
public MultiMap getParameters()
Get the uri query _parameters.
- the URI query _parameters
getPath
public String getPath()
Get the uri path.
getPort
public int getPort()
Get the uri port.
getQuery
public String getQuery()
Get the uri query String.
getScheme
public String getScheme()
Get the uri scheme.
getUnmodifiableParameters
public Map getUnmodifiableParameters()
Get the uri query _parameters.
- the URI query _parameters in an unmodifiable map.
getValues
public List getValues(String name)
Get named multiple values.
name
- The parameter name
- Umodifiable list of values or null
hasScheme
public static boolean hasScheme(String uri)
- True if the uri has a scheme
isAbsolute
public boolean isAbsolute()
Is the URI an absolute URL?
- True if the URI has a scheme or host
parentPath
public static String parentPath(String p)
Return the parent Path.
Treat a URI like a directory path and return the parent directory.
put
public void put(Map values)
Add dictionary to the uri query _parameters.
put
public Object put(Object name,
Object value)
Add name value pair to the uri query _parameters.
name
- name of valuevalue
- The value, which may be a multi valued list or
String array.
put
public void put(String encoded)
Add encoded _parameters.
encoded
- A HTTP encoded string of _parameters: e.g.. "a=1&b=2"
putParametersTo
public void putParametersTo(MultiMap map)
Add the uri query _parameters to a MultiMap
remove
public void remove(String name)
Remove named value
setHost
public void setHost(String host)
Set the uri host.
setPath
public void setPath(String path)
Set the uri path.
setPort
public void setPort(int port)
Set the uri port.
A port of 0 implies use the default port.
setQuery
public void setQuery(String query)
Set the uri query String.
query
- the URI query string
setScheme
public void setScheme(String scheme)
Set the uri scheme.
setURI
public void setURI(String uri)
throws IllegalArgumentException
stripPath
public static String stripPath(String path)
Strip parameters from a path.
Return path upto any semicolon parameters.
toString
public String toString()