com.ecyrd.jspwiki.dav
Class DavPath

java.lang.Object
  extended by com.ecyrd.jspwiki.dav.DavPath

public class DavPath
extends Object

The DavPath represents an abstract path to any resource within the WebDav system. Since the file tree displayed by the DAV storage may be different from the actual representation, this component is needed.

You instantiate a new DavPath simply by saying DavPath dp = new DavPath("/path/to/my/object");

If the path ends in a slash, it is understood to be a directory. If not, it represents a file.


Constructor Summary
DavPath(DavPath dp)
          Creates a new DavPath from an old one.
DavPath(String path)
          Creates a new DavPath object.
 
Method Summary
 void append(DavPath dp)
          Adds another path to the end of this path.
 void append(String path)
          Adds another path to the end of this path.
 String filePart()
          Returns the file part of the DavPath.
 String get(int idx)
          Returns the 'idx' component of the path, zero being the first component.
 String getName()
          Returns the name of the last component of the DavPath.
 String getPath()
          Returns the entire path as a String.
 boolean isDirectory()
          Returns true, if the path represents a directory.
 boolean isRoot()
          Returns true, if the path represents the top-level entity.
 int length()
          Exactly equivalent to size().
 String pathPart()
          Returns the directory part of the DavPath.
 int size()
          Exactly equivalent to length().
 DavPath subPath(int idx)
          Returns a new DavPath object that is a sub-path of this path.
 String toString()
          Returns a human-readable version of the path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DavPath

public DavPath(DavPath dp)
Creates a new DavPath from an old one.

Parameters:
dp - the dav path

DavPath

public DavPath(String path)
Creates a new DavPath object. The path parameter should be an arbitrary string with components separated with slashes.

Parameters:
path -
Method Detail

append

public void append(DavPath dp)
Adds another path to the end of this path.

Parameters:
dp - the current dav path

append

public void append(String path)
Adds another path to the end of this path. The "path" parameter may contain a slash-separated path (e.g. "foo/bar/blog.txt").

Parameters:
path - the current dav path

isRoot

public boolean isRoot()
Returns true, if the path represents the top-level entity. This is true, if the path is "/" or it is empty.

Returns:
True or false.

isDirectory

public boolean isDirectory()
Returns true, if the path represents a directory.

Returns:
true if the path is a directory; false otherwise

pathPart

public String pathPart()
Returns the directory part of the DavPath.

Returns:
the directory portion of the path

filePart

public String filePart()
Returns the file part of the DavPath. The method returns the last component of the path, unless the path is a directory, in which case it returns an empty string.

Returns:
the file name, or an empty string

getName

public String getName()
Returns the name of the last component of the DavPath. This is either the name of a directory, or the name of a file.

Returns:
the name of the right-most portion of the dav path

getPath

public String getPath()
Returns the entire path as a String.

Returns:
the entire dav path

subPath

public DavPath subPath(int idx)
Returns a new DavPath object that is a sub-path of this path. E.g. if the path is "/foo/bar/blog.txt", subPath(1) would return "bar/blog.txt". Notice that the resulting path is not absolute in this case.

Parameters:
idx - Start from this part.
Returns:
A sub-path of this path.

get

public String get(int idx)
Returns the 'idx' component of the path, zero being the first component. If there is no such component, it will simply return null.

Parameters:
idx - The component to return. Zero is the first element.
Returns:
A part of the path.

size

public int size()
Exactly equivalent to length().

Returns:
The length of the path.

length

public int length()
Exactly equivalent to size(). I'm too lazy to remember whether it's length() or size(), so I'll provide both...

Returns:
the size of the path

toString

public String toString()
Returns a human-readable version of the path. Please use getPath() instead of toString(), as this method is only good for debugging purposes.

Overrides:
toString in class Object
Returns:
the String representation of the path