Template Control Language (TCL) - Demo 1

Template

org/jtools/demo/tmpl/manual/TCLDemo1.txttmpl
1. Text      : This text appears unchanged in the output.
2. Comment   : [#$This comment appears neither in the template nor in the output.$#]
3. Code      : [c$// This Java comment appears unchanged in the templet's execute method body.$c]
4. Expression: [$1 > 0 ? "1 > 0" : "1 <= 0"$] is evaluated at runtime.
5. Evaluation: [p$TCLDemo1.Property$p] is evaluated at parsing time.
6. Statement : [m$main()$m]generates a simple main method into the templet.
Let's compile this template with TmplC. We activate Core Group and Core Macros on Compiler-Level and set the property "TCLDemo1.Property" to "MY-PROPERTY-VALUE". We get the

Templet

org/jtools/demo/tmpl/manual/TCLDemo1.java
// This is a generated file. Do not modify it by hand.
package org.jtools.demo.tmpl.manual;
public class TCLDemo1 {
    public java.lang.String getTmplLanguageName() {
        return "txttmpl";
    }
    public java.lang.String getDestLanguageName() {
        return "txt";
    }
    public static void main(String[] args) {
        try {
            java.io.PrintStream outputstream;
        if (args.length == 0)
            outputstream=System.out;
        else {
            java.io.File outputfile = new java.io.File(args[0]);
    	    org.jtools.io.DirectoryOperations.mkfiledir(outputfile);
            outputstream = new java.io.PrintStream(new java.io.FileOutputStream(outputfile), true);
        }
        new org.jtools.demo.tmpl.manual.TCLDemo1().execute(outputstream);
        outputstream.close();
      }
      catch(Exception ex) {
        System.out.println("execution failed");
        ex.printStackTrace();
      }
    }
        
    public void execute(java.io.PrintStream out) {
        out.println("1. Text      : This text appears unchanged in the output.");
        out.println("2. Comment   : ");
        out.println("3. Code      : ");
        // This Java comment appears unchanged in the templet's execute method body.
        out.print("4. Expression: ");
        out.print(String.valueOf((1 > 0) ? "1 > 0" : "1 <= 0"));
        out.println(" is evaluated at runtime.");
        out.println("5. Evaluation: MY-PROPERTY-VALUE is evaluated at parsing time.");
        out.println("6. Statement : generates a simple main method into the templet.");
        out.flush();
    }
}
Let's compile this with javac
javac org/jtools/demo/templ/manual/TCLDemo1.java
execute it
java org.jtools.demo.tmpl.manual.TCLDemo1 org/jtools/demo/tmpl/manual/TCLDemo1.txt
and get the

Output

1. Text      : This text appears unchanged in the output.
2. Comment   : 
3. Code      : 
4. Expression: 1 > 0 is evaluated at runtime.
5. Evaluation: MY-PROPERTY-VALUE is evaluated at parsing time.
6. Statement : generates a simple main method into the templet.