simple.template
Class Environment

java.lang.Object
  extended by simple.template.Environment
All Implemented Interfaces:
Container, Database

public class Environment
extends java.lang.Object
implements Container

The Delegate provides a full implementation of an environment. This enables the template engine to provide its mapping scheme to the object transparently and decouples both the controller objects and the templating system from the mapping scheme used. The resolve method provided by this will use the mapping scheme to locate the required templates, all completly transparent to the controllers.

Author:
Niall Gallagher

Constructor Summary
Environment(Container system, Context context)
          Constructor for the Delegate 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.
 java.util.Set keySet()
          To ascertain what mappings exist, the names of all values previously put into thhis 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.
 void put(java.lang.String name, java.lang.Object value)
          The put method is used to insert a mapping in the environment 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 environment.
 Document resolve(java.lang.String target)
          Looks for the named template and wraps the template within a new Document instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Environment

public Environment(Container system,
                   Context context)
Constructor for the Delegate object. In order to incorporate the template engines mapping scheme into this environment, this requires that the engines context is provided, the templating system is also required to produce documents that can be configured for rendering.

Parameters:
system - this represents the templating system used
context - this is the context of the template engine
Method Detail

put

public void put(java.lang.String name,
                java.lang.Object value)
The put method is used to insert a mapping in the environment 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 the container, and will thus be available to all documents.

Specified by:
put in interface Database
Parameters:
name - this is the name of the value being inserted
value - this is the named value that is inserted

get

public java.lang.Object get(java.lang.String name)
The 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 the container, and are retrievable from documents.

Specified by:
get in interface Database
Parameters:
name - this is the name of the value to be retrieved
Returns:
returns the value if it exists or null otherwise

remove

public void remove(java.lang.String name)
The remove method is used to remove the mapping from the environment. This method either removes the value or returns silently if the name does not exits. Once removed, all documents with access to the property can no longer reference it, nor can the container.

Specified by:
remove in interface Database
Parameters:
name - this is the name of the value to be removed

keySet

public java.util.Set keySet()
To ascertain what mappings exist, the names of all values previously put into thhis database can be retrieved with this method. This will return a Set that contains the names of all the mappings added to this.

Specified by:
keySet in interface Database
Returns:
this returns all the keys for existing mappings

contains

public boolean contains(java.lang.String name)
The contains method is used to determine if a mapping exists for the given name. This returns true if the mapping exists or false otherwise. This delegates to the internal container object that contains all mappings.

Specified by:
contains in interface Database
Parameters:
name - this is the name of the mapping to determine
Returns:
returns true if a mapping exists, false otherwise

exists

public boolean exists(java.lang.String path)
Determines whether the named template exists. This is used to determine if the lookup method will locate a template given the specified path. If the template is accessable this returns true, otherwise false is returned.

Specified by:
exists in interface Container
Parameters:
path - this is the path used to locate the template
Returns:
true if the template exists, false if it does not

lookup

public Document lookup(java.lang.String path)
                throws java.lang.Exception
Looks for the named template and wraps the template within a new 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. All documents retrieved use the UTF-8 encoding.

Specified by:
lookup in interface Container
Parameters:
path - this is the path used to locate the template
Returns:
the specified template wrapped within a document
Throws:
java.lang.Exception - this is thrown if the is a problem with locating or rendering the specified template

resolve

public Document resolve(java.lang.String target)
                 throws java.lang.Exception
Looks for the named template and wraps the template within a new Document instance. Resolving the location of the template is done using the internal mapping scheme employed by the template engine. This will extract the path from the HTTP URI and delegate to the lookup method, which will use the templating system to locate the template. This is used to hide all mapping details.

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. All documents retrieved use the UTF-8 encoding.

Parameters:
target - the unmodified URI to resolve to a template
Returns:
the specified template wrapped within a document
Throws:
java.lang.Exception - this is thrown if ther is a problem with locating or rendering the resolved template