org.apache.beehive.netui.core.urltemplates
Class URLTemplate

Object
  extended by URLTemplate

public class URLTemplate
extends Object

The class to format a URL defined by url-template-config template given by values for a set of tokens.


Nested Class Summary
protected  class URLTemplate.TemplateItem
           
 
Constructor Summary
URLTemplate(String template, Collection<String> knownTokens, Collection<String> requiredTokens)
          Create a URLTemplate from a url-template-config template.
URLTemplate(URLTemplate template)
          Copy constructor to create a URLTemplate from an existing URLTemplate.
 
Method Summary
 String getTemplate()
          Retrieve the String form of the template.
 void setTemplate(String template)
          Reset the String form of the template.
 void substitute(Map<String,String> tokensAndValues)
          Replace a set of tokens in the template with a corresponding set of values.
 void substitute(String token, int value)
          Replace a single token in the template with a corresponding int value.
 void substitute(String token, String value)
          Replace a single token in the template with a corresponding String value.
 String toString()
          Return the String representation of the template after replacing all tokens with their associated values..
 void verify()
          Verification will ensure the URL template conforms to a valid format for known tokens and contains the required tokens.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

URLTemplate

public URLTemplate(String template,
                   Collection<String> knownTokens,
                   Collection<String> requiredTokens)
Create a URLTemplate from a url-template-config template.

Allow clients to define a set of required and known tokens for the template verification. Tokens are expected to be qualified in braces. E.g. {url:path}

The template verification will ensure the URL template conforms to a valid format for known tokens and contains the required tokens.

Should call verify after creating a new template.

Parameters:
template - the string form of the template from url-template-config.
knownTokens - The set of known tokens for a valid template.
requiredTokens - The set of required tokens in a valid template.

URLTemplate

public URLTemplate(URLTemplate template)
Copy constructor to create a URLTemplate from an existing URLTemplate.

Note that this is not truly a complete copy because the Map of the replacement values for the given tokens is not copied. This copy will just have an empty map of token values so that it is "cleared" and ready to format another URL.

Parameters:
template - the URLTemplate to copy.
Method Detail

setTemplate

public void setTemplate(String template)
Reset the String form of the template.

Should call verify after setting a new template.

Parameters:
template - the string form of the template from url-template-config.

getTemplate

public String getTemplate()
Retrieve the String form of the template.

Returns:
the string form of the template.

verify

public void verify()
            throws IllegalStateException
Verification will ensure the URL template conforms to a valid format for known tokens and contains the required tokens. It will also parse the tokens and literal data into a list to improve the replacement performance when constructing the final URL string.

Throws:
IllegalStateException

substitute

public void substitute(Map<String,String> tokensAndValues)
Replace a set of tokens in the template with a corresponding set of values. This assumes that there is an ordered one-to-one relationship. Tokens are expected to be qualified in braces. E.g. {url:path}


substitute

public void substitute(String token,
                       String value)
Replace a single token in the template with a corresponding String value. Tokens are expected to be qualified in braces. E.g. {url:path}


substitute

public void substitute(String token,
                       int value)
Replace a single token in the template with a corresponding int value. Tokens are expected to be qualified in braces. E.g. {url:port}


toString

public String toString()
Return the String representation of the template after replacing all tokens with their associated values..

Overrides:
toString in class Object