Top Description Inners Fields Constructors Methods
org.stringtemplate.v4

public Class ST

extends Object
Class Inheritance
Imports
org.stringtemplate.v4.compiler.CompiledST, .FormalArgument, org.stringtemplate.v4.debug.AddAttributeEvent, .ConstructionEvent, .EvalTemplateEvent, .InterpEvent, org.stringtemplate.v4.gui.STViz, org.stringtemplate.v4.misc.Aggregate, .ErrorBuffer, .ErrorManager, .MultiMap, java.io.*, java.lang.reflect.Array, java.util.*

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. To render its attacks, use ST#render().

Todo

ST#locals is not actually a hash table like the documentation says.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public 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.

public static class
ST.DebugState

Events during template hierarchy construction (not evaluation)

public static enum
ST.RegionType

<@r()>, <@r>...

Field Summary

Modifier and TypeField and Description
public ST.DebugState
debugState

If STGroup#trackCreationEvents, track creation and add attribute events for each object.

public static final Object
public STGroup
groupThatCreatedThisInstance

Created as instance of which group?

public CompiledST
impl

The implementation for this template among all instances of same template .

public static final 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, which is synchronized.

public static final String
public static final String

Constructor Summary

AccessConstructor and Description
protected
ST()

Used by group creation routine, not by users

public
ST(String template)

Used to make templates inline in code for simple things like SQL or log records.

public
ST(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.

public
ST(STGroup group, String template)

public
ST(ST proto)

Clone a prototype template.

Method Summary

Modifier and TypeMethod and Description
public synchronized ST
add(String name, Object value)

Inject an attribute (name/value pair).

public synchronized ST
addAggr(String aggrSpec, Object... values)

Split aggrName.{propName1,propName2} into list [propName1, propName2] and the aggrName.

protected static ST.AttributeList
public static String
format(String template, Object... attributes)

ST.format("<%1>:<%2>", n, p);
public static String
format(int lineWidth, String template, Object... attributes)

public Object
getAttribute(String name)

Find an attribute in this template only.

public Map<String, Object>
public List<InterpEvent>
public List<InterpEvent>
getEvents(int lineWidth)

public List<InterpEvent>
getEvents(Locale locale)

public List<InterpEvent>
getEvents(Locale locale, int lineWidth)

public String
public STViz
public STViz
inspect(int lineWidth)

public STViz
inspect(Locale locale)

public STViz
inspect(ErrorManager errMgr, Locale locale, int lineWidth)

public boolean
protected void
rawSetAttribute(String name, Object value)

Set locals attribute value when you only know the name, not the index.

public void
remove(String name)

Remove an attribute value entirely (can't remove attribute definitions).

public String
public String
render(int lineWidth)

public String
render(Locale locale)

public String
render(Locale locale, int lineWidth)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public int
public int
write(STWriter out, Locale locale)

public int
public int
write(STWriter out, Locale locale, STErrorListener listener)

public int
write(File outputFile, STErrorListener listener)

public int
write(File outputFile, STErrorListener listener, String encoding)

public int
write(File outputFile, STErrorListener listener, String encoding, int lineWidth)

public int
write(File outputFile, STErrorListener listener, String encoding, Locale locale, int lineWidth)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

debugStateback to summary
public ST.DebugState debugState

If STGroup#trackCreationEvents, track creation and add attribute events for each object. Create this object on first use.

EMPTY_ATTRback to summary
public static final Object EMPTY_ATTR
groupThatCreatedThisInstanceback to summary
public STGroup 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 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()}
implback to summary
public CompiledST impl

The implementation for this template among all instances of same template .

IMPLICIT_ARG_NAMEback to summary
public static final 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". E.g., "$it$"

localsback to summary
protected Object[] locals

Safe to simultaneously write via add, 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.

UNKNOWN_NAMEback to summary
public static final String UNKNOWN_NAME
VERSIONback to summary
public static final String VERSION

Constructor Detail

STback to summary
protected ST()

Used by group creation routine, not by users

STback to summary
public ST(String template)

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.

STback to summary
public ST(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.

STback to summary
public ST(STGroup group, String template)
STback to summary
public ST(ST proto)

Clone a prototype template. Copy all fields minus debugState; don't delegate to ST(), which creates ConstructionEvent.

Method Detail

addback to summary
public synchronized ST add(String name, Object value)

Inject an attribute (name/value pair). If there is already an attribute with that name, this method turns the attribute into an 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")

addAggrback to summary
public synchronized ST addAggr(String aggrSpec, Object... values)

Split aggrName.{propName1,propName2} into list [propName1, propName2] and the aggrName. Spaces are allowed around ','.

convertToAttributeListback to summary
protected static ST.AttributeList convertToAttributeList(Object curvalue)
formatback to summary
public static String format(String template, Object... attributes)
ST.format("<%1>:<%2>", n, p);
formatback to summary
public static String format(int lineWidth, String template, Object... attributes)
getAttributeback to summary
public Object getAttribute(String name)

Find an attribute in this template only.

getAttributesback to summary
public Map<String, Object> getAttributes()
getEventsback to summary
public List<InterpEvent> getEvents()
getEventsback to summary
public List<InterpEvent> getEvents(int lineWidth)
getEventsback to summary
public List<InterpEvent> getEvents(Locale locale)
getEventsback to summary
public List<InterpEvent> getEvents(Locale locale, int lineWidth)
getNameback to summary
public String getName()
inspectback to summary
public STViz inspect()
inspectback to summary
public STViz inspect(int lineWidth)
inspectback to summary
public STViz inspect(Locale locale)
inspectback to summary
public STViz inspect(ErrorManager errMgr, Locale locale, int lineWidth)
isAnonSubtemplateback to summary
public boolean isAnonSubtemplate()
rawSetAttributeback to summary
protected void rawSetAttribute(String name, Object value)

Set 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.

removeback to summary
public void remove(String name)

Remove an attribute value entirely (can't remove attribute definitions).

renderback to summary
public String render()
renderback to summary
public String render(int lineWidth)
renderback to summary
public String render(Locale locale)
renderback to summary
public String render(Locale locale, int lineWidth)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
writeback to summary
public int write(STWriter out) throws IOException
writeback to summary
public int write(STWriter out, Locale locale)
writeback to summary
public int write(STWriter out, STErrorListener listener)
writeback to summary
public int write(STWriter out, Locale locale, STErrorListener listener)
writeback to summary
public int write(File outputFile, STErrorListener listener) throws IOException
writeback to summary
public int write(File outputFile, STErrorListener listener, String encoding) throws IOException
writeback to summary
public int write(File outputFile, STErrorListener listener, String encoding, int lineWidth) throws IOException
writeback to summary
public int write(File outputFile, STErrorListener listener, String encoding, Locale locale, int lineWidth) throws IOException
org.stringtemplate.v4 back to summary

public final Class ST.AttributeList

extends ArrayList<Object>
Class Inheritance

Just an alias for ArrayList, but this way I can track whether a list is something ST created or it's an incoming list.

Constructor Summary

AccessConstructor and Description
public
AttributeList(int size)

public

Method Summary

Inherited from java.util.ArrayList:
addaddaddAlladdAlladdFirstaddLastclearclonecontainsensureCapacityequalsforEachgetgetFirstgetLasthashCodeindexOfisEmptyiteratorlastIndexOflistIteratorlistIteratorremoveremoveremoveAllremoveFirstremoveIfremoveLastremoveRangereplaceAllretainAllsetsizesortspliteratorsubListtoArraytoArraytrimToSize

Constructor Detail

AttributeListback to summary
public AttributeList(int size)
AttributeListback to summary
public AttributeList()
org.stringtemplate.v4 back to summary

public Class ST.DebugState

extends Object
Class Inheritance

Events during template hierarchy construction (not evaluation)

Field Summary

Modifier and TypeField and Description
public MultiMap<String, AddAttributeEvent>
addAttrEvents

Track construction-time add attribute "events"; used for ST user-level debugging

public ConstructionEvent
newSTEvent

Record who made us?

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

addAttrEventsback to summary
public MultiMap<String, AddAttributeEvent> addAttrEvents

Track construction-time add attribute "events"; used for ST user-level debugging

newSTEventback to summary
public ConstructionEvent newSTEvent

Record who made us? ConstructionEvent creates Exception to grab stack

Constructor Detail

DebugStateback to summary
public DebugState()
org.stringtemplate.v4 back to summary

public final Enum ST.RegionType

extends Enum<ST.RegionType>
Class Inheritance

<@r()>, <@r>...<@end>, and @t.r() ::= "..." defined manually by coder

Field Summary

Modifier and TypeField and Description
public static final ST.RegionType
EMBEDDED

<@r>...

public static final ST.RegionType
EXPLICIT

@t.r() ::= "..."

public static final ST.RegionType
IMPLICIT

<@r()>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ST.RegionType
public static ST.RegionType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

EMBEDDEDback to summary
public static final ST.RegionType EMBEDDED

<@r>...<@end>

EXPLICITback to summary
public static final ST.RegionType EXPLICIT

@t.r() ::= "..."

IMPLICITback to summary
public static final ST.RegionType IMPLICIT

<@r()>

Constructor Detail

RegionTypeback to summary
private RegionType()

Method Detail

valueOfback to summary
public static ST.RegionType valueOf(String name)
valuesback to summary
public static ST.RegionType[] values()