public class BasicTemplate extends Object implements Template
${
and end with }
. Some tags
begin blocks (conditional clauses, iteration loops, etc.) which continue
until an empty tag, ${}
. Blocks can be nested, such that an
empty tag signifies the end of the innermost block.
To keep the implementation lean, only the following five tags are handled
here, because they are processed specially during the initial parsing. For
all other tags, see the RichTemplate
class.
${=key}
casts the key.${=key:format}
uses a Formatter
for format
the value cast by the tag.${import template-name}
imports the template
using the TemplateSource
, and inserts it in place of the tag. Note
that all imports are processed while parsing, so that this does not effect
casting performance in any way.${tag (iterable-key)key}
uses the
nested template filler nested-key
to process the tag. For
example: ${for-each (book)author}
. Note that this construct only
makes sense for tags that accept a single key as their argument.${import (iterable-key)template-name}
is replaced
by the nested block structure
${for-each nested-key}${import template-name}${}
. This
special implementation of the Using tag is only for use in
RichTemplate
, but is defined here because it needs to be processed
during parsing.${define key}
defines the block as filling
tag. This is useful when importing templates that require certain tags. The
block can in turn include any other tags, and thus it works like a
mini-import. Like imports, defines are processed while parsing.${#}
does not parse the block. It does not become
part of the template's parsed structure, and thus it does not take any
memory.${flatten}
removes all tabs, carriage returns and
newlines in the block. Note that this does not apply to casting, only to
literal text within the template! As with comments, the excess whitespace
does not became part of the template's parsed structure, and thus it does not
take any memory. It's useful for organizing the template with whitespace
without affecting its presentation.${external external-key}
calls the
ExternalHandler
to process this tag. External handlers can be used
for complex casting such as expression language evaluation, and delegation or
hooking to other templating/rendering systems.RichTemplate
,
Serialized FormModifier and Type | Field and Description |
---|---|
static String |
TAG_IMPORT_BEGIN |
static int |
TAG_IMPORT_BEGIN_LENGTH |
static String |
TAG_IMPORT_END |
static int |
TAG_IMPORT_END_LENGTH |
Constructor and Description |
---|
BasicTemplate(String content,
TemplateSource importTemplateSource) |
Modifier and Type | Method and Description |
---|---|
protected void |
cast(Chunk chunk,
Filler filler,
Appendable out,
boolean soft) |
void |
cast(Filler filler,
Appendable out) |
ExternalHandler |
getExternalHandler() |
Formatter |
getFormatter() |
String[] |
getRequiredTags() |
protected Chunk |
parseTag(String tag) |
void |
setExternalHandler(ExternalHandler externalHandler) |
void |
setFormatter(Formatter formatter) |
void |
softCast(Filler filler,
Appendable out) |
Iterator<Object> |
streamCast(Filler filler) |
String |
toString() |
void |
transform(Filler filler) |
public static final String TAG_IMPORT_BEGIN
public static final int TAG_IMPORT_BEGIN_LENGTH
public static final String TAG_IMPORT_END
public static final int TAG_IMPORT_END_LENGTH
public BasicTemplate(String content, TemplateSource importTemplateSource) throws ParseException, TemplateSourceException
public void setExternalHandler(ExternalHandler externalHandler)
setExternalHandler
in interface Template
public ExternalHandler getExternalHandler()
getExternalHandler
in interface Template
public void setFormatter(Formatter formatter)
setFormatter
in interface Template
public Formatter getFormatter()
getFormatter
in interface Template
public void cast(Filler filler, Appendable out) throws CastException
cast
in interface Template
CastException
public void softCast(Filler filler, Appendable out)
public Iterator<Object> streamCast(Filler filler)
streamCast
in interface Template
public void transform(Filler filler) throws ParseException, TemplateSourceException
transform
in interface Template
ParseException
TemplateSourceException
public String[] getRequiredTags()
getRequiredTags
in interface Template
protected Chunk parseTag(String tag) throws ParseException
ParseException
protected void cast(Chunk chunk, Filler filler, Appendable out, boolean soft) throws CastException, IOException
CastException
IOException
Copyright © 2009-2015 Three Crickets LLC.