org.apache.jetspeed.util
Class Path

java.lang.Object
  extended by org.apache.jetspeed.util.Path
All Implemented Interfaces:
Serializable, Cloneable

public class Path
extends Object
implements Serializable, Cloneable

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 ("").

Author:
Scott T. Weaver
See Also:
Serialized Form

Field Summary
private  String baseName
           
private static HashMap childrenMap
           
private static String[] EMPTY_SEGMENTS
           
private  String fileExtension
           
private  String fileName
           
private  int hashCode
           
private  String path
           
static String PATH_SEPERATOR
           
private  String queryString
           
private  String[] segments
           
private static long serialVersionUID
          The serial version uid.
 
Constructor Summary
  Path()
           
private Path(Path parent)
           
private Path(Path parent, String[] children, boolean pathOnly)
           
private Path(Path parent, String childSegment, boolean pathOnly)
           
  Path(String path)
           
private Path(String[] segments, int offset, int count)
           
 
Method Summary
 Path addSegment(String segment)
           Adds this segment to the end of the path but before the current file segment, if one exists.
private  String buildPath()
           
 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.
private static String[] split(String str, int start, int length, char separator)
           
private static String[] splitPath(String path)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
The serial version uid.

See Also:
Constant Field Values

PATH_SEPERATOR

public static final String PATH_SEPERATOR
See Also:
Constant Field Values

EMPTY_SEGMENTS

private static final String[] EMPTY_SEGMENTS

childrenMap

private static HashMap childrenMap

path

private final String path

segments

private final String[] segments

fileName

private final String fileName

baseName

private final String baseName

fileExtension

private final String fileExtension

queryString

private final String queryString

hashCode

private final int hashCode
Constructor Detail

Path

public Path()

Path

private Path(Path parent,
             String childSegment,
             boolean pathOnly)

Path

private Path(Path parent,
             String[] children,
             boolean pathOnly)

Path

private Path(Path parent)

Path

private Path(String[] segments,
             int offset,
             int count)

Path

public Path(String path)
Method Detail

splitPath

private static String[] splitPath(String path)

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

buildPath

private String buildPath()

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)

split

private static String[] split(String str,
                              int start,
                              int length,
                              char separator)


Copyright © 1999-2007 Apache Software Foundation. All Rights Reserved.