|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsimple.util.parse.Parser
simple.util.parse.URIParser
public class URIParser
This parser is used to parse uniform resource identifiers.
The uniform resource identifier syntax is given in RFC 2396.
This parser can parse relative and absolute URI's. The
uniform resource identifier syntax that this parser will
parse are based on the generic web based URL similar to
the syntax represented in RFC 2616 section 3.2.2. The syntax
used to parse this URI is a modified version of RFC 2396
This implements the
URI = (absoluteURI | relativeURI)
absoluteURI = scheme ":" ("//" netpath | relativeURI)
relativeURI = path ["?" querypart]
netpath = domain [":" port] relativeURI
path = *("/" segment)
segment = *pchar *( ";" param )
URI
interface and provides
methods that access the various parts of the URI. The parameters
in the path segments of the uniform resource identifier are
stored in name value pairs. If parameter names are not unique
across the path segments then only the deepest parameter will be
stored from the path segment. For example if the URI represented
was http://domain/path1;x=y/path2;x=z
the value for
the parameter named x
would be z
.
This will normalize the path part of the uniform resource identifier. A normalized path is one that contains no back references like "./" and "../". The normalized path will not contain the path parameters.
The setPath
method is used to reset the path this
uniform resource identifier has, it also resets the parameters.
The parameters are extracted from the new path given.
Field Summary |
---|
Fields inherited from class simple.util.parse.Parser |
---|
buf, count, off |
Constructor Summary | |
---|---|
URIParser()
Default constructor will create a URIParser
that contains no specifics. |
|
URIParser(java.lang.String text)
This is primarily a convineance constructor. |
Method Summary | |
---|---|
java.lang.String |
getDomain()
This is used to retrive the domain of this URI. |
java.lang.String |
getParameter(java.lang.String name)
This will return the value of the parameter with the given name. |
java.util.Enumeration |
getParameterNames()
This extracts the parameter names from the uniform resource identifier represented by this object. |
Path |
getPath()
This is used to retrive the path of this URI. |
int |
getPort()
This is used to retrive the port of the uniform resource identifier. |
Parameters |
getQuery()
This is used to retrive the query of this URI. |
java.lang.String |
getScheme()
This allows the scheme of the URL given to be returned. |
protected void |
init()
This will empty each tokens cache. |
protected void |
parse()
This will check to see what type of URI this is if it is an absoluteURI or a relativeURI . |
void |
setDomain(java.lang.String value)
This will set the domain to whatever value is in the string parameter. |
void |
setPath(Path path)
This will set the path to whatever value it is given. |
void |
setPath(java.lang.String text)
This will set the path to whatever value it is given. |
void |
setPort(int port)
This will set the port to whatever value it is given. |
void |
setQuery(Parameters query)
This will set the query to whatever value it is given. |
void |
setQuery(java.lang.String value)
This will set the query to whatever value it is given. |
void |
setScheme(java.lang.String value)
This allows the scheme for the URI to be specified. |
java.lang.String |
toString()
This is used to convert this URI object into a String
object. |
Methods inherited from class simple.util.parse.Parser |
---|
digit, ensureCapacity, parse, skip, space, toLower |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public URIParser()
URIParser
that contains no specifics. The instance will return
null
for all the get methods. The parsers
get methods are populated by using the parse
method.
public URIParser(java.lang.String text)
String
given to extract the specifics. This
could be achived by calling the default no-arg constructor
and then using the instance to invoke the parse
method on that String
to extract the parts.
text
- a String
containing a URI valueMethod Detail |
---|
public java.lang.String getScheme()
gopher://domain/path
is
a URI that is intended for the gopher protocol. The
scheme is the string gopher
.
getScheme
in interface URI
public java.lang.String getDomain()
http://domain/path?querypart
. This will
return the value of the domain part. If there is no
domain part then this will return null otherwise the
domain value found in the uniform resource identifier.
getDomain
in interface URI
public Path getPath()
/
to indicate the root.
The Path
object returned by this will contain
no path parameters. The path parameters are available using
the URI
methods. The reason that this does not
contain any of the path parameters is so that if the path is
needed to be converted into ab OS specific path then the path
parameters will not need to be seperately parsed out.
getPath
in interface URI
public Parameters getQuery()
Parameters
object. The query is
an optional member of a URI and comes after the path part, it
is preceeded by a question mark, ?
character.
For example the following URI contains query for
its query part, http://host:port/path?query
.
This returns a simple.util.net.Parameters
object
that can be used to interact directly with the query values.
The Parameters
object is a read-only interface
to the query parameters, and so will not affect the URI.
- Specified by:
getQuery
in interface URI
- Returns:
- a
Parameters
object for the query part
public int getPort()
http://host:port/path?querypart
. This
will return the value of the port. If there is no port then
this will return -1
because this represents
an impossible uniform resource identifier port. The port
is an optional part.
getPort
in interface URI
public java.util.Enumeration getParameterNames()
Enumeration
.
This will produce unique name and value parameters. Thus if the
URI contains several path segments with similar parameter names
this will return the deepest parameter. For example if the URI
represented was http://domain/path1;x=y/path2;x=z
the value for the parameter named x
would be
z
.
getParameterNames
in interface URI
public java.lang.String getParameter(java.lang.String name)
getParameterNames
. This will return null if the
parameter does not exist. The setPath
method will
reset the parameters the URI contains.
getParameter
in interface URI
name
- this is the name of the parameter to be retrived
public void setScheme(java.lang.String value)
://
identifier
to ensure that the URI.toString
will
produce the correct syntax.
Caution must be taken to ensure that the port and
the scheme are consistant. So if the original URI
was http://domain:80/path
and the scheme
was changed to ftp
the port number that
remains is the standard HTTP port not the FTP port.
setScheme
in interface URI
value
- this specifies the protocol this URI
is intended forpublic void setDomain(java.lang.String value)
toString
method will not contain
the domain. The result of the toString
method will be /path/path?query
. If the
path is non-null this URI will contain the path.
setDomain
in interface URI
value
- this will be the new domain of this
uniform resource identifier, if it is not nullpublic void setPort(int port)
toString
will
will not contain the optional port. If port number is above
0 then the toString
method will produce a URI
like http://host:123/path
but only if there is
a valid domain.
setPort
in interface URI
port
- the port value that this URI is to havepublic void setPath(java.lang.String text)
URI.toString
method will
not contain the path, that is if path is null then it will be
interpreted as /
.
This will reset the parameters this URI has. If the value
given to this method has embedded parameters these will form
the parameters of this URI. The value given may not be the
same value that the getPath
produces. The path
will have all back references and parameters stripped.
setPath
in interface URI
text
- the path that this URI is to be set withpublic void setPath(Path path)
URI.toString
method will
not contain the path, that is if path is null then it will be
interpreted as /
.
This will reset the parameters this URI has. If the value
given to this method has embedded parameters these will form
the parameters of this URI. The value given may not be the
same value that the getPath
produces. The path
will have all back references and parameters stripped.
setPath
in interface URI
path
- the path that this URI is to be set withpublic void setQuery(java.lang.String value)
URI.toString
method will
not contain the query. If the query was abc
then
the toString
method would produca a string like
http://host:port/path?abc
. If the query is null
this URI would have no query part. The query must not contain
the ?
character.
setQuery
in interface URI
value
- the query that this uniform resource identifier
is to be set to if it is non-nullpublic void setQuery(Parameters query)
URI.toString
method will
not contain the query. If the Parameters.toString
returns null then the query will be empty. This is basically
the setQuery(String)
method with the string value
from the issued Parameters.toString
method.
setQuery
in interface URI
query
- a Parameters
object that contains
the name value parameters for the queryprotected void parse()
absoluteURI
or a relativeURI
. To
see the definition of a URI see RFC 2616 for the definition
of a URL and for more specifics see RFC 2396 for the
expressions.
parse
in class Parser
protected void init()
toString
method has been called. Thus when the toString
method is called then the token depends on the value of the
cache alone in further calls to toString
.
However if a URI has just been parsed and that method has
not been invoked then the cache is created from the buf if
its length is greater than zero.
init
in class Parser
public java.lang.String toString()
String
object. This will only convert the parts of the URI that exist, so
the URI may not contain the domain or the query part and it will
not contain the path parameters. If the URI contains all these
parts then it will return somthing like
scheme://host:port/path/path?querypart
It can return /path/path?querypart
style relative
URI's. If any of the parts are set to null then that part will be
missing, for example if setDomain
method is invoked
with a null parameter then the domain and port will be missing
from the resulting URI. If the path part is set to null using the
setPath
then the path will be /
. An
example URI with the path part of null would be
scheme://host:port/?querypart
toString
in interface URI
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |