JavaXT

URL Class

Used to parse urls, extract querystring parameters, etc. Partial implementation of the java.net.URL class. Provides a querystring parser that is not part of the java.net.URL class. Can be used to parse non-http URLs, including JDBC connection strings.

Constructors

public URL( java.net.URL url )
public URL( String url )

Methods

exists( ) returns boolean
Used to test whether the url endpoint exists. Currently only supports HTTP URLs.
getHost( ) returns String
Returns the host name or IP address found in the URL.
getKeys( ) returns java.util.HashSet
Returns a list of parameter names found in the query string.
getParameter( String key ) returns String
Returns the value of a specific variable supplied in the query string.
keyQuery string parameter name. Performs a case insensitive search for the keyword.
getParameter( String[] keys ) returns String
Returns the value of a specific variable supplied in the query string.
keysAn array containing multiple possible parameter names. Performs a case insensitive search for each parameter name and returns the value for the first match.
getParameters( ) returns java.util.HashMap
Returns a list of parameters found in query string.
getPath( ) returns String
Return the path portion of the URL, starting with a "/" character. The path does not include the query string. If no path is found, returns a null.
getPort( ) returns Integer
Returns the server port found in the URL.
getProtocol( ) returns String
Returns the protocol found in the URL.
getQueryString( ) returns String
Returns the query string in the URL, or an empty string if none exists.
parseQueryString( String query ) returns java.util.HashMap
Used to parse a url query string and create a list of name/value pairs. Note that the keys are all lowercase.
removeParameter( String key ) returns String
Used to remove a parameter from the query string
setHost( String host ) returns void
Used to update the host name or IP address found in the URL.
setParameter( String key, String value ) returns void
Used to set or update a value for a given parameter.
setParameter( String key, String value, boolean append ) returns void
Used to set or update a value for a given parameter. If append is true, the value will be added to other values for this key.
setPath( String path ) returns void
Used to update the path portion of the URL. If the supplied path starts with "./" or "../", only part of the path will be replaced. Otherwise, the entire path will be replaced.

When supplying a relative path (path starting with "./" or "../"), the url parser assumes that directories in the original path are terminated with a "/". For example:

http://www.example.com/path/
If a path is not terminated with a "/", the parser assumes that the last "/" separates a path from a file. Example:
http://www.example.com/path/file.html
For example, if the original url looks like this:
http://www.example.com/path/
If you provide a relative path like "../index.html", will yield this:
http://www.example.com/index.html

Note that if the supplied path contains a query string, the original query string will be replaced with the new one.

setPort( int port ) returns void
Used to update the port found in the URL.
setProtocol( String protocol ) returns void
Used to update the protocol found in the URL.
setQueryString( String query ) returns void
Used to update the query string in the URL.
toString( ) returns String
Returns the URL as a string.
toURL( ) returns java.net.URL
Returns a properly encoded URL for HTTP requests