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

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

Public Methods

exists( ) returns boolean
Used to test whether the url endpoint exists. Currently only supports HTTP URLs.
setParameter( String key, String value, boolean append ) returns void
Used to set or update a value for a given parameter in the query string. If append is true, the value will be added to other values for this key.
setParameter( String key, String value ) returns void
Used to set or update a value for a given parameter.
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 LinkedHashMap<String, List<String>>
Returns a list of parameters found in query string.
getExtendedParameters( ) returns LinkedHashMap<String, List<String>>
Returns a list of extended parameters (e.g. jdbc params) that are not part of a standard url
removeParameter( String key ) returns String
Used to remove a parameter from the query string
getHost( ) returns String
Returns the host name or IP address found in the URL.
setHost( String host ) returns void
Used to update the host name or IP address found in the URL.
getPort( ) returns Integer
Returns the server port found in the URL.
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.
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.
setQueryString( String query ) returns void
Used to update the query string in the URL.
getKeys( ) returns HashSet<String>
Returns a list of parameter names found in the 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.
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.

toString( ) returns String
Returns the URL as a string.
toURL( ) returns java.net.URL
Returns a properly encoded URL for HTTP requests

Static Methods

parseQueryString( String query ) returns LinkedHashMap<String, List<String>>
Used to parse a url query string and create a list of name/value pairs.
parseJDBCParams( String params ) returns LinkedHashMap<String, List<String>>
Used to parse a JDBC parameter strings and return a list of name/value pairs.
getParameter( String key, HashMap<String, List<String>> parameters ) returns List<String>
setParameter( String key, List<String> values, HashMap<String, List<String>> parameters ) returns void
removeParameter( String key, HashMap<String, List<String>> parameters ) returns List<String>