Package org.simpleframework.http
Interface Path
-
- All Known Implementing Classes:
PathParser
public interface Path
ThePath
represents the path part of a URI. This provides the various components of the URI path to the user. 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.- See Also:
PathParser
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.String
getDirectory()
This will return the highest directory that exists within the path.java.lang.String
getExtension()
This will return the extension that the file name contains.java.lang.String
getName()
This will return the full name of the file without the path.java.lang.String
getPath()
This will return the normalized path.java.lang.String
getPath(int from)
This will return the normalized path from the specified path segment.java.lang.String
getPath(int from, int count)
This will return the normalized path from the specified path segment.java.lang.String
getRelative(java.lang.String path)
This will return the path as it is relative to the issued path.java.lang.String[]
getSegments()
This method is used to break the path into individual parts called segments, see RFC 2396.java.lang.String
toString()
This will return the normalized path.
-
-
-
Method Detail
-
getExtension
java.lang.String getExtension()
This will return the extension that the file name contains. For example a file namefile.en_US.extension
will produce an extension ofextension
. This will return null if the path contains no file extension.- Returns:
- this will return the extension this path contains
-
getName
java.lang.String getName()
This will return the full name of the file without the path. As regargs the definition of the path in RFC 2396 the name would be considered the last path segment. So if the path was/usr/README
the name isREADME
. 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.- Returns:
- this will return the name of the file in the path
-
getPath
java.lang.String getPath()
This will return the normalized path. The normalized path is the path without any references to its parent or itself. So if the path to be parsed is/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.- Returns:
- this returns the normalize path without
../
or./
-
getPath
java.lang.String getPath(int from)
This will return the normalized path from the specified path segment. This allows various path parts to be acquired in an efficient means what does not require copy operations of the use ofsubstring
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.- Parameters:
from
- this is the segment offset to get the path for- Returns:
- this returns the normalize path without
../
or./
-
getPath
java.lang.String getPath(int from, int count)
This will return the normalized path from the specified path segment. This allows various path parts to be acquired in an efficient means what does not require copy operations of the use ofsubstring
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.- Parameters:
from
- this is the segment offset to get the path forcount
- this is the number of path segments to include- Returns:
- this returns the normalize path without
../
or./
-
getSegments
java.lang.String[] getSegments()
This method is used to break the path into individual parts called segments, see RFC 2396. This can be used as an easy way to compare paths and to examine the directory tree that the path points to. For example, if an path was broken from the string/usr/bin/../etc
then the segments returned would beusr
andetc
as the path is normalized before the segments are extracted.- Returns:
- return all the path segments within the directory
-
getDirectory
java.lang.String getDirectory()
This will return the highest directory that exists within the path. This is used to that files within the same path can be acquired. An example of that this would do given the path/pub/./bin/README
would be to return the highest directory path/pub/bin/
. The "/" character will allways be the last character in the path.- Returns:
- this method will return the highest directory
-
getRelative
java.lang.String getRelative(java.lang.String path)
This will return the path as it is relative to the issued path. This in effect will chop the start of this path if it's start matches the highest directory of the given path as ofgetDirectory
. 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
.- Parameters:
path
- the path prefix to acquire a relative path- Returns:
- returns a path relative to the one it is given otherwize this method will return null
-
toString
java.lang.String toString()
This will return the normalized path. The normalized path is the path without any references to its parent or itself. So if the path to be parsed is/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.- Overrides:
toString
in classjava.lang.Object
- Returns:
- this returns the normalize path without
../
or./
-
-