org.weborganic.furi
Class TokenVariable

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

public class TokenVariable
extends Object
implements Token, Matchable

A URI token wrapping a variable.

Variables follow the following expression:

 var         = varname [ "=" vardefault ]
 varname     = (ALPHA / DIGIT)*(ALPHA / DIGIT / "." / "_" / "-" )
 vardefault  = *(unreserved / pct-encoded)
 

Version:
30 December 2008
Author:
Christophe Lauret

Constructor Summary
TokenVariable(String exp)
          Creates a new variable token.
TokenVariable(Variable var)
          Creates a new variable token.
 
Method Summary
 boolean equals(Object o)
          Two tokens are equals if and only if their string expression is equal.
 String expand(Parameters variables)
          Expands this object to produce a URI fragment as defined by the URI Template specifications.
 String expression()
          The expression corresponding to this token.
 Variable getVariable()
          Returns the variable wrapped by this token.
 int hashCode()
          
 boolean isResolvable()
          Indicates whether this token can be resolved.
 boolean match(String value)
          Indicates whether this token matches the specified part of a URL.
 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.
 String toString()
          
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.weborganic.furi.Token
expression, isResolvable
 

Constructor Detail

TokenVariable

public TokenVariable(String exp)
              throws NullPointerException,
                     URITemplateSyntaxException
Creates a new variable token.

Parameters:
exp - The expression to create a new.
Throws:
NullPointerException - If the specified expression is null.
URITemplateSyntaxException - If the specified expression could not be parsed as a variable.

TokenVariable

public TokenVariable(Variable var)
              throws NullPointerException
Creates a new variable token.

Parameters:
var - The variable this token corresponds to.
Throws:
NullPointerException - If the specified text is null.
Method Detail

getVariable

public Variable getVariable()
Returns the variable wrapped by this token.

Returns:
The variable wrapped by this token.

expand

public String expand(Parameters variables)
Expands this object to produce a URI fragment as defined by the URI Template specifications.

Specified by:
expand in interface Expandable
Parameters:
variables - The list of parameters and their values for substitution.
Returns:
The expanded URI fragment

match

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

Specified by:
match in interface Matchable
Parameters:
value - 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.

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.

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.

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