org.loom.mapping
Class UriParser

java.lang.Object
  extended by org.loom.mapping.UriParser

public class UriParser
extends java.lang.Object

Parses an incoming request and extracts any parameter values in its path. The expected format is (handle(\{param1(\?)?})?)+ Example: /entries/{param1}/{param2?} where param1 is required and param2 is not


Constructor Summary
UriParser()
           
 
Method Summary
 void addToken(UriToken token)
           
 java.lang.String format(com.google.common.collect.ListMultimap<java.lang.String,java.lang.String> params)
          Produce a String which is this parser representation with the provided parameters
 void format(java.lang.StringBuilder builder, com.google.common.collect.ListMultimap<java.lang.String,java.lang.String> params)
           
 java.util.Set<java.lang.String> getParameterNames()
           
 java.util.List<UriToken> getTokens()
           
static UriParser newInstance(java.lang.String expression)
          Create a new UriParser based on the uri expression
 boolean overlaps(UriParser uriParser)
           
 java.util.Map<java.lang.String,java.lang.String> parse(java.lang.String uri)
          Parse the provided URI and return a list of the parameters that were found.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UriParser

public UriParser()
Method Detail

newInstance

public static UriParser newInstance(java.lang.String expression)
Create a new UriParser based on the uri expression

Parameters:
expression - the String to be parsed, in the form '/controller/{param1}/{param2}' or similar.
Returns:
the instantiated RequestUriParser

parse

public java.util.Map<java.lang.String,java.lang.String> parse(java.lang.String uri)
Parse the provided URI and return a list of the parameters that were found.

Parameters:
uri - the uri to be parsed
Returns:
the parsed list of parameters, null if the provided uri was not a match.

addToken

public void addToken(UriToken token)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getTokens

public java.util.List<UriToken> getTokens()

format

public java.lang.String format(com.google.common.collect.ListMultimap<java.lang.String,java.lang.String> params)
Produce a String which is this parser representation with the provided parameters

Parameters:
params - the list of parameters to be included
Returns:
the String URI with the provided params
Throws:
java.lang.IllegalArgumentException - if any required parameter is missing or there is more than one value for the same parameter

format

public void format(java.lang.StringBuilder builder,
                   com.google.common.collect.ListMultimap<java.lang.String,java.lang.String> params)

getParameterNames

public java.util.Set<java.lang.String> getParameterNames()

overlaps

public boolean overlaps(UriParser uriParser)
Returns:
true if this UriParser can produce the same URI as the provided one