1 package org.apache.velocity.example; 2 /* 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 */ 20 21 import org.apache.velocity.Template; 22 import org.apache.velocity.runtime.RuntimeSingleton; 23 24 import java.io.BufferedWriter; 25 import java.io.OutputStreamWriter; 26 import java.io.Writer; 27 import java.util.Hashtable; 28 import java.util.Properties; 29 30 /** 31 * the ultimate in silliness... 32 * 33 * tests the DBContext example by putting a string and a hashtable 34 * into the context and then rendering a simple template with it. 35 * 36 * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a> 37 * @version $Id$ 38 */ 39 40 public class DBContextTest 41 { DBContextTest(String templateFile)42 public DBContextTest(String templateFile) 43 { 44 try 45 { 46 RuntimeSingleton.init( new Properties() ); 47 48 Template template = RuntimeSingleton.getTemplate(templateFile); 49 50 DBContext dbc = new DBContext(); 51 52 Hashtable h = new Hashtable(); 53 h.put("Bar", "this is from a hashtable!"); 54 55 dbc.put( "string", "Hello!"); 56 dbc.put( "hashtable", h ); 57 58 Writer writer = new BufferedWriter(new OutputStreamWriter(System.out)); 59 60 template.merge(dbc, writer); 61 62 writer.flush(); 63 writer.close(); 64 } 65 catch( Exception e ) 66 { 67 RuntimeSingleton.getLog().error("Something funny happened", e); 68 } 69 } 70 main(String[] args)71 public static void main(String[] args) 72 { 73 DBContextTest t; 74 t = new DBContextTest(args[0]); 75 } 76 } 77