org.ws4d.java.types
Class URI

java.lang.Object
  extended by org.ws4d.java.types.URI
Direct Known Subclasses:
AttributedURI

public class URI
extends java.lang.Object

This class implements the Uniform Resource Identifier RFC3986. All constructors which use strings a representation of URIs or paths expects encoded strings, if any not allowed characters - specified by the RFC3986 - must be part of this Strings.


Field Summary
static URI EMPTY_URI
           
static java.lang.String URN_SCHEMA_PREFIX
           
 
Constructor Summary
URI(java.lang.String uri)
          Constructor.
URI(java.lang.String baseURI, java.lang.String path)
          Creates an URI from a base URI as String and a path as String which is regarded to be relative to the given base URI.
URI(java.lang.String absoluteURI, URI baseURI)
          Creates an URI from String.
URI(URI baseURI, java.lang.String path)
          Creates an URI from a base URI and a path as which is regarded to be relative to the given base URI.
URI(URI baseURI, URI uri)
          Constructor.
 
Method Summary
static URI absolutize(URI baseUri, java.lang.String newUri)
          TODO
 java.lang.Object clone()
          Creates a clone of this URI.
 boolean equals(java.lang.Object obj)
           
 boolean equalsWsdRfc3986(URI other)
          Case-insensitive comparison of this with the given uri.
 java.lang.String getFragment()
          Returns the fragment defined in the URI. e.g. the fragment behind the "#".
 java.lang.String getHost()
          Returns the host defined in the URI.
 java.lang.String getHostWithPort()
          Returns a String containing the host and the port defined in the URI. e.g. host:port.
 java.lang.String getPassword()
          Returns the password defined in the URI.
 java.lang.String getPath()
          Returns the path defined in the URI.
 java.lang.String getPath(int deepness)
          Returns the leading part of the path, calculated by the path deepness.
 int getPathDeepness()
          Returns the deepness of the path inside this URI.
 int getPort()
          Returns the port for the host part of this URI.
 java.lang.String getQuery()
          Returns the query defined in the URI. e.g. the part behind the "?".
 java.lang.String getSchema()
          Returns the schema defined in the URI.
 java.lang.String getUser()
          Returns the user defined in the URI.
 int hashCode()
           
 boolean isIPv6Address()
           
static boolean isIPv6Address(java.lang.String address)
          Check for IPv6 address.
 boolean isRelativeReference()
          Returns true if this is a relative URI, false if the base part is set.
 boolean isURN()
          Returns true if this URI has the URN schema, false otherwise.
 boolean isValid()
          Returns true, if the URI seams to be correct and there were no problems while parsing it.
 void setFragment(java.lang.String fragment)
           
 void setFragmentEncoded(java.lang.String encodedFragment)
           
 void setQuery(java.lang.String query)
           
 void setQueryEncoded(java.lang.String encodedQuery)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

URN_SCHEMA_PREFIX

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

EMPTY_URI

public static final URI EMPTY_URI
Constructor Detail

URI

public URI(java.lang.String uri)
Constructor. Creates an URI from String.

Parameters:
uri - The String representation of an URI. If the URI string must contain any not allowed characters, specified by the RFC3986, this characters have to be percent encoded.

URI

public URI(URI baseURI,
           URI uri)
Constructor. Merges a base URI together with another URI (URI reference). Implementation based on Chapter 5.2.2 Transform References of the IETF RFC 3986.

Parameters:
baseURI - Base URI, must be a non relative URI, fragment will be ignored.
uri -

URI

public URI(URI baseURI,
           java.lang.String path)
Creates an URI from a base URI and a path as which is regarded to be relative to the given base URI.

This method allows to change the path of the URI. For instance: http://example.org/testing into http://example.org/stable

Parameters:
baseURI - URI to be the base of the newly created URI.
path - A path relative to the baseURI. If the path string must contain any not allowed characters, specified by the RFC3986, this characters have to be percent encoded.

URI

public URI(java.lang.String absoluteURI,
           URI baseURI)
Creates an URI from String.

Parameters:
absoluteURI - the String representation of an URI.
baseURI - if baseURI is set the absoluteURI is handled as relative URI in relation to the baseURI.

URI

public URI(java.lang.String baseURI,
           java.lang.String path)
Creates an URI from a base URI as String and a path as String which is regarded to be relative to the given base URI.

Parameters:
baseURI - the String representation of an absolute base URI
path - A path relative to the baseURI. No path with reserved characters allowed, those characters must be encoded.
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

clone

public java.lang.Object clone()
Creates a clone of this URI.

Overrides:
clone in class java.lang.Object
Returns:
the clone of this URI.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

equalsWsdRfc3986

public boolean equalsWsdRfc3986(URI other)
Case-insensitive comparison of this with the given uri.

Parameters:
other -
Returns:
true only if this URI instance equals other in terms of RFC3986 equality

isRelativeReference

public boolean isRelativeReference()
Returns true if this is a relative URI, false if the base part is set.

Returns:
true if this is a relative URI, false if the base part is set.

isValid

public boolean isValid()
Returns true, if the URI seams to be correct and there were no problems while parsing it.

Returns:
true, if the URI could be parsed, false otherwise.

isURN

public boolean isURN()
Returns true if this URI has the URN schema, false otherwise.

Returns:
true if this URI has the URN schema, false otherwise.

getSchema

public java.lang.String getSchema()
Returns the schema defined in the URI.

Returns:
the schema.

getUser

public java.lang.String getUser()
Returns the user defined in the URI.

Returns:
the user.

getPassword

public java.lang.String getPassword()
Returns the password defined in the URI.

Returns:
the password.

getHost

public java.lang.String getHost()
Returns the host defined in the URI.

Returns:
the host.

getPort

public int getPort()
Returns the port for the host part of this URI.

Returns:
the port.

getHostWithPort

public java.lang.String getHostWithPort()
Returns a String containing the host and the port defined in the URI. e.g. host:port.

Returns:
the host:port part.

getPath

public java.lang.String getPath()
Returns the path defined in the URI. If no path is set, "/" is returned.

Returns:
the path.

getQuery

public java.lang.String getQuery()
Returns the query defined in the URI. e.g. the part behind the "?". (http://localhost/index?foobar=yes).

Returns:
the query.

setQuery

public void setQuery(java.lang.String query)

setQueryEncoded

public void setQueryEncoded(java.lang.String encodedQuery)

getFragment

public java.lang.String getFragment()
Returns the fragment defined in the URI. e.g. the fragment behind the "#". (http://localhost/index#anchor).

Returns:
the fragment

setFragment

public void setFragment(java.lang.String fragment)

setFragmentEncoded

public void setFragmentEncoded(java.lang.String encodedFragment)

getPathDeepness

public int getPathDeepness()
Returns the deepness of the path inside this URI. If URI relative, the path deepness = -1.

Returns:
Path deepness. -1, if URI relative.

getPath

public java.lang.String getPath(int deepness)
Returns the leading part of the path, calculated by the path deepness. e.g if the URI is something like http://somehost.com/somepath/otherpath/file.html:

Parameters:
uri - The URI to use.
deepness - The path deepness.
Returns:
The path limited by deepness.

absolutize

public static URI absolutize(URI baseUri,
                             java.lang.String newUri)
TODO

Parameters:
baseUri -
newUri -
Returns:
an absolute URI created from baseUri and newUri

isIPv6Address

public static final boolean isIPv6Address(java.lang.String address)
Check for IPv6 address.

This will check the string for textual representation of an IPv6 address. At first, this method will check for the colon which should be between the hex digits.

Parameters:
address - the string representation of the address which should be checked.
Returns:
true if the string is a IPv6 address, false otherwise.

isIPv6Address

public boolean isIPv6Address()