org.owasp.webscarab.model
Class HttpUrl

java.lang.Object
  extended by org.owasp.webscarab.model.HttpUrl
All Implemented Interfaces:
java.lang.Comparable

public class HttpUrl
extends java.lang.Object
implements java.lang.Comparable

Represents a http or https url

Author:
knoppix

Constructor Summary
HttpUrl(HttpUrl url, java.lang.String relative)
          Creates a new url, basing the supplied relative path against the supplied HttpUrl
HttpUrl(java.lang.String url)
          creates an HttpUrl by parsing the supplied string
 
Method Summary
 int compareTo(java.lang.Object o)
          Compares this object with the specified object for order.
 java.lang.String direct()
          returns only the /path;fragment?query part of the URL
 java.lang.StringBuffer direct(java.lang.StringBuffer buff)
          appends the /path;fragment?query part of the URL to the supplied buffer
 boolean equals(java.lang.Object o)
          Indicates whether some other object is "equal to" this one.
 java.lang.String getFragment()
          returns the fragment part of the url, or null if none exists
 java.lang.String getHost()
          returns the host part of the url
 java.lang.String getParameters()
          returns a string representation of the parameters passed to the url
 HttpUrl getParentUrl()
          returns the parent of this Url.
 java.lang.String getPath()
          returns the "file path" of the URL, excluding any fragments or queries
 int getPort()
          returns the port
 java.lang.String getQuery()
          returns the query part of the url, or null if none exists
 java.lang.String getScheme()
          returns the schem of the url
 java.lang.String getSHPP()
          returns a string representation of the url, excluding any fragments or query parts
 HttpUrl[] getUrlHierarchy()
          returns an array containing the Url hierarchy, including this Url
 int hashCode()
          Returns a hash code value for the object.
 java.lang.String toString()
          returns a string representation of the URL, in fully qualified form
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HttpUrl

public HttpUrl(java.lang.String url)
        throws java.net.MalformedURLException
creates an HttpUrl by parsing the supplied string

Parameters:
url - a String representation of the URL
Throws:
java.net.MalformedURLException - if the url is not well-formed

HttpUrl

public HttpUrl(HttpUrl url,
               java.lang.String relative)
        throws java.net.MalformedURLException
Creates a new url, basing the supplied relative path against the supplied HttpUrl

Parameters:
url - the existing base url
relative - the relative path
Throws:
java.net.MalformedURLException - if the url is malformed
Method Detail

getScheme

public java.lang.String getScheme()
returns the schem of the url

Returns:
Returns the scheme.

getHost

public java.lang.String getHost()
returns the host part of the url

Returns:
Returns the host.

getPort

public int getPort()
returns the port

Returns:
Returns the port.

getPath

public java.lang.String getPath()
returns the "file path" of the URL, excluding any fragments or queries

Returns:
Returns the path.

getFragment

public java.lang.String getFragment()
returns the fragment part of the url, or null if none exists

Returns:
Returns the fragment.

getQuery

public java.lang.String getQuery()
returns the query part of the url, or null if none exists

Returns:
Returns the query.

getSHPP

public java.lang.String getSHPP()
returns a string representation of the url, excluding any fragments or query parts

Returns:
the string representation of the URL, excluding any fragments or query

getParameters

public java.lang.String getParameters()
returns a string representation of the parameters passed to the url

Returns:
the string representation of the parameters

getParentUrl

public HttpUrl getParentUrl()
returns the parent of this Url.

Returns:
the parent of this Url, or null if this is a top-level Url

getUrlHierarchy

public HttpUrl[] getUrlHierarchy()
returns an array containing the Url hierarchy, including this Url

Returns:
an array of the Url hierarchy

toString

public java.lang.String toString()
returns a string representation of the URL, in fully qualified form

Overrides:
toString in class java.lang.Object
Returns:
the fully qualifed url

direct

public java.lang.StringBuffer direct(java.lang.StringBuffer buff)
appends the /path;fragment?query part of the URL to the supplied buffer

Parameters:
buff - a StrinBuffer to append the URL to
Returns:
the buffer

direct

public java.lang.String direct()
returns only the /path;fragment?query part of the URL

Returns:
the /path;fragment?query part of the URL

equals

public boolean equals(java.lang.Object o)
Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).

Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.

Overrides:
equals in class java.lang.Object
Parameters:
o - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.
See Also:
hashCode(), Hashtable

compareTo

public int compareTo(java.lang.Object o)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

In the foregoing description, the notation sgn(expression) designates the mathematical signum function, which is defined to return one of -1, 0, or 1 according to whether the value of expression is negative, zero or positive. The implementor must ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception iff y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y)>0 && y.compareTo(z)>0) implies x.compareTo(z)>0.

Finally, the implementer must ensure that x.compareTo(y)==0 implies that sgn(x.compareTo(z)) == sgn(y.compareTo(z)), for all z.

It is strongly recommended, but not strictly required that (x.compareTo(y)==0) == (x.equals(y)). Generally speaking, any class that implements the Comparable interface and violates this condition should clearly indicate this fact. The recommended language is "Note: this class has a natural ordering that is inconsistent with equals."

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - the Object to be compared.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

hashCode

public int hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable.

The general contract of hashCode is:

As much as is reasonably practical, the hashCode method defined by class HttpUrl does return distinct integers for distinct objects. (This is implemented by converting the url to a String, and returning the String's hashCode() )

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this object.
See Also:
Object.equals(java.lang.Object), Hashtable