public class MyVariableVisitor extends BaseVisitor
{
public static final String SOURCE_VERSION_ID = "$Id$";
public Object visit(ASTReference arg0, Object arg1)
{
String name = arg0.literal();
List tokenList = (List) arg1;
tokenList.add(name);
return super.visit(arg0, arg1);
}
}
public static void main(String[] args) throws Exception
{
Properties p = new Properties();
p.setProperty("file.resource.loader.path", "D:\\");
VelocityEngine vEngine = new VelocityEngine(p);
Template template = vEngine.getTemplate("just.html");
SimpleNode simpleNode = (SimpleNode) template.getData();
MyVariableVisitor mvVisitor = new MyVariableVisitor();
List tokenList = new ArrayList();
simpleNode.jjtAccept(mvVisitor, tokenList);
for (String item : tokenList)
{
System.out.println(item);
}
}
No comments:
Post a Comment