org.weborganic.furi
Class TokenOperatorPS

java.lang.Object
  extended by org.weborganic.furi.TokenOperatorPS
All Implemented Interfaces:
Expandable, Matchable, Token, TokenOperator

public class TokenOperatorPS
extends Object
implements TokenOperator, Matchable

A token based on the operators used in PageSeeder.

This syntax borrows heavily from a suggestion made by Roy T. Fielding on the W3C URI list and regarding the URI Template draft specification.

  instruction   = "{" [ operator ] variable-list "}"
  operator      = "/" / "+" / ";" / "?" / op-reserve
  variable-list =  varspec *( "," varspec )
  varspec       =  [ var-type ] varname [ ":" prefix-len ] [ "=" default ]
  var-type      = "@" / "%" / type-reserve
  varname       = ALPHA *( ALPHA | DIGIT | "_" )
  prefix-len    = 1*DIGIT
  default       = *( unreserved / reserved )
  op-reserve    = <anything else that isn't ALPHA or operator>
  type-reserve  = <anything else that isn't ALPHA, ",", or operator>
 

Version:
6 November 2009
Author:
Christophe Lauret
See Also:
Re: URI Templates? from Roy T. Fielding on 2008-09-16 (uri@w3.org)

Nested Class Summary
static class TokenOperatorPS.Operator
          The list of operators currently supported.
 
Constructor Summary
TokenOperatorPS(TokenOperatorPS.Operator op, List<Variable> vars)
          Creates a new operator token.
TokenOperatorPS(TokenOperatorPS.Operator op, Variable var)
          Creates a new operator token for one variable only.
 
Method Summary
 boolean equals(Object o)
          Two tokens are equals if and only if their string expression is equal.
 String expand(Parameters parameters)
          Expands the token operator using the specified parameters.
 String expression()
          The expression corresponding to this token.
 int hashCode()
          
 boolean isResolvable()
          Indicates whether this token can be resolved.
 boolean match(String part)
          Indicates whether this token matches the specified part of a URL.
 TokenOperatorPS.Operator operator()
          Returns the operator part of this token.
static TokenOperatorPS parse(String exp)
          Parses the specified string and returns the corresponding token.
 Pattern pattern()
          Returns a regular expression pattern corresponding to this object.
 boolean resolve(String expanded, Map<Variable,Object> values)
          Resolves the specified expanded URI part for this token.
static TokenOperatorPS.Operator toOperator(char c)
          Returns the operator if it is defined in this class.
 String toString()
          
 List<Variable> variables()
          Returns the list of variables used in this token.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.weborganic.furi.Token
expression
 

Constructor Detail

TokenOperatorPS

public TokenOperatorPS(TokenOperatorPS.Operator op,
                       Variable var)
                throws NullPointerException
Creates a new operator token for one variable only.

Parameters:
op - The operator to use.
var - The variable for this operator.
Throws:
NullPointerException - If any of the argument is null.

TokenOperatorPS

public TokenOperatorPS(TokenOperatorPS.Operator op,
                       List<Variable> vars)
                throws NullPointerException
Creates a new operator token.

Parameters:
op - The operator to use.
vars - The variables for this operator.
Throws:
NullPointerException - If any of the argument is null.
Method Detail

expand

public String expand(Parameters parameters)
Expands the token operator using the specified parameters.

Specified by:
expand in interface Expandable
Parameters:
parameters - The parameters for variable substitution.
Returns:
The corresponding expanded string.

operator

public TokenOperatorPS.Operator operator()
Returns the operator part of this token.

Returns:
the operator.

variables

public List<Variable> variables()
Returns the list of variables used in this token.

Specified by:
variables in interface TokenOperator
Returns:
the list of variables.

isResolvable

public boolean isResolvable()
Indicates whether this token can be resolved.

A resolvable token contains variables which can be resolved. By default a token is resolvable if it can be matched.

Specified by:
isResolvable in interface Token
Returns:
true if variables can be resolved from the specified pattern; false otherwise.

resolve

public boolean resolve(String expanded,
                       Map<Variable,Object> values)
Resolves the specified expanded URI part for this token.

The resolution process requires all variables referenced in the token to be mapped to the value that is present in the expanded URI data.

Specified by:
resolve in interface Token
Parameters:
expanded - The part of the URI that correspond to an expanded version of the token.
values - The variables mapped to their values as a result of resolution.
Returns:
true this operation was successful; false otherwise.

match

public boolean match(String part)
Indicates whether this token matches the specified part of a URL.

Specified by:
match in interface Matchable
Parameters:
part - The part of URL to test for matching.
Returns:
true if it matches; false otherwise.

pattern

public Pattern pattern()
Returns a regular expression pattern corresponding to this object.

Specified by:
pattern in interface Matchable
Returns:
The regular expression pattern corresponding to this object.

toOperator

public static TokenOperatorPS.Operator toOperator(char c)
Returns the operator if it is defined in this class.

Parameters:
c - The character representation of the operator.
Returns:
The corresponding operator instance.

parse

public static TokenOperatorPS parse(String exp)
                             throws URITemplateSyntaxException
Parses the specified string and returns the corresponding token. This method accepts both the raw expression or the expression wrapped in curly brackets.

Parameters:
exp - The expression to parse.
Returns:
The corresponding token.
Throws:
URITemplateSyntaxException - If the string cannot be parsed as a valid

expression

public String expression()
The expression corresponding to this token.

Specified by:
expression in interface Token
Returns:
The expression corresponding to this token.

equals

public boolean equals(Object o)
Two tokens are equals if and only if their string expression is equal.

Overrides:
equals in class Object

hashCode

public int hashCode()

Overrides:
hashCode in class Object

toString

public String toString()

Overrides:
toString in class Object