<?xml version="1.0"?>
<tl>
package com.craigc.progen;
import org.w3c.dom.*;
import java.io.*;
import java.util.*;
<for path="//declare/@import">
import <value path="."/>;
</for>
<java>
String className = getClassName(context.evalString("//declare/@classname"));
</java>
public class <expr>className</expr> {
Properties properties = new Properties();
<for path="//declarations">
<value path="."/>
</for>
public boolean generate(XPathContext context, ProgramWriter out) {
try {
<java>generate2(context, out); </java>
} catch (Exception e) {
System.out.println("Exception: "+e.getMessage());
e.printStackTrace();
return false;
}
return true;
}
public static void main(String[] args) {
try {
ProgramWriter out = args.length>=2
?new ProgramWriter(new FileOutputStream(args[1]))
:new ProgramWriter(System.out);
<expr>className</expr> pg = new <expr>className</expr>();
for (int j=1; jlt;=args.length; ++j) {
pg.properties.put("arg"+j, args[j-1]);
}
pg.generate(new XPathContext(args[0]), out);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
String[][] history = {
{ "<expr>new Date()</expr>", // date this file was generated
<expr>quoteString(properties.getProperty("arg1"))</expr>,
<expr>quoteString(properties.getProperty("arg2"))</expr> },
<java whitespace="reverse">
for (int j=0; j<history.length; ++j) {
out.print(" ");
for (int k=0; k<history[j].length; ++k) {
out.print(quoteString(history[j][k])+", ");
}
out.println("}, ");
}
</java>
};
}
<declarations>
String ind = " ";
int uid = 0;
public boolean generate2(XPathContext context, ProgramWriter out) {
// See Example 12-28
}
public String quoteString(String t) {
// add quotes and convert new lines, tabs quotes
}
public String strip(String t) {
// remove trailing white space characters
}
public String getClassName(String className) {
// if className is an empty string, get class name from properties.get("arg2")
}
</declarations>
</tl>
|