it.could.util.location
Class Location

java.lang.Object
  extended byit.could.util.location.Location
All Implemented Interfaces:
Encodable, EncodingAware

public class Location
extends Object
implements Encodable

An utility class representing an HTTP-like URL.

This class can be used to represent any URL that roughly uses the HTTP format. Compared to the standard URL class, the scheme part of the a Location is never checked, and it's up to the application to verify its correctness, while compared to the URI class, its parsing mechanism is a lot more relaxed (be liberal in what you accept, be strict in what you send).

For a bigger picture on how this class works, this is an easy-to-read representation of what the different parts of a Location are:

URL components

One important difference between this implementation and the description of URLs and URIs is that parameter paths are represented only at the end of the entire path structure rather than for each path element. This over-simplification allows easy relativization of Locations when used with servlet containers, which normally use path parameters to encode the session id.

Author:
Pier Fumagalli

Nested Class Summary
static class Location.Authority
          The Authority class represents the autority and user information for a Location.
static class Location.Schemes
          The Schemes class represents an unmodifiable ordered collection of String schemes for a Location.
 
Field Summary
 
Fields inherited from interface it.could.util.encoding.EncodingAware
DEFAULT_ENCODING, PLATFORM_ENCODING
 
Constructor Summary
Location(Location.Schemes schemes, Location.Authority authority, Path path, Parameters parameters, String fragment)
          Create a new Location instance.
 
Method Summary
 boolean equals(Object object)
          Check if the specified Object is equal to this instance.
static int findPort(List schemes, String encoding)
          Return the port number associated with the specified schemes.
 Location.Authority getAuthority()
          Return the Authority part for this Location or null.
 String getFragment()
          Return the fragment of this Location unencoded.
 Parameters getParameters()
          Return an unmodifiable list of all parameters parsed from this Location's query string or null.
 Path getPath()
          Return the non-null Path structure associated with this Location instance.
 Location.Schemes getSchemes()
          Return an unmodifiable list of all schemes for this Location instance or null.
 int hashCode()
          Return the hash code value for this Location instance.
 boolean isAbsolute()
          Checks whether this Location is absolute or not.
 boolean isAuthoritative(Location location)
           
 boolean isRelative()
           
static Location parse(String url)
           
static Location parse(String url, String encoding)
           
 Location relativize(Location location)
           
 Location relativize(String url)
           
 Location relativize(String url, String encoding)
           
 Location resolve(Location location)
           
 Location resolve(String url)
           
 Location resolve(String url, String encoding)
           
 String toString()
          Return the String representation of this Location instance.
 String toString(String encoding)
          Return the String representation of this Location instance using the specified character encoding.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Location

public Location(Location.Schemes schemes,
                Location.Authority authority,
                Path path,
                Parameters parameters,
                String fragment)
         throws MalformedURLException

Create a new Location instance.

Method Detail

parse

public static Location parse(String url)
                      throws MalformedURLException
Throws:
MalformedURLException

parse

public static Location parse(String url,
                             String encoding)
                      throws MalformedURLException,
                             UnsupportedEncodingException
Throws:
MalformedURLException
UnsupportedEncodingException

getSchemes

public Location.Schemes getSchemes()

Return an unmodifiable list of all schemes for this Location instance or null.


getAuthority

public Location.Authority getAuthority()

Return the Authority part for this Location or null.


getPath

public Path getPath()

Return the non-null Path structure associated with this Location instance.


getParameters

public Parameters getParameters()

Return an unmodifiable list of all parameters parsed from this Location's query string or null.


getFragment

public String getFragment()

Return the fragment of this Location unencoded.


equals

public boolean equals(Object object)

Check if the specified Object is equal to this instance.

The specified Object must be a non-null Location instance whose string value equals this one's.


hashCode

public int hashCode()

Return the hash code value for this Location instance.


toString

public String toString()

Return the String representation of this Location instance.

Specified by:
toString in interface Encodable

toString

public String toString(String encoding)
                throws UnsupportedEncodingException

Return the String representation of this Location instance using the specified character encoding.

Specified by:
toString in interface Encodable
Throws:
UnsupportedEncodingException - if the specified encoding is not supported by the platform.

isAbsolute

public boolean isAbsolute()

Checks whether this Location is absolute or not.

This method must not be confused with the similarly named Path.isAbsolute() method. This method will check whether the full Location is absolute (it has a scheme), while the one exposed by the Path class will check if the path is absolute.


isRelative

public boolean isRelative()

isAuthoritative

public boolean isAuthoritative(Location location)

resolve

public Location resolve(String url)
                 throws MalformedURLException
Throws:
MalformedURLException

resolve

public Location resolve(String url,
                        String encoding)
                 throws MalformedURLException,
                        UnsupportedEncodingException
Throws:
MalformedURLException
UnsupportedEncodingException

resolve

public Location resolve(Location location)

relativize

public Location relativize(String url)
                    throws MalformedURLException
Throws:
MalformedURLException

relativize

public Location relativize(String url,
                           String encoding)
                    throws MalformedURLException,
                           UnsupportedEncodingException
Throws:
MalformedURLException
UnsupportedEncodingException

relativize

public Location relativize(Location location)

findPort

public static int findPort(List schemes,
                           String encoding)
                    throws UnsupportedEncodingException

Return the port number associated with the specified schemes.

Throws:
UnsupportedEncodingException