|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsimple.template.freemarker.FreemarkerContainer
public class FreemarkerContainer
The FreemarkerContainer
provides an implementation
of the Container
object for Freemarker.
This can be used with a TemplateEngine
to provide
template documents written in the Freemarker Templating Language
(FTL) to service objects. This container will use a template
root that is the root of the Context
specified.
A subclassed implementation of this Container
typically implements the lookup(String)
method
inorder to populate a database with various tools or objects.
This can done by creating a SimpleHash
instance
and delegating to the lookup(String, Object)
method once the SimpleHash
has been populated.
Configuration
Field Summary | |
---|---|
protected freemarker.template.SimpleHash |
data
The internal storage used by this instance. |
Constructor Summary | |
---|---|
FreemarkerContainer()
Constructor for the FreemarkerContainer object. |
|
FreemarkerContainer(freemarker.template.Configuration engine)
Constructor for the FreemarkerContainer object. |
|
FreemarkerContainer(freemarker.template.Configuration engine,
Context context)
Constructor for the FreemarkerContainer object. |
|
FreemarkerContainer(Context context)
Constructor for the FreemarkerContainer object. |
Method Summary | |
---|---|
boolean |
contains(java.lang.String name)
The contains method is used to determine if
a mapping exists for the given name. |
boolean |
exists(java.lang.String path)
Determines whether the named template exists. |
java.lang.Object |
get(java.lang.String name)
The get method is used to retrieve the value
mapped to the specified name. |
protected void |
init(Context context)
In the event that the Configuration instance is
uninitialized this attempts to set the root path for loading
of templates to the root context path. |
protected void |
init(java.lang.String root)
In the event that the Configuration instance is
uninitialized this attempts to set the root path for loading
of templates to the specified path. |
java.util.Set |
keySet()
To ascertain what mappings exist, the names of all values previously put into this database can be retrieved with this method. |
Document |
lookup(java.lang.String path)
Looks for the named template and wraps the template within a new Document instance. |
Document |
lookup(java.lang.String path,
boolean share)
Looks for the named template and wraps the template within a new Document instance. |
Document |
lookup(java.lang.String path,
java.lang.Object data,
boolean share)
Looks for the named template and wraps the template within a new Document instance. |
void |
put(java.lang.String name,
java.lang.Object value)
The put method is used to insert a mapping in
the database that pairs the issued name with the issued
value. |
void |
remove(java.lang.String name)
The remove method is used to remove the
mapping from the database. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface simple.template.Database |
---|
contains, get, keySet, put, remove |
Field Detail |
---|
protected freemarker.template.SimpleHash data
Constructor Detail |
---|
public FreemarkerContainer() throws java.lang.Exception
FreemarkerContainer
object.
The instance created will load templates from the current
working directory. So all URI paths provided, referencing
a template, will be resolved from the application path.
java.lang.Exception
- if there is an initialization problempublic FreemarkerContainer(Context context) throws java.lang.Exception
FreemarkerContainer
object.
The instance created will load templates from the context
path. So all URI paths provided will be resolved from the
root path of the provided context object.
context
- the context used to locate the templates
java.lang.Exception
- if there is an initialization problempublic FreemarkerContainer(freemarker.template.Configuration engine) throws java.lang.Exception
FreemarkerContainer
object.
If a specialized Configuration
instance is
required one can be provided, this enables properties, such
as the template root and application attributes to be set.
engine
- this is the engine used by this instance
java.lang.Exception
- if there is an initialization problempublic FreemarkerContainer(freemarker.template.Configuration engine, Context context) throws java.lang.Exception
FreemarkerContainer
object.
If a specialized Configuration
instance is
required one can be provided, this enables properties, such
as the template root and application attributes to be set.
engine
- this is the engine used by this instancecontext
- the context used to locate the properties
java.lang.Exception
- if there is an initialization problemMethod Detail |
---|
protected void init(Context context) throws java.lang.Exception
Configuration
instance is
uninitialized this attempts to set the root path for loading
of templates to the root context path. This will acquire the
base path of the context and set the template loading path
within the freemarker runtime. If the base directory does not
exist then this will throw a file not found exception.
context
- the context used to locate the properties
java.lang.Exception
- if there is a problem on initializationprotected void init(java.lang.String root) throws java.lang.Exception
Configuration
instance is
uninitialized this attempts to set the root path for loading
of templates to the specified path. All templates referenced
by this template will be resolved from the suggested path.
root
- this is the directory used for loading templates
java.lang.Exception
- if there is a problem on initializationpublic boolean exists(java.lang.String path)
lookup
method will locate
a template given the specified path. If the template is
accessible this returns true, otherwise false is returned.
exists
in interface Container
path
- this is the path used to locate the template
public Document lookup(java.lang.String path) throws java.lang.Exception
Document
instance. Resolving the location
of the template is left up the templating system, typically
this requires a file path reference to locate the template.
The document created by this method is transient, that is, it is a unique instance. This means that changes to the properties of any created document object affect only that instance. By default this assumes the UTF-8 encoding.
lookup
in interface Container
path
- this is the path used to locate the template
java.lang.Exception
- this is thrown if the is a problem with
locating or rendering the specified templatepublic Document lookup(java.lang.String path, boolean share) throws java.lang.Exception
Document
instance. Resolving the location
of the template is left up the templating system, typically
this requires a file path reference to locate the template.
The document created by this method is transient, that is, it is a unique instance. This means that changes to the properties of any created document object affect only that instance. By default this assumes the UTF-8 encoding.
path
- this is the path used to locate the templateshare
- should the data model be shared or inherited
java.lang.Exception
- this is thrown if the is a problem with
locating or rendering the specified templatepublic Document lookup(java.lang.String path, java.lang.Object data, boolean share) throws java.lang.Exception
Document
instance. Resolving the location
of the template is left up the templating system, typically
this requires a file path reference to locate the template.
The document created by this method is transient, that is, it is a unique instance. This means that changes to the properties of any created document object affect only that instance. By default this assumes the UTF-8 encoding.
This method allows the SimpleHash
used by the
document object to be specified. This is useful if various
tools need to be added to the database before it is used by
the document, such as rendering tools and various others.
path
- this is the path used to locate the templatedata
- this provides a set of default properties
java.lang.Exception
- this is thrown if the is a problem with
locating or rendering the specified templatepublic void put(java.lang.String name, java.lang.Object value)
put
method is used to insert a mapping in
the database that pairs the issued name with the issued
value. The value can be referenced in future by its name.
Properties set with this method will be set within this
instances data source, which is available to subclasses.
put
in interface Database
name
- this is the name of the value being insertedvalue
- this is the named value that is insertedpublic java.lang.Object get(java.lang.String name)
get
method is used to retrieve the value
mapped to the specified name. If a value does not exist
matching the given name, then this returns null. All the
property values retrieved by this method are obtained
from an internal source that is accessible to subclasses.
get
in interface Database
name
- this is the name of the value to be retrieved
public void remove(java.lang.String name)
remove
method is used to remove the
mapping from the database. This method either removes
the value or returns silently if the name does not exist.
This removes the mapping from the internal data source.
remove
in interface Database
name
- this is the name of the value to be removedpublic java.util.Set keySet()
Set
that
contains the names of all the mappings added to this.
keySet
in interface Database
public boolean contains(java.lang.String name)
contains
method is used to determine if
a mapping exists for the given name. This returns true if
the mapping exists or false otherwise.
contains
in interface Database
name
- this is the name of the mapping to determine
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |