Class ST
java.lang.Object
org.stringtemplate.v4.ST
An instance of the StringTemplate. It consists primarily of
a reference to its implementation (shared among all
instances) and a hash table of attributes. Because
of dynamic scoping, we also need a reference to any enclosing instance. For
example, in a deeply nested template for an HTML page body, we could still
reference the title attribute defined in the outermost page template.
To use templates, you create one (usually via STGroup) and then inject
attributes using add(String, Object). To render its attacks, use render().
TODO: locals is not actually a hash table like the documentation
says.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classJust an alias forArrayList, but this way I can track whether a list is something ST created or it's an incoming list.static classEvents during template hierarchy construction (not evaluation)static enum<@r()>,<@r>...<@end>, and@t.r() ::= "..."defined manually by coder -
Field Summary
FieldsModifier and TypeFieldDescriptionIfSTGroup.trackCreationEvents, track creation and add attribute events for each object.static final ObjectCreated as instance of which group? We need this to initialize interpreter via render.The implementation for this template among all instances of same template .static final StringWhen there are no formal args for template t and you map t across some values, t implicitly gets arg "it".protected Object[]Safe to simultaneously write viaadd(String, Object), which is synchronized.static final Stringstatic final String -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedST()Used by group creation routine, not by usersUsed to make templates inline in code for simple things like SQL or log records.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 alterSTGroup.defaultGroup.Clone a prototype template. -
Method Summary
Modifier and TypeMethodDescriptionInject an attribute (name/value pair).SplitaggrName.{propName1,propName2}into list[propName1, propName2]and theaggrName.protected static ST.AttributeListconvertToAttributeList(Object curvalue) static Stringstatic StringST.format("<%1>:<%2>", n, p);getAttribute(String name) Find an attribute in this template only.getEvents(int lineWidth) getName()inspect()inspect(int lineWidth) inspect(ErrorManager errMgr, Locale locale, int lineWidth) booleanprotected voidrawSetAttribute(String name, Object value) Setlocalsattribute value when you only know the name, not the index.voidRemove an attribute value entirely (can't remove attribute definitions).render()render(int lineWidth) toString()intwrite(File outputFile, STErrorListener listener) intwrite(File outputFile, STErrorListener listener, String encoding) intwrite(File outputFile, STErrorListener listener, String encoding, int lineWidth) intwrite(File outputFile, STErrorListener listener, String encoding, Locale locale, int lineWidth) intintintwrite(STWriter out, Locale locale, STErrorListener listener) intwrite(STWriter out, STErrorListener listener)
-
Field Details
-
VERSION
- See Also:
-
UNKNOWN_NAME
- See Also:
-
EMPTY_ATTR
-
IMPLICIT_ARG_NAME
When there are no formal args for template t and you map t across some values, t implicitly gets arg "it". E.g., "$it$"- See Also:
-
impl
The implementation for this template among all instances of same template . -
locals
Safe to simultaneously write viaadd(String, Object), which is synchronized. Reading during exec is, however, NOT synchronized. So, not thread safe to add attributes while it is being evaluated. Initialized toEMPTY_ATTRto distinguishnullfrom empty. -
groupThatCreatedThisInstance
Created as instance of which group? We need this to initialize interpreter via render. So, we create st and then it needs to know which group created it for sake of polymorphism:st = skin1.getInstanceOf("searchbox"); result = st.render(); // knows skin1 created itSay we have a groupg1with templatetthat imports templatestandufrom another groupg2.g1.getInstanceOf("u")findsuing2but remembers thatg1created it. Ifuincludest, it should createg1.tnotg2.t.g1 = {t(), u()} | v g2 = {t()} -
debugState
IfSTGroup.trackCreationEvents, track creation and add attribute events for each object. Create this object on first use.
-
-
Constructor Details
-
ST
protected ST()Used by group creation routine, not by users -
ST
Used to make templates inline in code for simple things like SQL or log records. No formal arguments are set and there is no enclosing instance. -
ST
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 alterSTGroup.defaultGroup. -
ST
-
ST
Clone a prototype template. Copy all fields minusdebugState; don't delegate toST(), which createsConstructionEvent.
-
-
Method Details
-
add
Inject an attribute (name/value pair). If there is already an attribute with that name, this method turns the attribute into anST.AttributeListwith both the previous and the new attribute as elements. This method will never alter aListthat you inject. If you send in aListand then inject a single value element,addcopies original list and adds the new value. The attribute name cannot be null or contain '.'.Return
thisso we can chain:t.add("x", 1).add("y", "hi") -
addAggr
-
remove
Remove an attribute value entirely (can't remove attribute definitions). -
rawSetAttribute
-
getAttribute
-
getAttributes
-
convertToAttributeList
-
getName
-
isAnonSubtemplate
public boolean isAnonSubtemplate() -
write
- Throws:
IOException
-
write
-
write
-
write
-
write
- Throws:
IOException
-
write
- Throws:
IOException
-
write
public int write(File outputFile, STErrorListener listener, String encoding, int lineWidth) throws IOException - Throws:
IOException
-
write
public int write(File outputFile, STErrorListener listener, String encoding, Locale locale, int lineWidth) throws IOException - Throws:
IOException
-
render
-
render
-
render
-
render
-
inspect
-
inspect
-
inspect
-
inspect
-
getEvents
-
getEvents
-
getEvents
-
getEvents
-
toString
-
format
-
format
-