issrg.utils
Class ParsedURL

java.lang.Object
  extended by issrg.utils.ParsedURL

public class ParsedURL
extends java.lang.Object

This class provides methods for splitting a URL into an array of strings. There is also a method for checking that particular strings conform to the standard - i.e. contain only valid characters.

It handles only HTTP-like URLs:

protocol : // [[username [: password] @] host [:port]] [/ [ path ] [# anchor] [? query]]

Note that host is also an optional part of the URL, so file: URLs are also acceptable (but getHost() will return null).

There are corresponding methods to get these values; they can be null, if the value is missing (only path is not null, and has 0 elements, if missing; paths ending with '/' have an empty String "" at the end of the array).

Author:
A.Otenko

Constructor Summary
protected ParsedURL()
           
protected ParsedURL(java.lang.String url, java.lang.String protocol, java.lang.String userName, java.lang.String password, java.lang.String host, java.lang.String port, java.lang.String[] path, java.lang.String anchor, java.lang.String query)
          This constructor builds a ParsedURL given the original URL and parts of it.
 
Method Summary
 java.lang.String getAnchor()
           
 java.lang.String getHost()
           
 java.lang.String getNormalizedURL()
          This method returns a normalised URL (i.e. the path is without '.' and '..' elements, etc.)
 java.lang.String[] getOriginalPath()
          This method returns the path as it is in the URL ("." and ".." are possible).
 java.lang.String getPassword()
           
 java.lang.String[] getPath()
          This method returns normalised path (excessive "." and ".." are removed)
 java.lang.String getPathString()
          This method returns the normalised path as a String.
 java.lang.String getPort()
           
 java.lang.String getProtocol()
           
 java.lang.String getQuery()
           
 java.lang.String getURL()
           
 java.lang.String getUserName()
           
static ParsedURL parseURL(java.lang.String url)
          This method parses a URL string, and returns a ParsedURL object, if succeded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParsedURL

protected ParsedURL()

ParsedURL

protected ParsedURL(java.lang.String url,
                    java.lang.String protocol,
                    java.lang.String userName,
                    java.lang.String password,
                    java.lang.String host,
                    java.lang.String port,
                    java.lang.String[] path,
                    java.lang.String anchor,
                    java.lang.String query)
This constructor builds a ParsedURL given the original URL and parts of it. Any part can be null, except the path.

Parameters:
url - - the original URL from which the parts were obtained
protocol - - the protocol extracted from the original URL
userName - - the user name as it appears in the URL
password - - the password as it appears in the URL
host - - the host name as it appears in the URL
port - - the port specification String; may be an integer, but sometimes it is more than that (e.g. a range of ports)
path - - the array of path elements; cannot be null, but can be empty
anchor - - the anchor String (everything after "#" and before the query String)
query - - the query String (everything after "?")
Method Detail

getProtocol

public java.lang.String getProtocol()
Returns:
the protocol of the URL as it has been provided to the constructor

getURL

public java.lang.String getURL()
Returns:
the original URL as it has been provided to the constructor

getUserName

public java.lang.String getUserName()
Returns:
the user name as it has been provided to the constructor

getPassword

public java.lang.String getPassword()
Returns:
the password as it has been provided to the constructor

getHost

public java.lang.String getHost()
Returns:
the host name as it has been provided to the constructor

getPort

public java.lang.String getPort()
Returns:
the port string as it has been provided to the constructor

getPath

public java.lang.String[] getPath()
This method returns normalised path (excessive "." and ".." are removed)

Returns:
array of strings, representing the path; no "." or ".." are there, only the last element may be a "." if the URL ends with a "/" and means that the previous name in the path is a directory

getOriginalPath

public java.lang.String[] getOriginalPath()
This method returns the path as it is in the URL ("." and ".." are possible).

Returns:
array of strings, representing the path; if no excessive "." or ".." were used, it is the same as getPath()

getPathString

public java.lang.String getPathString()
This method returns the normalised path as a String.


getAnchor

public java.lang.String getAnchor()
Returns:
the anchor string as it has been provided to the constructor

getQuery

public java.lang.String getQuery()
Returns:
the query string as it has been provided to the constructor

getNormalizedURL

public java.lang.String getNormalizedURL()
This method returns a normalised URL (i.e. the path is without '.' and '..' elements, etc.)


parseURL

public static ParsedURL parseURL(java.lang.String url)
This method parses a URL string, and returns a ParsedURL object, if succeded. It returns null, if URL is not valid.

Valid URLs correspond to the following syntax:

[url:]protocol : // [username [: password]@] host [: port] [/ [path] [# [anchor]]] [? [query]]

Parameters:
url - is a string encoding of the URL; no character transformation is done, e.g. %20 remains itself, and is not substituted by a space
Returns:
ParsedURL object, if parse succeeded, or null, if parse failed.