it.eng.spago.cms.util
Class Path

java.lang.Object
  extended by it.eng.spago.cms.util.Path

public class Path
extends java.lang.Object

Utilities useful for manipulate the path of an elements. The methods of the class allow to control the format of the path, to obtain the Ancestor Path and to perform checks.


Constructor Summary
Path()
           
 
Method Summary
static Path create(java.lang.String pathStr)
          Creates the pathObject relative to a path string.
 boolean equals(Path path)
          Cheks the equality between the current path object and another one.
 java.lang.String getAbsPathStr()
          Returns the path in absolute string format.
 java.util.Vector getElements()
          Returns the Vector of element that compose the path
 java.lang.String getNameLastElement()
          Returns the name of the last element of the path (which is the name of the node).
 Path getPathAncestor(int deep)
          Returns the object path of an ancestor of the path.
 java.lang.String getRootRelativePathStr()
          Returns the path in string format relative to root node.
 boolean isAncestorOf(Path path)
          Checks if the path is an ancestor of another.
static boolean isMalformedPathString(java.lang.String pathStr)
          Checks if a path is expressed using the right format.
 boolean isRootNode()
          Checks if the path corresponds to the root node of the content management tree.
 void setElements(java.util.Vector elements)
          Set the Vector of elements which compose tha path
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Path

public Path()
Method Detail

create

public static Path create(java.lang.String pathStr)
                   throws PathNotValidException
Creates the pathObject relative to a path string. An Example of correct path is: /usr/local/program. A path must always start with the char '/' but can not end with it. If path is not in the correct format a PathNotValidException will be thrown.

Parameters:
pathStr - the string of the path
Returns:
A Path Object representing the string path
Throws:
PathNotValidException - Thrown if the path is not expressed with the correct format

isMalformedPathString

public static boolean isMalformedPathString(java.lang.String pathStr)
Checks if a path is expressed using the right format.

Parameters:
pathStr - path string to check
Returns:
boolean, true if path hasn't a right format, false otherwise

equals

public boolean equals(Path path)
Cheks the equality between the current path object and another one. Two path are equal if they possess the same number of elements, and if all the elements are equal.

Parameters:
path - Path object to compare
Returns:
boolean, true if paths are equals and false otherwise

isAncestorOf

public boolean isAncestorOf(Path path)
Checks if the path is an ancestor of another. A path is ancestor of another if all its elements are equal and in the same order to those at the begin of the other path. Example: "/usr/local/program" is an ancestor of "/usr/local/program/myprogram"

Parameters:
path - Path to check
Returns:
boolean, true if path is ancestor false otherwise

isRootNode

public boolean isRootNode()
Checks if the path corresponds to the root node of the content management tree. If the path is equal to the root path his vector elements is empty.

Returns:
boolean, true if path is equals to the one of the root node, false otherwise

getAbsPathStr

public java.lang.String getAbsPathStr()
Returns the path in absolute string format. The string path starts with "/" and it's the entire path of the node Example: "/usr/local/program"

Returns:
String, the entire absolute path of the node

getRootRelativePathStr

public java.lang.String getRootRelativePathStr()
Returns the path in string format relative to root node. The path string returned doesn't starts with "/" and it's the entire path of the node. This method is very useful to retrive nodes, using paths, from root node. Example: "usr/local/program"

Returns:
String, the entire string path of the node

getNameLastElement

public java.lang.String getNameLastElement()
Returns the name of the last element of the path (which is the name of the node). Example: if the path is "/usr/local/program" the method will return "program".

Returns:
String, name of the last element of the path

getPathAncestor

public Path getPathAncestor(int deep)
Returns the object path of an ancestor of the path. The search depth of the ancestors is given from the parameter in input: If the deep search is greater than the number of elements of the path the method returns null.

Parameters:
deep, - the number of back steps to do in order to find the ancestor
Returns:
Path, the object path of the ancestor found or null if the ancestor has not been found

getElements

public java.util.Vector getElements()
Returns the Vector of element that compose the path

Returns:
Vector of elements that compose the path.

setElements

public void setElements(java.util.Vector elements)
Set the Vector of elements which compose tha path

Parameters:
elements - Vector of elements of the path