com.fatwire.agent
Class Path

java.lang.Object
  extended by com.fatwire.agent.Path

public class Path
extends java.lang.Object

Item path.

Represents the path of an item inside a content repository. This path is unique for each item.

The separator is '/' or '\' character by default although there is a way to specify a custom separator. When path is serialized to string '/' character is used as separator by default, although you may specify your own.

When the path is constructed the input string is

The path could be rooted (starts with the separator) or not.

It also could be used for other purposes as a convenient path-processing utility.

Example usage:

      Path folderAbsolutePath = new Path(L"/usr/");
      Path fileRelativePath = new Path(L"myproject/info.txt");
      Path fileAbsolutePath = folderAbsolutePath.append( fileRelativePath );
      System.println( "Top folder: " + fileAbsolutePath.get(0) );
      System.println( "Parent folder: " + 
          fileAbsolutePath.SubPath(0, fileAbsolutePath.getLength()-1) );
 


Constructor Summary
Path(java.lang.String path)
          Default constructor.
Path(java.lang.String path, char sep)
          Constructor.
Path(java.lang.String path, char[] seps)
          Constructor.
 
Method Summary
 Path append(Path path)
          Appends the path to this path.
 boolean equals(java.lang.Object obj)
           
 java.lang.String get(int pos)
          Returns n-th part of path (zero-based).
 java.lang.String getExtension()
          Extracts file extension from path.
 java.lang.String getFilename()
          Extracts file name from this path.
 int getLength()
          Returns path length.
 Path getParent()
          Gets parent path.
 boolean isRooted()
          Determines whether path starts with the path separator.
 Path subPath(int pos, int npos)
          Returns sub-path within the current path.
 java.lang.String toString()
           
 java.lang.String toString(java.lang.String sep)
          Serializes this path using a custom separator.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Path

public Path(java.lang.String path)
Default constructor. It uses either '\' or '/' character as a separator.

Parameters:
path - path to parse.

Path

public Path(java.lang.String path,
            char sep)
Constructor. Parses path from a string using custom separator.

Parameters:
path - path string to parse.
sep - custom separator to use.

Path

public Path(java.lang.String path,
            char[] seps)
Constructor. Parses path from a string using custom separators.

Parameters:
path - path string to parse.
seps - custom separators to use. Each character in this array is considered as a separator.
Method Detail

get

public java.lang.String get(int pos)
                     throws InvalidArgumentException
Returns n-th part of path (zero-based). Example,
      Path path = new Path(L"/usr/file.txt");
      System.println(path.get(0)); // prints 'user';
      System.println(path.get(1)); // prints 'file.txt'
      System.println(path.get(2)); // throws InvalidArgumentException
 

Parameters:
pos - position to return.
Returns:
n-th part of path.
Throws:
InvalidArgumentException - if pos is out of range.

subPath

public Path subPath(int pos,
                    int npos)
             throws InvalidArgumentException
Returns sub-path within the current path. If npos parameter is 0 and if pos is also 0 and the pass is not rooted empty path ("") is returned, otherwise empty rooted path ("/") is returned. Example,
      Path path = new Path(L"/usr/myproject/conf/config.xml");
      System.println( path.SubPath(1, 2) ); // prints '/myproject/conf'
      int length = path.getLength(); // length = 4
      System.println( path.getParent() ); // prints '/usr/myproject/conf'
 

Parameters:
pos - zero-based position to start with.
npos - number of positions to return.
Returns:
sub-path.
Throws:
InvalidArgumentException - if pos or npos are out of range.

isRooted

public boolean isRooted()
Determines whether path starts with the path separator.


getFilename

public java.lang.String getFilename()
                             throws InvalidArgumentException
Extracts file name from this path. Example,
      Path path = new Path(L"/usr/myproject/conf/config.xml");
      System.println( path.getFilename() ); // prints 'config.xml'
      System.println( path.getExtension() ); // prints '.xml'
 

Returns:
file name.
Throws:
InvalidArgumentException

getExtension

public java.lang.String getExtension()
                              throws InvalidArgumentException
Extracts file extension from path. See example of getFilename().

Returns:
file extension.
Throws:
InvalidArgumentException

getParent

public Path getParent()
               throws InvalidArgumentException
Gets parent path. See example of subPath().

Returns:
parent path.
Throws:
InvalidArgumentException

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

getLength

public int getLength()
Returns path length. See example of subPath().

Returns:
path length.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(java.lang.String sep)
Serializes this path using a custom separator.

Parameters:
sep - separator to use.
Returns:
serialized path.

append

public Path append(Path path)
Appends the path to this path. Neither this object no the path parameter is modified. A new path object is constructed and returned.

Parameters:
path - path to append to this object.
Returns:
resulting path.