public class TemplateSplitter extends Object
This transfomrs a given ("template"-)file into another file, applying the following rules:
- normal content is transformed to a java-program
e.g. the input:
'hello this is some text'
will result in
'out.println( "hello this is some text" );'
- content escaped using '<%' and '%>' is not transformed to 'out.println( .. )' code.
e.g. the input:
'hello <%for int i = 1; i < 10; i++) {%> this is some text <% } %>'
results in:
'out.print( "hello" );
for int i = 0; i != 10; i++) {
out.print( "this is some text" );
}'
- content escaped using '<%+' and '%>' is transformed to 'out.println( "xxx" + content )' code.
e.g.
'hello <%for int i = 1; i < 10; i++) {%> this is <%+i%> some text <% } %>'
results in:
'out.print( "hello" );
for int i = 0; i != 10; i++) {
out.print( "this is "+i+"some text" );
}'
known problems
- 2 escapings without any content produce incorrect output ("<%xy%><%yz%>")
workaround: "<%xy%><%yz%>" is aequivalent to "<%xyyz%>"
- since unescaped input is transformed into 'out.println( "unescaped text" )'
quotes have to be java-style escaped in the input file. e.g.
'these are \"quotes\"' ==transformed to==> 'out.println( "these are \"quotes\"" )'
same applies to '\'
'this is one backslash: \\' ==transformed to==> 'out.println( "this is one backslash: \\" )'
| Constructor and Description |
|---|
TemplateSplitter()
Constructs an empty TemplateSplitter
|
TemplateSplitter(InputStream in,
PrintStream out)
Constructs a TemplateSplitter with the given input and output streams
|
| Modifier and Type | Method and Description |
|---|---|
void |
closeIn() |
void |
closeOut() |
String |
getClazzName() |
static void |
main(String[] args)
sample code
|
void |
run()
starts transformation of input to output
|
void |
run(InputStream in,
PrintStream out)
starts transformation of input to output
|
void |
setClazzName(String clazzName)
special: all occurences of 'CLAZZNAME' in the inputfile will be replaced by the given String 'clazzName'
|
public TemplateSplitter()
public TemplateSplitter(InputStream in, PrintStream out)
public void run(InputStream in, PrintStream out) throws IOException
IOExceptionpublic void setClazzName(String clazzName)
public String getClazzName()
public void run()
throws IOException
IOExceptionpublic void closeIn()
public void closeOut()
Copyright © 2014. All rights reserved.