org.weborganic.furi
Class URITemplate

java.lang.Object
  extended by org.weborganic.furi.URITemplate
All Implemented Interfaces:
Expandable
Direct Known Subclasses:
URIPattern

public class URITemplate
extends Object
implements Expandable

A URI Template for constructing URIs following the same structure. Instances of this class implement the URI templates as defined by the URI Template (Draft 3) by Joe Gregorio. A URI Template follows the URI syntax and can be expanded given a set of variable values.

Version:
5 November 2009
Author:
Christophe Lauret
See Also:
URI Template (draft 3)

Constructor Summary
URITemplate(String template)
          Creates a new URI Template instance.
URITemplate(String template, TokenFactory factory)
          Creates a new URI Template instance using the specified token factory.
 
Method Summary
static List<Token> digest(String template)
          Returns the list of tokens corresponding to the specified URI template.
static List<Token> digest(String template, TokenFactory factory)
          Returns the list of tokens corresponding to the specified URI template.
 boolean equals(Object o)
           
 String expand(Parameters parameters)
          Expands the template to produce a URI as defined by the URI Template specifications.
static String expand(String template, Parameters parameters)
          Method provided for convenience.
 int hashCode()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

URITemplate

public URITemplate(String template)
            throws IllegalArgumentException
Creates a new URI Template instance.

Parameters:
template - A String following the URI template syntax.
Throws:
NullPointerException - If the specified template is null.
URITemplateSyntaxException - If the string provided does not follow the proper syntax.
IllegalArgumentException

URITemplate

public URITemplate(String template,
                   TokenFactory factory)
            throws IllegalArgumentException
Creates a new URI Template instance using the specified token factory.

If the specified factory is null, the default is used.

Parameters:
template - A String following the URI template syntax.
factory - A token factory in order to choose the URI template syntax to use.
Throws:
NullPointerException - If the specified template is null.
URITemplateSyntaxException - If the string provided does not follow the proper syntax.
IllegalArgumentException
Method Detail

expand

public String expand(Parameters parameters)
Expands the template to produce a URI as defined by the URI Template specifications.

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

expand

public static String expand(String template,
                            Parameters parameters)
Method provided for convenience. It returns the same as:
 return new URITemplate(template).expand(variables);
 

Parameters:
template - The URI template.
parameters - The parameter values to use for substitution.
Returns:
The corresponding expanded URI.

digest

public static List<Token> digest(String template)
                          throws URITemplateSyntaxException
Returns the list of tokens corresponding to the specified URI template.

Parameters:
template - The URI template to digest.
Returns:
The corresponding list of URL tokens.
Throws:
URITemplateSyntaxException - If the string cannot be parsed.

digest

public static List<Token> digest(String template,
                                 TokenFactory factory)
                          throws URITemplateSyntaxException
Returns the list of tokens corresponding to the specified URI template.

Parameters:
template - The URI template to digest.
Returns:
The corresponding list of URL tokens.
Throws:
URITemplateSyntaxException - If the string cannot be parsed.

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object