ee.mare.indrek.jtlt
Class Template

Object
  extended byee.mare.indrek.jtlt.Template
Direct Known Subclasses:
HtmlTemplate

public class Template
extends Object

Template class is the basic building block to generate templated content.


Constructor Summary
Template(TemplateGenerator gen)
          Create a template using given template generator as base.
 
Method Summary
 void addParam(String key, Object val)
          Set macro parameters for given block and sub-blocks to val.
 boolean exists(String name)
          To find out whether a given subblock exists.
 TemplateGenerator getBase()
          Get the base generator template.
 boolean instance(String sub_name)
          Lock and unlock given block name in one call.
 void instance(String sub_name, Map map)
          Lock given sub and do tlt.replace (map).
 boolean lock_back(String sub_name)
          Lock and create another block of given subtemplate for replacements, placing the block at the back of other blocks previously created.
 boolean lock_front(String sub_name)
          Lock and create another block of given subtemplate for replacements, placing the block at the front of other blocks previously created.
 boolean lock(String sub_name)
          Lock and create another block of given subtemplate for replacements.
 void nreplace(String key, String value)
          Replace given key in the template with value in this block and all subblocks.
 void output(Writer out)
          Output the template contents.
 void replace(Map map)
          Replace all keys-values inside the map.
 void replace(String key, String value)
          Replace given key in the template with value in the currently active block.
 String toString()
          Convert the template to string.
 void unlock()
          Unlock previously locked block of subtemplate moving up in scope.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Template

public Template(TemplateGenerator gen)
Create a template using given template generator as base.

Method Detail

addParam

public void addParam(String key,
                     Object val)
Set macro parameters for given block and sub-blocks to val. Given object shadows here and in any subblocks parameters defined with same name in parent blocks.


exists

public boolean exists(String name)
To find out whether a given subblock exists.


getBase

public TemplateGenerator getBase()
Get the base generator template.


instance

public boolean instance(String sub_name)
Lock and unlock given block name in one call.


instance

public void instance(String sub_name,
                     Map map)
Lock given sub and do tlt.replace (map).

See Also:
replace(Map)

lock_back

public boolean lock_back(String sub_name)
Lock and create another block of given subtemplate for replacements, placing the block at the back of other blocks previously created.


lock_front

public boolean lock_front(String sub_name)
Lock and create another block of given subtemplate for replacements, placing the block at the front of other blocks previously created.


lock

public boolean lock(String sub_name)
Lock and create another block of given subtemplate for replacements. The block is placed at the back of previously created that named blocks. If the locking fails a complaint will be written.

Returns:
whether a subtemplate with given name was found and locking succeeded
See Also:
TemplateContext.setComplainTo(java.io.PrintStream)

nreplace

public void nreplace(String key,
                     String value)
Replace given key in the template with value in this block and all subblocks. Actually the subblocks query the parent block for key-s and so use this value.


output

public void output(Writer out)
            throws IOException
Output the template contents.

Throws:
IOException

replace

public void replace(Map map)
Replace all keys-values inside the map. So the map must contain String:String associations.


replace

public void replace(String key,
                    String value)
Replace given key in the template with value in the currently active block.


toString

public String toString()
Convert the template to string.


unlock

public void unlock()
Unlock previously locked block of subtemplate moving up in scope. If you try to unlock the top block a complain will be written and the function will just return.