org.pf.net
Class UniformResourceLocator

java.lang.Object
  extended by org.pf.net.UniformResourceLocator

public class UniformResourceLocator
extends java.lang.Object

Helper class to parse and manipulate URLs in a convenient way.

Version:
1.0
Author:
Manfred Duchrow

Field Summary
static int HTTP_DEFAULT_PORT
           
static java.lang.String HTTP_SCHEME_PREFIX
          "http://"
static int HTTPS_DEFAULT_PORT
           
static java.lang.String HTTPS_SCHEME_PREFIX
          "https://"
static java.lang.String SCHEME_HOST_SEPARATOR
          "://"
static java.lang.String SCHEME_HTTP
           
static java.lang.String SCHEME_HTTPS
           
static java.lang.String SLASH
          The character '/' that is used to separate naming elements of the URL
static java.lang.String URL_PARAM_ASSIGN
          The character '=' that is used to separate name and value of query parameters
static java.lang.String URL_PARAM_SEPARATOR
          The character '&' that is used to separate consecutive query parameters from each other
static java.lang.String URL_PORT_SEPARATOR
          The character ':' that is used to separate hostname from the port
static java.lang.String URL_QUERY_SEPARATOR
          The character '?'
 
Constructor Summary
UniformResourceLocator()
          Initialize the new instance with default values.
UniformResourceLocator(java.lang.String url)
          Initialize the new instance with the given URL
 
Method Summary
 UniformResourceLocator copy()
          Creates a copy of this object.
 java.lang.String getParameter(java.lang.String name)
          Returns the value of the parameter with the given name or null.
 java.util.Enumeration getParameterNames()
          Returns the names of all parameters
 int getPort()
          Return the defined port.
 java.lang.String getQueryString()
          Returns the query string, that is everything following the '?'.
 java.lang.String getRequestURI()
          Returns the request URI
 java.lang.String getScheme()
           
 java.lang.String getServerName()
          Return the server name
 java.lang.String getServerNameAndPort()
          Returns a string containing the server name and optionally the port number, separated by a colon (':').
 boolean hasQueryParameter()
          Returns true if this URL contains at least one query parameter
 boolean isAbsolute()
          Returns true if this is an absolute URL
 boolean isDefaultPort()
          Returns true, if the port is not explicitly set which means the default port has to be used.
 boolean isRelative()
          Returns true if this is a relative URL
 void setFilename(java.lang.String filename)
          Sets the given filename to the end of the requestURI.
 void setParameter(java.lang.String name, java.lang.String value)
           
 void setPort(int newValue)
          Set the port of the URL
 void setQueryString(java.lang.String query)
           
 void setRequestURI(java.lang.String uri)
           
 void setScheme(java.lang.String scheme)
           
 void setServerName(java.lang.String name)
           
 java.lang.String toString()
          Returns the full URL including parameters as its string representation
 java.net.URI toURI()
           
 java.net.URL toURL()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SCHEME_HTTP

public static final java.lang.String SCHEME_HTTP
See Also:
Constant Field Values

SCHEME_HTTPS

public static final java.lang.String SCHEME_HTTPS
See Also:
Constant Field Values

HTTP_DEFAULT_PORT

public static final int HTTP_DEFAULT_PORT
See Also:
Constant Field Values

HTTPS_DEFAULT_PORT

public static final int HTTPS_DEFAULT_PORT
See Also:
Constant Field Values

SCHEME_HOST_SEPARATOR

public static final java.lang.String SCHEME_HOST_SEPARATOR
"://"

See Also:
Constant Field Values

HTTP_SCHEME_PREFIX

public static final java.lang.String HTTP_SCHEME_PREFIX
"http://"

See Also:
Constant Field Values

HTTPS_SCHEME_PREFIX

public static final java.lang.String HTTPS_SCHEME_PREFIX
"https://"

See Also:
Constant Field Values

URL_QUERY_SEPARATOR

public static final java.lang.String URL_QUERY_SEPARATOR
The character '?' that is used to separate the query parameters from the URL

See Also:
Constant Field Values

URL_PARAM_SEPARATOR

public static final java.lang.String URL_PARAM_SEPARATOR
The character '&' that is used to separate consecutive query parameters from each other

See Also:
Constant Field Values

URL_PARAM_ASSIGN

public static final java.lang.String URL_PARAM_ASSIGN
The character '=' that is used to separate name and value of query parameters

See Also:
Constant Field Values

URL_PORT_SEPARATOR

public static final java.lang.String URL_PORT_SEPARATOR
The character ':' that is used to separate hostname from the port

See Also:
Constant Field Values

SLASH

public static final java.lang.String SLASH
The character '/' that is used to separate naming elements of the URL

See Also:
Constant Field Values
Constructor Detail

UniformResourceLocator

public UniformResourceLocator(java.lang.String url)
                       throws java.net.MalformedURLException
Initialize the new instance with the given URL

Throws:
java.net.MalformedURLException

UniformResourceLocator

public UniformResourceLocator()
Initialize the new instance with default values.

Method Detail

hasQueryParameter

public boolean hasQueryParameter()
Returns true if this URL contains at least one query parameter


getQueryString

public java.lang.String getQueryString()
Returns the query string, that is everything following the '?'.


setQueryString

public void setQueryString(java.lang.String query)

getServerName

public java.lang.String getServerName()
Return the server name


setServerName

public void setServerName(java.lang.String name)

getPort

public int getPort()
Return the defined port. If the port is not defined (i.e zero (0)) it returns thedefault port for the current scheme.


setPort

public void setPort(int newValue)
Set the port of the URL


getRequestURI

public java.lang.String getRequestURI()
Returns the request URI


setRequestURI

public void setRequestURI(java.lang.String uri)

setFilename

public void setFilename(java.lang.String filename)
Sets the given filename to the end of the requestURI. If there is already a filename it will be replaced.


getScheme

public java.lang.String getScheme()

setScheme

public void setScheme(java.lang.String scheme)

getParameterNames

public java.util.Enumeration getParameterNames()
Returns the names of all parameters


getParameter

public java.lang.String getParameter(java.lang.String name)
Returns the value of the parameter with the given name or null.


setParameter

public void setParameter(java.lang.String name,
                         java.lang.String value)

isDefaultPort

public boolean isDefaultPort()
Returns true, if the port is not explicitly set which means the default port has to be used.


getServerNameAndPort

public java.lang.String getServerNameAndPort()
Returns a string containing the server name and optionally the port number, separated by a colon (':'). The port will NOT be appended to the server name if In all other cases the port will be appended to the server name.


copy

public UniformResourceLocator copy()
Creates a copy of this object. Changing the copy has no impact on the original object.


isRelative

public boolean isRelative()
Returns true if this is a relative URL


isAbsolute

public boolean isAbsolute()
Returns true if this is an absolute URL


toString

public java.lang.String toString()
Returns the full URL including parameters as its string representation

Overrides:
toString in class java.lang.Object

toURL

public java.net.URL toURL()

toURI

public java.net.URI toURI()