com.bea.content
Class PathHelper

java.lang.Object
  extended by com.bea.content.PathHelper

public class PathHelper
extends Object

Utility class to manipulate unix path like Strings such as /a/b/c/d. Paths are always expected to begin with / and end without it. Therefore neither a/b/c or /a/b/c/ are considered valid. Most operations take a path which must be in correct form and also an element to add/remove from the path. This element must not contain the SEPARATOR / as any part of itself.


Field Summary
static String SEPARATOR
          The path separator used by the Federated content API and the WLP Repository for all path values.
 
Constructor Summary
PathHelper()
           
 
Method Summary
static String addFirst(String first, String path)
          Adds a new element to the front of a path.
static String addLast(String path, String last)
          Adds a new element to the end of a path.
static String buildFederatedPath(String repositoryPath, String repositoryName)
           
static String buildRepositoryPath(String federatedPath, String repositoryName)
           
static int countNodes(String path)
          Returns the number of nodes in the path.
static String getFirst(String path)
          Gets the first element in the path.
static String getLast(String path)
          Gets the last element in the path.
static String getLineage(String path)
          Removes the last element and returns the result.
static int getNameCount(String path)
          Gets the number of Nodes in the path.
static String getParentName(String path)
          Gets the second to last element in a path.
static List getPathAsList(String path)
          Converts a path into it's lineage and returns a list of strings.
static List<String> getPathItemsAsList(String path)
          Converts a path into a list of each of it's items as strings.
static String getSubPath(String path, int size)
          Returns the lineage with the number of parents specified.
static boolean isValid(String path)
          Checks if the path is valid: must be non null must be > 0 characters must start with a SEPARATOR must not end with a SEPARATOR
static String removeFirst(String path)
          Removes the first element from path and returns the result.
static String removeLast(String path)
          Removes the last element from path and returns the result.
static String removeLast(String path, int i)
          Removes the last i number of elements from path and returns the result.
static String trimPath(String path, int size)
          Trims the path to the given size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEPARATOR

public static final String SEPARATOR
The path separator used by the Federated content API and the WLP Repository for all path values.

See Also
Constants Summary
Constructor Detail

PathHelper

public PathHelper()
Method Detail

buildRepositoryPath

public static String buildRepositoryPath(String federatedPath,
                                         String repositoryName)
                                  throws RepositoryException
Throws
RepositoryException

buildFederatedPath

public static String buildFederatedPath(String repositoryPath,
                                        String repositoryName)
                                 throws RepositoryException
Throws
RepositoryException

isValid

public static boolean isValid(String path)
Checks if the path is valid:
  • must be non null
  • must be > 0 characters
  • must start with a SEPARATOR
  • must not end with a SEPARATOR

    Parameters
    path - - the path to validate
    Returns
    true if the above are fullfilled, false if the path is incorrect

  • addLast

    public static String addLast(String path,
                                 String last)
    Adds a new element to the end of a path. For example last = last and path = /a/b/c would return /a/b/c/last.

    Parameters
    path - - the path to add an element to.
    Returns
    the updated path

    addFirst

    public static String addFirst(String first,
                                  String path)
    Adds a new element to the front of a path. For example first = first and path = /a/b/c would return /first/a/b/c.

    Parameters
    first - - the element to add. Must not contain / as part of the String.
    path - - the path to add an element to.
    Returns
    the updated path

    getLast

    public static String getLast(String path)
    Gets the last element in the path. For example, /a/b/c/last would return last


    getFirst

    public static String getFirst(String path)
    Gets the first element in the path. For example, /first/a/b/c would return first.


    getParentName

    public static String getParentName(String path)
    Gets the second to last element in a path. For example, /a/b/c/parent/e would return parent


    getPathAsList

    public static List getPathAsList(String path)
    Converts a path into it's lineage and returns a list of strings. So for example the path "a/b/c/d" would return a list of string objects : "a/b/c/d", "a/b/c", "a/b", "a"

    Parameters
    path -
    Returns
    A list of strings

    getPathItemsAsList

    public static List<String> getPathItemsAsList(String path)
    Converts a path into a list of each of it's items as strings. So for example the path "a/b/c/d" would return a list of string objects : "a", "b", "c", "d"

    Parameters
    path -
    Returns
    A list of strings

    removeFirst

    public static String removeFirst(String path)
    Removes the first element from path and returns the result. For example, /first/a/b/c would return /a/b/c If there is only one element then return an empty String.


    removeLast

    public static String removeLast(String path)
    Removes the last element from path and returns the result. For example, /a/b/c/last would return /a/b/c If there is only one element then return an empty String.


    removeLast

    public static String removeLast(String path,
                                    int i)
    Removes the last i number of elements from path and returns the result. For example, /a/b/c/last where i=2 would return /a/b If there is only one element then return an empty String.


    countNodes

    public static int countNodes(String path)
    Returns the number of nodes in the path.


    getLineage

    public static String getLineage(String path)
    Removes the last element and returns the result. For example, /a/b/c/d would return /a/b/c


    trimPath

    public static String trimPath(String path,
                                  int size)
    Trims the path to the given size. For example, path = /one/two/three/four and size = 10 would return /one/two/t


    getSubPath

    public static String getSubPath(String path,
                                    int size)
    Returns the lineage with the number of parents specified. For example, /a/b/c/d/e with a size of 3 would return /a/b/c


    getNameCount

    public static int getNameCount(String path)
    Gets the number of Nodes in the path. For example, /a/b/c/d would return 4.



    Copyright © 2000, 2008, Oracle and/or its affiliates. All rights reserved.
    Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
    Other names may be trademarks of their respective owners.