public class ST extends Object
To use templates, you create one (usually via STGroup) and then inject attributes using add(java.lang.String, java.lang.Object). To render its attacks, use render().
TODO: locals is not actually a hash table like the documentation says.
| Modifier and Type | Class and Description |
|---|---|
static class |
ST
Just an alias for
ArrayList, but this way I can track whether a list is something ST created or it's an incoming list.
|
static class |
ST
Events during template hierarchy construction (not evaluation)
|
static class |
ST
<@r()>,
<@r>...<@end>, and
@t.r() ::= "..." defined manually by coder
|
| Modifier and Type | Field and Description |
|---|---|
ST |
debugState
If
STGroup, track creation and add attribute events for each object.
|
static Object |
EMPTY_ATTR
|
STGroup |
groupThatCreatedThisInstance
Created as instance of which group? We need this to initialize interpreter via render.
|
CompiledST |
impl
The implementation for this template among all instances of same template .
|
static String |
IMPLICIT_ARG_NAME
When there are no formal args for template t and you map t across some values, t implicitly gets arg "it".
|
protected Object |
locals
Safe to simultaneously write via
add(java.lang.String, java.lang.Object), which is synchronized.
|
static String |
UNKNOWN_NAME
|
static String |
VERSION
|
| Modifier | Constructor and Description |
|---|---|
protected |
ST()
Used by group creation routine, not by users
|
|
ST(ST
Clone a prototype template.
|
|
ST(STGroup
|
|
ST(String
Used to make templates inline in code for simple things like SQL or log records.
|
|
ST(String
Create ST using non-default delimiters; each one of these will live in it's own group since you're overriding a default; don't want to alter
STGroup.
|
| Modifier and Type | Method and Description |
|---|---|
ST |
add(String
Inject an attribute (name/value pair).
|
ST |
addAggr(String
Split
aggrName.{propName1,propName2} into list
[propName1, propName2] and the
aggrName.
|
protected static ST |
convertToAttributeList(Object
|
static String |
format(int lineWidth, String
|
static String |
format(String
ST.format("name, phone | <name>:<phone>", n, p); ST.format("<%1>:<%2>", n, p); ST.format("<name>:<phone>", "name", x, "phone", y);
|
Object |
getAttribute(String
Find an attribute in this template only.
|
Map |
getAttributes()
|
List |
getEvents()
|
List |
getEvents(int lineWidth)
|
List |
getEvents(Locale
|
List |
getEvents(Locale
|
String |
getName()
|
STViz |
inspect()
|
STViz |
inspect(ErrorManager
|
STViz |
inspect(int lineWidth)
|
STViz |
inspect(Locale
|
boolean |
isAnonSubtemplate()
|
protected void |
rawSetAttribute(String
Set
locals attribute value when you only know the name, not the index.
|
void |
remove(String
Remove an attribute value entirely (can't remove attribute definitions).
|
String |
render()
|
String |
render(int lineWidth)
|
String |
render(Locale
|
String |
render(Locale
|
String |
toString()
|
int |
write(File
|
int |
write(File
|
int |
write(File
|
int |
write(File
|
int |
write(STWriter
|
int |
write(STWriter
|
int |
write(STWriter
|
int |
write(STWriter
|
public static final StringVERSION
public static final StringUNKNOWN_NAME
public static final ObjectEMPTY_ATTR
public static final StringIMPLICIT_ARG_NAME
public CompiledSTimpl
protected Object[] locals
add(java.lang.String, java.lang.Object), which is synchronized. Reading during exec is, however, NOT synchronized. So, not thread safe to add attributes while it is being evaluated. Initialized to
EMPTY_ATTR to distinguish
null from empty.
public STGroupgroupThatCreatedThisInstance
st = skin1.getInstanceOf("searchbox");
result = st.render(); // knows skin1 created it
Say we have a group
g1 with template
t that imports templates
t and
u from another group
g2.
g1.getInstanceOf("u") finds
u in
g2 but remembers that
g1 created it. If
u includes
t, it should create
g1.t not
g2.t.
g1 = {t(), u()}
|
v
g2 = {t()}
public ST.DebugState debugState
STGroup.trackCreationEvents , track creation and add attribute events for each object. Create this object on first use.
protected ST()
public ST(Stringtemplate)
public ST(Stringtemplate, char delimiterStartChar, char delimiterStopChar)
STGroup.defaultGroup .
public ST(STproto)
debugState; don't delegate to
ST(), which creates
ConstructionEvent.
public STadd(String name, Object value)
ST.AttributeList with both the previous and the new attribute as elements. This method will never alter a
List that you inject. If you send in a
List and then inject a single value element,
add copies original list and adds the new value. The attribute name cannot be null or contain '.'.
Return this so we can chain:
t.add("x", 1).add("y", "hi")
public STaddAggr(String aggrSpec, Object ... values)
aggrName.{propName1,propName2} into list
[propName1, propName2] and the
aggrName. Spaces are allowed around
','.
public void remove(Stringname)
protected void rawSetAttribute(Stringname, Object value)
locals attribute value when you only know the name, not the index. This is ultimately invoked by calling
ST#add from outside so toss an exception to notify them.
protected static ST.AttributeList convertToAttributeList(Object curvalue)
public StringgetName()
public boolean isAnonSubtemplate()
public int write(STWriterout) throws IOException
IOException
public int write(STWriterout, STErrorListener listener)
public int write(STWriterout, Locale locale, STErrorListener listener)
public int write(FileoutputFile, STErrorListener listener) throws IOException
IOException
public int write(FileoutputFile, STErrorListener listener, String encoding) throws IOException
IOException
public int write(FileoutputFile, STErrorListener listener, String encoding, int lineWidth) throws IOException
IOException
public int write(FileoutputFile, STErrorListener listener, String encoding, Locale locale, int lineWidth) throws IOException
IOException
public Stringrender()
public Stringrender(int lineWidth)
public STVizinspect()
public STVizinspect(int lineWidth)
public STVizinspect(ErrorManager errMgr, Locale locale, int lineWidth)
public List<InterpEvent > getEvents()
public List<InterpEvent > getEvents(int lineWidth)
public List<InterpEvent > getEvents(Locale locale)
public List<InterpEvent > getEvents(Locale locale, int lineWidth)
public StringtoString()
public static Stringformat(String template, Object ... attributes)
ST.format("name, phone | <name>:<phone>", n, p);
ST.format("<%1>:<%2>", n, p);
ST.format("<name>:<phone>", "name", x, "phone", y);