org.apache.beehive.netui.core.urls
Class TemplatedURLFormatter

Object
  extended by TemplatedURLFormatter

public abstract class TemplatedURLFormatter
extends Object

Used by URLRewriterService to apply any relevant templates to a URL, after all other rewriting has been done on the URL.

Offers a mechanism for formatting URLs based on templates from a URL template config file. A template is chosen from a reference group based on the template type (key).

This class also contains the collection of known and required tokens it expects within URL templates it handles.

In general, an implementation of this abstract class should be thread-safe, not having state. If it is used as per-webapp default TemplatedURLFormatter, defined in beehive-netui-config.xml (with a class name), URLRewriterService.getTemplatedURL() will share the same instance (from the ServletContext - see getTemplatedURLFormatter(javax.servlet.ServletContext)) for multiple simultaneous requests.


Field Summary
protected  List _knownTokens
           
static String DEFAULT_TEMPLATE_REF
          The default name for a reference group.
static String DOMAIN_TOKEN
           
static String FRAGMENT_TOKEN
           
static String PATH_TOKEN
           
static String PORT_TOKEN
           
static String QUERY_STRING_TOKEN
           
protected  List requiredTokens
           
static String SCHEME_TOKEN
           
 
Constructor Summary
TemplatedURLFormatter()
           
 
Method Summary
 List getKnownTokens()
          Returns the list of the known tokens (strings) that this URL template formatter handles.
 List getRequiredTokens()
          Returns the list of the tokens (strings) that this URL template requires when formatting a URL with a template.
abstract  String getTemplatedURL(ServletContext servletContext, ServletRequest request, MutableURI uri, String key, URIContext uriContext)
          Format the given URL using a URL template, if defined in a URL template config file.
static TemplatedURLFormatter getTemplatedURLFormatter(ServletContext servletContext)
          Gets the TemplatedURLFormatter instance attribute of the ServletContext.
static void initServletContext(ServletContext servletContext, TemplatedURLFormatter formatter)
          Adds a given TemplatedURLFormatter instance as an attribute of the ServletContext.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TEMPLATE_REF

public static final String DEFAULT_TEMPLATE_REF
The default name for a reference group.

See Also:
Constant Field Values

SCHEME_TOKEN

public static final String SCHEME_TOKEN
See Also:
Constant Field Values

DOMAIN_TOKEN

public static final String DOMAIN_TOKEN
See Also:
Constant Field Values

PORT_TOKEN

public static final String PORT_TOKEN
See Also:
Constant Field Values

PATH_TOKEN

public static final String PATH_TOKEN
See Also:
Constant Field Values

QUERY_STRING_TOKEN

public static final String QUERY_STRING_TOKEN
See Also:
Constant Field Values

FRAGMENT_TOKEN

public static final String FRAGMENT_TOKEN
See Also:
Constant Field Values

_knownTokens

protected List _knownTokens

requiredTokens

protected List requiredTokens
Constructor Detail

TemplatedURLFormatter

public TemplatedURLFormatter()
Method Detail

getTemplatedURLFormatter

public static TemplatedURLFormatter getTemplatedURLFormatter(ServletContext servletContext)
Gets the TemplatedURLFormatter instance attribute of the ServletContext.

Parameters:
servletContext - the current ServletContext.
Returns:
the TemplatedURLFormatter instance from the ServletContext.

initServletContext

public static void initServletContext(ServletContext servletContext,
                                      TemplatedURLFormatter formatter)
Adds a given TemplatedURLFormatter instance as an attribute of the ServletContext.

Parameters:
servletContext - the current ServletContext.
formatter - the TemplatedURLFormatter instance to add as an attribute of the context

getKnownTokens

public List getKnownTokens()
Returns the list of the known tokens (strings) that this URL template formatter handles. These strings can be used for the template verification. Tokens are expected to be qualified in braces. E.g. {url:path}

Returns:
the list of strings for the known tokens

getRequiredTokens

public List getRequiredTokens()
Returns the list of the tokens (strings) that this URL template requires when formatting a URL with a template. These strings can be used for the template verification. Tokens are expected to be qualified in braces. E.g. {url:path}

Returns:
the list of strings for the known tokens

getTemplatedURL

public abstract String getTemplatedURL(ServletContext servletContext,
                                       ServletRequest request,
                                       MutableURI uri,
                                       String key,
                                       URIContext uriContext)
Format the given URL using a URL template, if defined in a URL template config file. The URIContext encapsulates some additional data needed to write out the string form. E.g. It defines if the "&" entity or the '&' character should be used to separate quary parameters.

Parameters:
servletContext - the current ServletContext.
request - the current ServletRequest.
uri - the MutableURI to be formatted into a String.
key - key for the URL template type to use for formatting the URI
uriContext - data required to write out the string form.
Returns:
the URL as a String