You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Josh Lucas <jo...@stonecottage.com> on 2000/08/25 08:57:06 UTC

[Patch] Template.java / Test.java

Below is a patch which I did to get Velocity to return the parsed
document.  I also updated Test.java to reflect these changes.  I was
able to move from a WebMacro page to Velocity fairly quickly once I
figured out the NPE that was being throw within the Exception.  You can
see the simple finished product at http://www.diarylog.org.

Anyways, here's the patch.  Great work!


josh


Index: Template.java
===================================================================
RCS file:
/home/cvspublic/jakarta-velocity/src/java/org/apache/velocity/Template.java,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 Template.java
--- Template.java       2000/08/24 21:42:46     1.1.1.1
+++ Template.java       2000/08/25 06:48:31
@@ -67,6 +67,7 @@
  *
  * template.setContext(context);
  * template.parse();
+ * String output = template.getOutput();
  */
 public class Template
 {
@@ -76,6 +77,8 @@
     protected Parser parser;
     /** The context against which the template is parsed */
     protected Context context;
+    /** The output of the parsed template */
+    protected String output;
 
     public Template(String template)
     {
@@ -92,6 +95,11 @@
         this.context = context;
     }
 
+    public String getOutput()
+    {
+        return output;
+    }
+
     public void parse()
     {
         try
@@ -102,11 +110,10 @@
             //DumpVisitor visitor = new DumpVisitor();
             visitor.setContext(context);
             parser.getRoot().jjtAccept(visitor, null);
-            System.out.println(visitor.getDocument());
+            this.output = visitor.getDocument();
         }
         catch(Exception e)
         {
-            System.out.println("!! " + parser.token.image);
             System.out.println(e);
             e.printStackTrace();
         }

Index: Test.java
===================================================================
RCS file:
/home/cvspublic/jakarta-velocity/src/java/org/apache/velocity/Test.java,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 Test.java
--- Test.java   2000/08/24 21:42:46     1.1.1.1
+++ Test.java   2000/08/25 06:53:04
@@ -75,6 +75,7 @@
         
         template.setContext(context);
         template.parse();
+        System.out.println(template.getDocument());
     }
 
     public static void main(String[] args)