Package org.stringtemplate.v4
Interface STWriter
-
- All Known Implementing Classes:
AutoIndentWriter
,NoIndentWriter
public interface STWriter
Generic StringTemplate output writer filter.Literals and the elements of expressions are emitted via
write(String)
. Separators are emitted viawriteSeparator(String)
because they must be handled specially when wrapping lines (we don't want to wrap in between an element and it's separator).
-
-
Field Summary
Fields Modifier and Type Field Description static int
NO_WRAP
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description int
index()
Return the absolute char index into the output of the char we're about to write.void
popAnchorPoint()
String
popIndentation()
void
pushAnchorPoint()
void
pushIndentation(String indent)
void
setLineWidth(int lineWidth)
int
write(String str)
Write the string and return how many actual characters were written.int
write(String str, String wrap)
Same as write, but wrap lines using the indicated string as the wrap character (such as"\n"
).int
writeSeparator(String str)
Write a separator.int
writeWrap(String wrap)
Because we evaluate ST instance by invokingInterpreter.exec(STWriter, InstanceScope)
again, we can't pass options in.
-
-
-
Field Detail
-
NO_WRAP
static final int NO_WRAP
- See Also:
- Constant Field Values
-
-
Method Detail
-
pushIndentation
void pushIndentation(String indent)
-
popIndentation
String popIndentation()
-
pushAnchorPoint
void pushAnchorPoint()
-
popAnchorPoint
void popAnchorPoint()
-
setLineWidth
void setLineWidth(int lineWidth)
-
write
int write(String str) throws IOException
Write the string and return how many actual characters were written. With auto-indentation and wrapping, more chars thanstr.length()
can be emitted. No wrapping is done.- Throws:
IOException
-
write
int write(String str, String wrap) throws IOException
Same as write, but wrap lines using the indicated string as the wrap character (such as"\n"
).- Throws:
IOException
-
writeWrap
int writeWrap(String wrap) throws IOException
Because we evaluate ST instance by invokingInterpreter.exec(STWriter, InstanceScope)
again, we can't pass options in. So theBytecode.INSTR_WRITE
instruction of an applied template (such as when we wrap in between template applications like<data:{v|[<v>]}; wrap>
) we need to write thewrap
string before callingInterpreter.exec(org.stringtemplate.v4.STWriter, org.stringtemplate.v4.InstanceScope)
. We expose just like for the separator. SeeInterpreter.writeObject(org.stringtemplate.v4.STWriter, org.stringtemplate.v4.InstanceScope, java.lang.Object, java.lang.String[])
where it checks for ST instance. If POJO,Interpreter.writePOJO(org.stringtemplate.v4.STWriter, org.stringtemplate.v4.InstanceScope, java.lang.Object, java.lang.String[])
passeswrap
towrite(String str, String wrap)
. Can't pass toInterpreter.exec(org.stringtemplate.v4.STWriter, org.stringtemplate.v4.InstanceScope)
.- Throws:
IOException
-
writeSeparator
int writeSeparator(String str) throws IOException
Write a separator. Same aswrite(String)
except that a"\n"
cannot be inserted before emitting a separator.- Throws:
IOException
-
index
int index()
Return the absolute char index into the output of the char we're about to write. Returns 0 if no char written yet.
-
-