org.jproggy.snippetory
Class TemplateContext

java.lang.Object
  extended by org.jproggy.snippetory.TemplateContext
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
Repo.TemplateContext

public class TemplateContext
extends Object
implements Cloneable

The TemplateContext represents the configuration how templates are parsed. It provides a fluent interface for inline creation as well as a bean interface for convenient injection. Using the injection variant it's also easy to use a subclass and use a different parsing mechanism or place an additional layer of interceptors.

Caution: As the TemplateContext is a mutable construct it has to be considered single threaded! For reuse over several threads one would need to ensure immutability. However, the clone method allows fast creation of copies.


Constructor Summary
TemplateContext()
           
 
Method Summary
 TemplateContext attrib(String name, String value)
           
 TemplateContext clone()
           
 TemplateContext encoding(Encoding encoding)
           
 TemplateContext encoding(String encoding)
           
 Map<String,String> getBaseAttribs()
          Returns the attributes intended to be set on the root node of a template created by one of the parse methods.
 Locale getLocale()
           
 Syntax getSyntax()
           
 Template getTemplate(String uri)
          Get the Template identified by the uri.
 UriResolver getUriResolver()
           
 TemplateContext locale(Locale locale)
           
 void setBaseAttribs(Map<String,String> baseAttribs)
           
 void setLocale(Locale locale)
           
 void setSyntax(Syntax syntax)
           
 void setUriResolver(UriResolver uriResolver)
           
 TemplateContext syntax(Syntax syntax)
           
 TemplateContext syntax(SyntaxID syntax)
           
 TemplateContext uriResolver(UriResolver uriResolver)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TemplateContext

public TemplateContext()
Method Detail

clone

public TemplateContext clone()
Overrides:
clone in class Object

syntax

public TemplateContext syntax(SyntaxID syntax)

syntax

public TemplateContext syntax(Syntax syntax)

getSyntax

public Syntax getSyntax()

setSyntax

public void setSyntax(Syntax syntax)

uriResolver

public TemplateContext uriResolver(UriResolver uriResolver)

setUriResolver

public void setUriResolver(UriResolver uriResolver)

getUriResolver

public UriResolver getUriResolver()

encoding

public TemplateContext encoding(String encoding)

encoding

public TemplateContext encoding(Encoding encoding)

locale

public TemplateContext locale(Locale locale)

getLocale

public Locale getLocale()

setLocale

public void setLocale(Locale locale)

attrib

public TemplateContext attrib(String name,
                              String value)

getBaseAttribs

public Map<String,String> getBaseAttribs()
Returns the attributes intended to be set on the root node of a template created by one of the parse methods. This makes especially sense for inherited attributes. Expect the returned map to be unmodifiable. I.e. copy via copy constructor and set newly if you want to extend it.

Returns:

setBaseAttribs

public void setBaseAttribs(Map<String,String> baseAttribs)

getTemplate

public Template getTemplate(String uri)
Get the Template identified by the uri. The uri is resolved by the configured uri resolver. Thus configuring a UriRelover is mandatory,