|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.simpleframework.common.parse.Parser
org.simpleframework.http.parse.PathParser
public class PathParser
This is used to parse a path given as part of a URI. This will read the path, normalize it, and break it up into its components. The normalization of the path is the conversion of the path given into it's actual path by removing the references to the parent directories and to the current dir.
If the path that this represents is /usr/bin/../etc/./README
then the actual path, normalized, is /usr/etc/README. Once
the path has been normalized it is possible to acquire the segments as
an array of strings, which allows simple manipulation of the path.
Although RFC 2396 defines the path within a URI to have parameters this
does not extract those parameters this will simply normalize the path and
include the path parameters in the path. If the path is to be converted
into a OS specific file system path that has the parameters extracted
then the AddressParser should be used.
| Field Summary |
|---|
| Fields inherited from class org.simpleframework.common.parse.Parser |
|---|
buf, count, off |
| Constructor Summary | |
|---|---|
PathParser()
The default constructor will create a PathParser that
contains no specifics. |
|
PathParser(String path)
This is primarily a convineance constructor. |
|
| Method Summary | |
|---|---|
String |
getDirectory()
This will return the highest directory that exists within the path. |
String |
getExtension()
This will return the extension that the file name contains. |
String |
getName()
This will return the full name of the file without the path. |
String |
getPath()
This will return the normalized path. |
String |
getPath(int from)
This will return the normalized path from the specified path segment. |
String |
getPath(int from,
int count)
This will return the normalized path from the specified path segment. |
String |
getRelative(String path)
This will return the path as it is relative to the issued path. |
String[] |
getSegments()
This method is used to break the path into individual parts called segments, see RFC 2396. |
protected void |
init()
This will initialize the parser so that it is in a ready state. |
protected void |
parse()
This will parse the path in such a way that it ensures that at no stage there are trailing back references, using path normalization. |
String |
toString()
This will return the normalized path. |
| Methods inherited from class org.simpleframework.common.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 PathParser()
PathParser that
contains no specifics. The instance will return null
for all the get methods. The PathParser's get methods
may be populated by using the parse method.
public PathParser(String path)
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.
path - a String containing a path value| Method Detail |
|---|
protected void parse()
PathParser will create the same String
path given a set of paths that have different back references. For
example the paths /path/../path and /path
are the same path but different String's.
This will NOT parse an immediate back reference as this signifies
a path that cannot exist. So a path such as /../ will
result in a null for all methods. Paths such as ../bin
will not be allowed.
parse in class Parserprotected void init()
Parser.parse method.
init in class Parserpublic String getExtension()
file.en_US.extension
will produce an extension of extension. This
will return null if the path contains no file extension.
getExtension in interface Pathpublic String getName()
/usr/README the name is README.
Also for directorys the name of the directory in the last
path segment is returned. This returns the name without any
of the path parameters. As RFC 2396 defines the path to have
path parameters after the path segments.
getName in interface Pathpublic String getPath()
/usr/../etc/./ the
path is /etc/. If the path that this represents
is a path with an immediate back reference then this will
return null. This is the path with all its information even
the parameter information if it was defined in the path.
getPath in interface Path../ or ./public String getPath(int from)
substring invocations. Of particular
interest is the extraction of context based paths. This is
the path with all its information even the parameter
information if it was defined in the path.
getPath in interface Pathfrom - this is the segment offset to get the path for
../ or ./
public String getPath(int from,
int count)
substring invocations. Of particular
interest is the extraction of context based paths. This is
the path with all its information even the parameter
information if it was defined in the path.
getPath in interface Pathfrom - this is the segment offset to get the path forcount - this is the number of path segments to include
../ or ./public String getDirectory()
/pub/./bin/README would be to return
the highest directory path /pub/bin/. The "/"
character will allways be the last character in the path.
getDirectory in interface Pathpublic String[] getSegments()
/usr/bin/../etc then the segments
returned would be usr and etc as
the path is normalized before the segments are extracted.
getSegments in interface Pathpublic String getRelative(String path)
getDirectory. This is useful if paths
that are relative to a specific location are required. To
illustrate what this method will do the following example
is provided. If this object represented the path string
/usr/share/rfc/rfc2396.txt and the issued
path was /usr/share/text.txt then this will
return the path string /rfc/rfc2396.txt.
getRelative in interface Pathpath - the path prefix to acquire a relative path
public String toString()
/usr/../etc/./ the
path is /etc/. If the path that this represents
is a path with an immediate back reference then this will
return null. This is the path with all its information even
the parameter information if it was defined in the path.
toString in interface PathtoString in class Object../ or ./
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||