KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > DBContextTest


1
2 import java.io.BufferedWriter JavaDoc;
3 import java.io.OutputStreamWriter JavaDoc;
4 import java.io.Writer JavaDoc;
5
6 import java.util.Hashtable JavaDoc;
7 import java.util.Vector JavaDoc;
8 import java.util.Properties JavaDoc;
9
10 import org.apache.velocity.Template;
11
12 import org.apache.velocity.runtime.Runtime;
13
14 /**
15  * the ultimate in silliness...
16  *
17  * tests the DBContext example by putting a string and a hashtable
18  * into the context and then rendering a simple template with it.
19  *
20  * @author <a HREF="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
21  * @version $Id: DBContextTest.java,v 1.1 2001/02/12 03:11:25 geirm Exp $
22  */

23
24 public class DBContextTest
25 {
26     public DBContextTest(String JavaDoc templateFile)
27     {
28         try
29         {
30             Runtime.init( new Properties JavaDoc() );
31  
32             Template template = Runtime.getTemplate(templateFile);
33
34             DBContext dbc = new DBContext();
35
36             Hashtable JavaDoc h = new Hashtable JavaDoc();
37             h.put("Bar", "this is from a hashtable!");
38        
39             dbc.put( "string", "Hello!");
40             dbc.put( "hashtable", h );
41             
42             Writer JavaDoc writer = new BufferedWriter JavaDoc(new OutputStreamWriter JavaDoc(System.out));
43        
44             template.merge(dbc, writer);
45
46             writer.flush();
47             writer.close();
48         }
49         catch( Exception JavaDoc e )
50         {
51             Runtime.error(e);
52         }
53     }
54
55     public static void main(String JavaDoc[] args)
56     {
57         DBContextTest t;
58         t = new DBContextTest(args[0]);
59     }
60 }
61
Popular Tags