geirm 01/02/25 20:02:33
Modified: src/java/org/apache/velocity/test/misc Test.java
Log:
Added a try/catch around getTemplate() so it will report any problems. Not
much use to users, but demonstrates how to deal with it, and more importantly
Test is easier for us to use :)
Revision Changes Path
1.16 +26 -7
jakarta-velocity/src/java/org/apache/velocity/test/misc/Test.java
Index: Test.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/test/misc/Test.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- Test.java 2001/02/15 12:30:27 1.15
+++ Test.java 2001/02/26 04:02:32 1.16
@@ -74,6 +74,9 @@
import org.apache.velocity.app.FieldMethodizer;
import org.apache.velocity.app.Velocity;
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
+
import org.apache.velocity.runtime.Runtime;
import org.apache.velocity.test.provider.TestProvider;
@@ -83,7 +86,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
- * @version $Id: Test.java,v 1.15 2001/02/15 12:30:27 geirm Exp $
+ * @version $Id: Test.java,v 1.16 2001/02/26 04:02:32 geirm Exp $
*/
public class Test
{
@@ -162,7 +165,20 @@
if (templateFile == null)
templateFile = "examples/example.vm";
- Template template = Runtime.getTemplate(templateFile);
+ Template template = null;
+
+ try
+ {
+ template = Runtime.getTemplate(templateFile);
+ }
+ catch( ResourceNotFoundException rnfe )
+ {
+ System.out.println("Test : Cannot find template " + templateFile );
+ }
+ catch( ParseErrorException pee )
+ {
+ System.out.println("Test : Syntax error in template " +
templateFile + ":" + pee );
+ }
/*
* now, make a Context object and populate it.
@@ -216,12 +232,15 @@
/*
* make a writer, and merge the template 'against' the context
*/
-
- writer = new BufferedWriter(new OutputStreamWriter(System.out));
- template.merge( context , writer);
- writer.flush();
- writer.close();
+ if( template != null)
+ {
+ writer = new BufferedWriter(new OutputStreamWriter(System.out));
+ template.merge( context , writer);
+ writer.flush();
+ writer.close();
+ }
+
}
catch( Exception e )
{