public class ST
extends java.lang.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.AttributeList
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.DebugState
Events during template hierarchy construction (not evaluation)
|
static class |
ST.RegionType
<@r()>, <@r>...<@end>, and @t.r() ::= "..." defined manually by coder |
| Modifier and Type | Field and Description |
|---|---|
ST.DebugState |
debugState
If
STGroup.trackCreationEvents, track creation and add
attribute events for each object. |
static java.lang.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 java.lang.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 java.lang.Object[] |
locals
Safe to simultaneously write via
add(java.lang.String, java.lang.Object), which is synchronized. |
static java.lang.String |
UNKNOWN_NAME |
static java.lang.String |
VERSION |
| Modifier | Constructor and Description |
|---|---|
protected |
ST()
Used by group creation routine, not by users
|
|
ST(ST proto)
Clone a prototype template.
|
|
ST(STGroup group,
java.lang.String template) |
|
ST(java.lang.String template)
Used to make templates inline in code for simple things like SQL or log records.
|
|
ST(java.lang.String template,
char delimiterStartChar,
char delimiterStopChar)
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.defaultGroup. |
| Modifier and Type | Method and Description |
|---|---|
ST |
add(java.lang.String name,
java.lang.Object value)
Inject an attribute (name/value pair).
|
ST |
addAggr(java.lang.String aggrSpec,
java.lang.Object... values)
Split
aggrName.{propName1,propName2} into list
[propName1, propName2] and the aggrName. |
protected static ST.AttributeList |
convertToAttributeList(java.lang.Object curvalue) |
static java.lang.String |
format(int lineWidth,
java.lang.String template,
java.lang.Object... attributes) |
static java.lang.String |
format(java.lang.String template,
java.lang.Object... attributes)
ST.format("<%1>:<%2>", n, p);
|
java.lang.Object |
getAttribute(java.lang.String name)
Find an attribute in this template only.
|
java.util.Map<java.lang.String,java.lang.Object> |
getAttributes() |
java.util.List<InterpEvent> |
getEvents() |
java.util.List<InterpEvent> |
getEvents(int lineWidth) |
java.util.List<InterpEvent> |
getEvents(java.util.Locale locale) |
java.util.List<InterpEvent> |
getEvents(java.util.Locale locale,
int lineWidth) |
java.lang.String |
getName() |
STViz |
inspect() |
STViz |
inspect(ErrorManager errMgr,
java.util.Locale locale,
int lineWidth) |
STViz |
inspect(int lineWidth) |
STViz |
inspect(java.util.Locale locale) |
boolean |
isAnonSubtemplate() |
protected void |
rawSetAttribute(java.lang.String name,
java.lang.Object value)
Set
locals attribute value when you only know the name, not the
index. |
void |
remove(java.lang.String name)
Remove an attribute value entirely (can't remove attribute definitions).
|
java.lang.String |
render() |
java.lang.String |
render(int lineWidth) |
java.lang.String |
render(java.util.Locale locale) |
java.lang.String |
render(java.util.Locale locale,
int lineWidth) |
java.lang.String |
toString() |
int |
write(java.io.File outputFile,
STErrorListener listener) |
int |
write(java.io.File outputFile,
STErrorListener listener,
java.lang.String encoding) |
int |
write(java.io.File outputFile,
STErrorListener listener,
java.lang.String encoding,
int lineWidth) |
int |
write(java.io.File outputFile,
STErrorListener listener,
java.lang.String encoding,
java.util.Locale locale,
int lineWidth) |
int |
write(STWriter out) |
int |
write(STWriter out,
java.util.Locale locale) |
int |
write(STWriter out,
java.util.Locale locale,
STErrorListener listener) |
int |
write(STWriter out,
STErrorListener listener) |
public static final java.lang.String VERSION
public static final java.lang.String UNKNOWN_NAME
public static final java.lang.Object EMPTY_ATTR
public static final java.lang.String IMPLICIT_ARG_NAME
public CompiledST impl
protected java.lang.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 STGroup groupThatCreatedThisInstance
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(java.lang.String template)
public ST(java.lang.String template, char delimiterStartChar, char delimiterStopChar)
STGroup.defaultGroup.public ST(STGroup group, java.lang.String template)
public ST(ST proto)
debugState; don't delegate to ST(),
which creates ConstructionEvent.public ST add(java.lang.String name, java.lang.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 ST addAggr(java.lang.String aggrSpec, java.lang.Object... values)
aggrName.{propName1,propName2} into list
[propName1, propName2] and the aggrName. Spaces are
allowed around ','.public void remove(java.lang.String name)
protected void rawSetAttribute(java.lang.String name,
java.lang.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.public java.lang.Object getAttribute(java.lang.String name)
public java.util.Map<java.lang.String,java.lang.Object> getAttributes()
protected static ST.AttributeList convertToAttributeList(java.lang.Object curvalue)
public java.lang.String getName()
public boolean isAnonSubtemplate()
public int write(STWriter out) throws java.io.IOException
java.io.IOExceptionpublic int write(STWriter out, java.util.Locale locale)
public int write(STWriter out, STErrorListener listener)
public int write(STWriter out, java.util.Locale locale, STErrorListener listener)
public int write(java.io.File outputFile,
STErrorListener listener)
throws java.io.IOException
java.io.IOExceptionpublic int write(java.io.File outputFile,
STErrorListener listener,
java.lang.String encoding)
throws java.io.IOException
java.io.IOExceptionpublic int write(java.io.File outputFile,
STErrorListener listener,
java.lang.String encoding,
int lineWidth)
throws java.io.IOException
java.io.IOExceptionpublic int write(java.io.File outputFile,
STErrorListener listener,
java.lang.String encoding,
java.util.Locale locale,
int lineWidth)
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String render()
public java.lang.String render(int lineWidth)
public java.lang.String render(java.util.Locale locale)
public java.lang.String render(java.util.Locale locale,
int lineWidth)
public STViz inspect()
public STViz inspect(int lineWidth)
public STViz inspect(java.util.Locale locale)
public STViz inspect(ErrorManager errMgr, java.util.Locale locale, int lineWidth)
public java.util.List<InterpEvent> getEvents()
public java.util.List<InterpEvent> getEvents(int lineWidth)
public java.util.List<InterpEvent> getEvents(java.util.Locale locale)
public java.util.List<InterpEvent> getEvents(java.util.Locale locale, int lineWidth)
public java.lang.String toString()
toString in class java.lang.Objectpublic static java.lang.String format(java.lang.String template,
java.lang.Object... attributes)
ST.format("<%1>:<%2>", n, p);
public static java.lang.String format(int lineWidth,
java.lang.String template,
java.lang.Object... attributes)
Copyright © 2018. All Rights Reserved.