1 package org.apache.velocity.test.view; 2 3 18 19 import java.io.IOException ; 20 import java.io.PrintWriter ; 21 import java.io.FileInputStream ; 22 import java.io.BufferedReader ; 23 import java.io.InputStreamReader ; 24 25 import org.apache.velocity.runtime.RuntimeSingleton; 26 27 import org.apache.velocity.runtime.visitor.NodeViewMode; 28 import org.apache.velocity.runtime.parser.node.SimpleNode; 29 30 34 public class TemplateNodeView 35 { 36 40 private SimpleNode document; 41 42 48 private NodeViewMode visitor; 49 50 56 public TemplateNodeView(String template) 57 { 58 try 59 { 60 RuntimeSingleton.init("velocity.properties"); 61 62 InputStreamReader isr = new InputStreamReader ( 63 new FileInputStream (template), 64 RuntimeSingleton.getString(RuntimeSingleton.INPUT_ENCODING)); 65 66 BufferedReader br = new BufferedReader ( isr ); 67 68 document = RuntimeSingleton.parse( br, template); 69 70 visitor = new NodeViewMode(); 71 visitor.setContext(null); 72 visitor.setWriter(new PrintWriter (System.out)); 73 document.jjtAccept(visitor, null); 74 } 75 catch (Exception e) 76 { 77 System.out.println(e); 78 e.printStackTrace(); 79 } 80 } 81 82 83 public static void main(String args[]) 84 { 85 TemplateNodeView v = new TemplateNodeView(args[0]); 86 } 87 } 88 | Popular Tags |