org.hippoecm.hst.core.util
Class Path

java.lang.Object
  extended by org.hippoecm.hst.core.util.Path
All Implemented Interfaces:
Serializable

public class Path
extends Object
implements Serializable

Overview

The Path object is used to standard used to standardize the creation of mutation of path-like structures. For: example /foo/bar/index.html.

Rules for Interperting Pathes

Below are the rules for how the constructor interprets literal paths. NOTE the addSegment(String) interprets string pathes in a somewhat different manner.

Literal Path Interpretation
/foo/bar/index.html foo and bar will be considered directory segments while index.html will be considered a file segment. This means that the baseName will be set to index and the fileExtension will be set to .html
/foo/bar/, /foo/bar, foo/bar/ foo/bar

foo and bar will be considered directory segments. baseName and fileExtension will be left as null.

I cases where a file has no extension you must use the setFileSegment(String)) to manually set the file. This causes the baseName to be set to the file name specified and the fileExtension will be set to the empty string ("").

Version:
$Id: Path.java 25188 2010-11-19 02:09:13Z wko $
See Also:
Serialized Form

Field Summary
static String PATH_SEPERATOR
           
 
Constructor Summary
Path()
           
Path(String path)
           
 
Method Summary
 Path addSegment(String segment)
           Adds this segment to the end of the path but before the current file segment, if one exists.
 boolean equals(Object obj)
           
 String getBaseName()
           
 Path getChild(Path childPath)
           
 Path getChild(String childPath)
           
 String getFileExtension()
           
 String getFileName()
           
 String getQueryString()
           
 String getSegment(int i)
          Returns the segement of the path at the specified index i.
 Path getSubPath(int beginAtSegment)
           
 Path getSubPath(int beginAtSegment, int endSegment)
           
 int hashCode()
           
 int length()
           
 Path removeLastPathSegment()
          Removes the last directory segment in this path.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

PATH_SEPERATOR

public static final String PATH_SEPERATOR
See Also:
Constant Field Values
Constructor Detail

Path

public Path()

Path

public Path(String path)
Method Detail

getSegment

public String getSegment(int i)
Returns the segement of the path at the specified index i.

Parameters:
i - index containing the segment to return.
Returns:
Segment at index i
Throws:
ArrayIndexOutOfBoundsException - if the index is not within the bounds of this Path.

addSegment

public Path addSegment(String segment)

Adds this segment to the end of the path but before the current file segment, if one exists. For consistency Segments added via this method are ALWAYS considered directories even when matching a standrad file pattern i.e. index.html

If you need to set the file segment, please use the setFileSegment() method.

Parameters:
segment -
Returns:

getSubPath

public Path getSubPath(int beginAtSegment)

getSubPath

public Path getSubPath(int beginAtSegment,
                       int endSegment)

getBaseName

public String getBaseName()

getFileExtension

public String getFileExtension()

getFileName

public String getFileName()

getQueryString

public String getQueryString()

length

public int length()

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

removeLastPathSegment

public Path removeLastPathSegment()
Removes the last directory segment in this path. This method WILL NOT remove the fileSegment, but path segment immediately before it.

Returns:
segment removed.

getChild

public Path getChild(String childPath)

getChild

public Path getChild(Path childPath)


Copyright © 2008-2012 Hippo. All Rights Reserved.