scone.netobjects
Class SimpleUri

java.lang.Object
  extended by scone.netobjects.SimpleUri

public class SimpleUri
extends java.lang.Object

This implementation tries to be compliant with RFC2396 (it is not by default, see below!). However, there are some exceptions:

implementation of ambiguities:

Type java SimpleUri for a reference!

URIs are parsed into the components
scheme:authority/path?query#fragment
URLs are normally interpreted as
protocol:host/path?query#fragment
therefor this class defines methods to access these field virtually.

http - URIs are also parsed into port, file and extension. The port is deleted if it is set to 80, the file is deleted if it starts with "index." "welcome." or "default."

Unfortunately, the Netscape Navigator evaluates relative URIs in a different way than described in RFC2396:
An empty reference with base http://a/b/c/d;p?q evaluates to http://a/b/c/
This class mimics the behaviour of the Netscape Navigator/ Internet Explorer by default. If you want to have a clean RFC compliant parsing, set the static variable parseNavigatorLike to false.

Author:
Harald Weinreich, Volkert Buchmann

Field Summary
protected  java.lang.String authority
           
protected  SimpleUri base
           
protected  java.lang.String extension
           
protected  java.lang.String file
           
protected  java.lang.String fragment
           
protected static java.util.Hashtable mimeTypeTable
           
protected  java.lang.String opaquePart
           
protected  java.lang.String originalUriString
           
static boolean parseNavigatorLike
           
protected  java.lang.String path
           
protected  java.lang.String port
           
protected  java.lang.String query
           
protected  java.lang.String scheme
           
 
Constructor Summary
SimpleUri(SimpleUri base, java.lang.String uriString)
          Create a new SimpleUri to a base URI.
SimpleUri(java.lang.String uriString)
          Create a new SimpleUri from a String.
 
Method Summary
 boolean equals(SimpleUri uri)
          Compare this SimpleUri to another SimpleUri.
 boolean equals(java.lang.String uriString)
          Compare this SimpleUri to another normalized URI.
protected  void findPathAndQuery(java.lang.String s, int j)
           
 java.lang.String getAuthority()
           
 java.lang.String getExtension()
          returns the file extension of the URI like html, php or asp.
 java.lang.String getFile()
           
 java.lang.String getFragment()
          Returns the fragment part of the URI (the string after the # without the #).
 java.lang.String getHexHashCode()
          Returns a hashcode hex String to this SimpleUri.
static java.lang.String getHexHashCode(java.lang.String uriString)
          Returns a hashcode hex String to a SimpleUri String.
 java.lang.String getHexHashCodeofHost()
          Returns a hashcode hex String to the "scheme:authority:port"-part of the SimpleUri.
 java.lang.String getHost()
           
 java.lang.String getMainHost()
           
 java.lang.String getMimeType()
          This method returns the mime-type of this URI.
static java.lang.String getMimeTypeFromExtension(java.lang.String extension)
          This static method returns the appropiete mime-type to a file extension.
 java.lang.String getOpaquePart()
           
 java.lang.String getOriginalUri()
           
 java.lang.String getPath()
           
 java.lang.String getPort()
           
 java.lang.String getProtocol()
           
 java.lang.String getQuery()
           
 java.lang.String getRef()
          Returns the fragment part of the URI (the string after the # without the #).
 java.lang.String getScheme()
           
 java.lang.String getUri()
          return the URI as String.
static void main(java.lang.String[] args)
          This main method is only for test purposes!
protected  void normalizeHttpUri()
          Shorten the URI as much as useful
protected  java.util.Vector parseBase(java.lang.String path)
           
protected  void parseNetPath(java.lang.String s, int i)
           
protected  void parseRelativeUri(java.lang.String s)
           
protected  void parseUri()
           
protected  void print()
          for test purposes: Print original URI and normalized URI
protected  void reset()
          clear SimpleURI
 java.lang.String toDocString()
          This method returns the URI without the fragment (``#创) identifyer...
 java.net.URL toDocURL()
          This method returns the URI without the fragment identifyer...
 java.lang.String toHostString()
           
 java.lang.String toString()
          The complete URI is returned (same as getUri()).
 java.net.URL toURL()
          The complete URI is returned.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

scheme

protected java.lang.String scheme

authority

protected java.lang.String authority

path

protected java.lang.String path

query

protected java.lang.String query

fragment

protected java.lang.String fragment

opaquePart

protected java.lang.String opaquePart

port

protected java.lang.String port

file

protected java.lang.String file

extension

protected java.lang.String extension

originalUriString

protected java.lang.String originalUriString

base

protected SimpleUri base

parseNavigatorLike

public static boolean parseNavigatorLike

mimeTypeTable

protected static java.util.Hashtable mimeTypeTable
Constructor Detail

SimpleUri

public SimpleUri(SimpleUri base,
                 java.lang.String uriString)
Create a new SimpleUri to a base URI.

Parameters:
SimpleUri - baseUri
String - uriString

SimpleUri

public SimpleUri(java.lang.String uriString)
Create a new SimpleUri from a String. The Uri will be normalized

Method Detail

main

public static void main(java.lang.String[] args)
This main method is only for test purposes!


print

protected void print()
for test purposes: Print original URI and normalized URI


equals

public boolean equals(java.lang.String uriString)
Compare this SimpleUri to another normalized URI.

Example: http://www.scone.de:80/index.html equals http://www.scone.de/


equals

public boolean equals(SimpleUri uri)
Compare this SimpleUri to another SimpleUri.


getPath

public java.lang.String getPath()
Returns:
path part or URI without host or filename etc.

getQuery

public java.lang.String getQuery()
Returns:
the query part of the URI without the ``?创

getOpaquePart

public java.lang.String getOpaquePart()
Returns:
opaque part of URI, like ``webmaster@scone.de创 in ``mailto:webmaster@scone.de创

getOriginalUri

public java.lang.String getOriginalUri()
Returns:
the original URI from which this SimpleUri was created.

getUri

public java.lang.String getUri()
return the URI as String. Same as toString()

scheme:authority:port/path/file?query#fragment


getProtocol

public java.lang.String getProtocol()
Returns:
the protocol (i.e. scheme) of this URI like http, ftp or mailto (without colon)

getScheme

public java.lang.String getScheme()
Returns:
the scheme (i.e. protocol) of this URI like http, ftp or mailto (without colon)

getHost

public java.lang.String getHost()
Returns:
the host (i.e. authority) part of the URI

getAuthority

public java.lang.String getAuthority()
Returns:
the host (i.e. authority) part of the URI

getMainHost

public java.lang.String getMainHost()
Returns:
the main host part of the URI, i.e. ebay.com from search.ebay.com and www.ebay.com, or ebay.co.uk from search.ebay.co.uk and www.ebay.co.uk

getPort

public java.lang.String getPort()
Returns:
the port number of the URI. Empty if default port is used.

getFile

public java.lang.String getFile()

getExtension

public java.lang.String getExtension()
returns the file extension of the URI like html, php or asp. Without the dot.


getRef

public java.lang.String getRef()
Returns the fragment part of the URI (the string after the # without the #).


getFragment

public java.lang.String getFragment()
Returns the fragment part of the URI (the string after the # without the #).


toString

public java.lang.String toString()
The complete URI is returned (same as getUri()).

scheme:authority:port/path/file?query#fragment

Overrides:
toString in class java.lang.Object

toDocString

public java.lang.String toDocString()
This method returns the URI without the fragment (``#创) identifyer...


toURL

public java.net.URL toURL()
The complete URI is returned.

scheme:authority:port/path/file?query#fragment

Returns:
returns a Java URL made from this SimpleURI.

toDocURL

public java.net.URL toDocURL()
This method returns the URI without the fragment identifyer...


toHostString

public java.lang.String toHostString()

getHexHashCode

public java.lang.String getHexHashCode()
Returns a hashcode hex String to this SimpleUri.


getHexHashCodeofHost

public java.lang.String getHexHashCodeofHost()
Returns a hashcode hex String to the "scheme:authority:port"-part of the SimpleUri.


getHexHashCode

public static java.lang.String getHexHashCode(java.lang.String uriString)
Returns a hashcode hex String to a SimpleUri String. The hashcode for a String object is computed as
 
 s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
 
using long arithmetic, where s[i] is the ith character of the SimpleUri, n is the length of the Uri, and ^ indicates exponentiation.

Returns:
a hash code value for this object.

getMimeType

public java.lang.String getMimeType()
This method returns the mime-type of this URI.

Returns:
extension the extension of this SimpleUri

getMimeTypeFromExtension

public static java.lang.String getMimeTypeFromExtension(java.lang.String extension)
This static method returns the appropiete mime-type to a file extension.

Parameters:
extension - the extension of the file or Url

reset

protected void reset()
clear SimpleURI


parseUri

protected void parseUri()

parseNetPath

protected void parseNetPath(java.lang.String s,
                            int i)

parseRelativeUri

protected void parseRelativeUri(java.lang.String s)

parseBase

protected java.util.Vector parseBase(java.lang.String path)

findPathAndQuery

protected void findPathAndQuery(java.lang.String s,
                                int j)

normalizeHttpUri

protected void normalizeHttpUri()
Shorten the URI as much as useful