xv.text.template
Class TemplateEnvironment

java.lang.Object
  extended by xv.text.template.TemplateEnvironment

public class TemplateEnvironment
extends Object

An environment within a template. Basically this is a map of strings to Java objects. (In fact, the implementation is wrapped around a map.)

However, due to the myriad of ways that the collections Map interface allows values to be snuck in, this class does not actually implement Map at present.

Author:
xv

Constructor Summary
TemplateEnvironment()
           
TemplateEnvironment(Map<? extends String,? extends Object> original)
          Create a new environment using values from the given map.
TemplateEnvironment(String first, String... remaining)
          This is a convenience constructor.
 
Method Summary
 boolean contains(String var)
          Check if the environment has a binding for the given variable name.
 Object get(String var)
           
 Object get(String var, Object def)
           
 String getString(String var)
          Gets the given variable as a string.
 String[] getVariableNames()
           
 Object remove(String var)
          Removes the given binding.
 void set(String var, Object value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TemplateEnvironment

public TemplateEnvironment()

TemplateEnvironment

public TemplateEnvironment(Map<? extends String,? extends Object> original)
Create a new environment using values from the given map.

I'm aware that String is final, but, ...whatever.

Parameters:
original -

TemplateEnvironment

public TemplateEnvironment(String first,
                           String... remaining)
This is a convenience constructor. The arguments should be an even number of strings. The first string is the first key, the second string is the first value, the third string is the second key, and so on.

Parameters:
first - the first string - this is a hack to prevent "ambiguous" errors
remaining - the remaining arguments
Method Detail

get

public Object get(String var)

get

public Object get(String var,
                  Object def)

getString

public String getString(String var)
Gets the given variable as a string. The empty string is returned if the variable is unset. If the value is null, the string "null" is returned. Otherwise this converts to a string directly via Object.toString().

Parameters:
var -
Returns:

contains

public boolean contains(String var)
Check if the environment has a binding for the given variable name.

Parameters:
var - the variable name to check
Returns:
whether the environment has a binding for that variable name

set

public void set(String var,
                Object value)

remove

public Object remove(String var)
Removes the given binding.

Parameters:
var -
Returns:

getVariableNames

public String[] getVariableNames()


Copyright © 2008-2011. All Rights Reserved.