org.rundeck.storage.api
Class PathUtil

java.lang.Object
  extended by org.rundeck.storage.api.PathUtil

public class PathUtil
extends java.lang.Object

Utility methods for paths


Nested Class Summary
static class PathUtil.PathImpl
           
 
Field Summary
static Path ROOT
           
static java.lang.String SEPARATOR
           
 
Constructor Summary
PathUtil()
           
 
Method Summary
static PathSelector allpathSelector()
           
static
<T extends ContentMeta>
ResourceSelector<T>
allResourceSelector()
          A resource selector which always matches
static Path appendPath(Path prefix, java.lang.String subpath)
          Append one path to another
static java.lang.String appendPath(java.lang.String prefixPath, java.lang.String subpath)
          Append one path to another
static Path asPath(java.lang.String path)
           
static java.lang.String cleanPath(java.lang.String path)
          Clean the path string by removing leading and trailing slashes and removing duplicate slashes.
static
<T extends ContentMeta>
ResourceSelector<T>
composeSelector(ResourceSelector<T> a, ResourceSelector<T> b, boolean and)
          compose two selectors
static
<T extends ContentMeta>
ResourceSelector<T>
exactMetadataResourceSelector(java.util.Map<java.lang.String,java.lang.String> required, boolean requireAll)
          A resource selector which requires metadata values to be equal to some required strings
static boolean hasRoot(Path path, Path root)
          Return true if the given path starts with the given root
static boolean hasRoot(java.lang.String path, java.lang.String root)
          Return true if the given path starts with the given root
static boolean isRoot(Path path)
          Return true if the path is the root
static boolean isRoot(java.lang.String path)
          Return true if the path is the root
static Path parentPath(Path path)
           
static java.lang.String parentPathString(java.lang.String path)
          Return the string representing the parent of the given path
static Path pathFromComponents(java.lang.String[] components)
          create a path from an array of components
static java.lang.String pathName(java.lang.String path)
           
static java.lang.String pathStringFromComponents(java.lang.String[] components)
          create a path from an array of components
static
<T extends ContentMeta>
ResourceSelector<T>
regexMetadataResourceSelector(java.util.Map<java.lang.String,java.lang.String> required, boolean requireAll)
          A resource selector which requires metadata values to match regexes
static java.lang.String removePrefix(java.lang.String rootPath, java.lang.String extpath)
           
static
<T extends ContentMeta>
ResourceSelector<T>
resourceSelector(java.lang.String selector)
          Return a ResourceSelector constructed using this selector syntax:
static PathSelector subpathSelector(Path rootPath)
          A Path selector that matches the given root path and any resource below it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEPARATOR

public static final java.lang.String SEPARATOR
See Also:
Constant Field Values

ROOT

public static final Path ROOT
Constructor Detail

PathUtil

public PathUtil()
Method Detail

asPath

public static Path asPath(java.lang.String path)

pathFromComponents

public static Path pathFromComponents(java.lang.String[] components)
create a path from an array of components

Parameters:
components -
Returns:

pathStringFromComponents

public static java.lang.String pathStringFromComponents(java.lang.String[] components)
create a path from an array of components

Parameters:
components -
Returns:

hasRoot

public static boolean hasRoot(Path path,
                              Path root)
Return true if the given path starts with the given root

Parameters:
path -
root -
Returns:

hasRoot

public static boolean hasRoot(java.lang.String path,
                              java.lang.String root)
Return true if the given path starts with the given root

Parameters:
path -
root -
Returns:

parentPath

public static Path parentPath(Path path)

isRoot

public static boolean isRoot(java.lang.String path)
Return true if the path is the root

Parameters:
path -
Returns:

isRoot

public static boolean isRoot(Path path)
Return true if the path is the root

Parameters:
path -
Returns:

parentPathString

public static java.lang.String parentPathString(java.lang.String path)
Return the string representing the parent of the given path

Parameters:
path - path string
Returns:
parent path string

cleanPath

public static java.lang.String cleanPath(java.lang.String path)
Clean the path string by removing leading and trailing slashes and removing duplicate slashes.

Parameters:
path - input path
Returns:
cleaned path string

pathName

public static java.lang.String pathName(java.lang.String path)

removePrefix

public static java.lang.String removePrefix(java.lang.String rootPath,
                                            java.lang.String extpath)

appendPath

public static Path appendPath(Path prefix,
                              java.lang.String subpath)
Append one path to another

Parameters:
prefix - prefix
subpath - sub path
Returns:
sub path appended to the prefix

appendPath

public static java.lang.String appendPath(java.lang.String prefixPath,
                                          java.lang.String subpath)
Append one path to another

Parameters:
prefixPath - prefix
subpath - sub path
Returns:
sub path appended to the prefix

subpathSelector

public static PathSelector subpathSelector(Path rootPath)
A Path selector that matches the given root path and any resource below it.

Parameters:
rootPath -
Returns:

allpathSelector

public static PathSelector allpathSelector()

exactMetadataResourceSelector

public static <T extends ContentMeta> ResourceSelector<T> exactMetadataResourceSelector(java.util.Map<java.lang.String,java.lang.String> required,
                                                                                        boolean requireAll)
A resource selector which requires metadata values to be equal to some required strings

Type Parameters:
T - content type
Parameters:
required - required metadata strings
requireAll - if true, require all values are equal, otherwise require one value to be equal
Returns:
selector for resources with all or some required metadata values

regexMetadataResourceSelector

public static <T extends ContentMeta> ResourceSelector<T> regexMetadataResourceSelector(java.util.Map<java.lang.String,java.lang.String> required,
                                                                                        boolean requireAll)
A resource selector which requires metadata values to match regexes

Type Parameters:
T - content type
Parameters:
required - required metadata regexes
requireAll - if true, require all values match regexes, otherwise require one value to match the regex
Returns:
selector for resources with all or some matching metadata values

composeSelector

public static <T extends ContentMeta> ResourceSelector<T> composeSelector(ResourceSelector<T> a,
                                                                          ResourceSelector<T> b,
                                                                          boolean and)
compose two selectors

Type Parameters:
T -
Parameters:
a -
b -
and - true indicates AND, otherwise OR
Returns:
new selector appyling the operator to the selector

allResourceSelector

public static <T extends ContentMeta> ResourceSelector<T> allResourceSelector()
A resource selector which always matches

Type Parameters:
T - content type
Returns:
selector

resourceSelector

public static <T extends ContentMeta> ResourceSelector<T> resourceSelector(java.lang.String selector)
Return a ResourceSelector constructed using this selector syntax:
 key OP value [; key OP value]*
 
OP can be "=" (exact match) or "=~" (regular expression match).
The returned selector effectively "AND"s the match requirements.
The special string "*" equates to allResourceSelector()

Parameters:
selector - the selector syntax string to parse, not null
Returns:
a resource selector corresponding to the parsed selector string