Package com.yahoo.restapi
Class Path
- java.lang.Object
-
- com.yahoo.restapi.Path
-
public class Path extends java.lang.Object
A path which is able to match strings containing bracketed placeholders and return the values given at the placeholders. The path is split on '/', and each part is then URL decoded. E.g a path /a/1/bar/fuz/baz/%62%2f will match /a/{foo}/bar/{b}/baz/{c} and return foo=1, b=fuz, and c=c/ Only full path elements may be placeholders, i.e /a{bar} is not interpreted as one. If the path spec ends with /{*}, it will match urls with any rest path. The rest path (not including the trailing slash) will be available as getRest(). Note that for convenience in common use this has state which changes as a side effect of each matches invocation. It is therefore for single thread use. An optional prefix can be used to match the path spec against an alternative path. This is used when you have alternative paths mapped to the same resource.- Author:
- bratseth
-
-
Constructor Summary
Constructors Constructor Description Path(java.lang.String path)
Deprecated.usePath(URI)
for correct handling of URL encoded paths.Path(java.lang.String path, java.lang.String optionalPrefix)
Deprecated.usePath(URI, String)
for correct handling of URL encoded paths.Path(java.net.URI uri)
Path(java.net.URI uri, java.lang.String optionalPrefix)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
asString()
java.lang.String
get(java.lang.String placeholder)
Returns the value of the given template variable in the last path matched, or null if the previous matches call returned false or if this has not matched anything yet.java.lang.String
getRest()
Returns the rest of the last matched path.boolean
matches(java.lang.String pathSpec)
Parses the path according to pathSpec - must be called prior toget(java.lang.String)
Returns whether this path matches the given template string.java.lang.String
toString()
-
-
-
Constructor Detail
-
Path
@Deprecated public Path(java.lang.String path)
Deprecated.usePath(URI)
for correct handling of URL encoded paths.
-
Path
@Deprecated public Path(java.lang.String path, java.lang.String optionalPrefix)
Deprecated.usePath(URI, String)
for correct handling of URL encoded paths.
-
Path
public Path(java.net.URI uri)
-
Path
public Path(java.net.URI uri, java.lang.String optionalPrefix)
-
-
Method Detail
-
matches
public boolean matches(java.lang.String pathSpec)
Parses the path according to pathSpec - must be called prior toget(java.lang.String)
Returns whether this path matches the given template string. If the given template has placeholders, their values (accessible by get) are reset by calling this, whether or not the path matches the given template. This will NOT match empty path elements.- Parameters:
pathSpec
- the path string to match to this- Returns:
- true if the string matches, false otherwise
-
get
public java.lang.String get(java.lang.String placeholder)
Returns the value of the given template variable in the last path matched, or null if the previous matches call returned false or if this has not matched anything yet.
-
getRest
public java.lang.String getRest()
Returns the rest of the last matched path. This is always the empty string (never null) unless the path spec ends with {*}
-
asString
public java.lang.String asString()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-