You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by jv...@locus.apache.org on 2000/08/26 09:55:07 UTC
cvs commit: jakarta-velocity/src/java/org/apache/velocity Template.java Test.java Utils.java
jvanzyl 00/08/26 00:55:07
Modified: src/java/org/apache/velocity Template.java Test.java
Removed: src/java/org/apache/velocity Utils.java
Log:
- first whack at preparsed templates.
Revision Changes Path
1.3 +23 -16 jakarta-velocity/src/java/org/apache/velocity/Template.java
Index: Template.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/Template.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Template.java 2000/08/25 06:59:49 1.2
+++ Template.java 2000/08/26 07:55:06 1.3
@@ -55,8 +55,10 @@
*/
import org.apache.velocity.parser.Parser;
+import org.apache.velocity.parser.SimpleNode;
import org.apache.velocity.visitor.ProcessVisitor;
import org.apache.velocity.visitor.DumpVisitor;
+import org.apache.velocity.injector.*;
/**
* Template template = new Template("test.bm");
@@ -67,7 +69,6 @@
*
* template.setContext(context);
* template.parse();
- * String output = template.getOutput();
*/
public class Template
{
@@ -77,9 +78,15 @@
protected Parser parser;
/** The context against which the template is parsed */
protected Context context;
- /** The output of the parsed template */
- protected String output;
-
+ /** An array of injectors that will be used to inject
+ * content into a preparsed template.
+ */
+ protected Injector[] injectors;
+ /** The root of the AST */
+ SimpleNode root;
+
+ protected ProcessVisitor visitor;
+
public Template(String template)
{
this.template = template;
@@ -94,28 +101,28 @@
{
this.context = context;
}
-
- public String getOutput()
- {
- return output;
- }
- public void parse()
+ public void preParse()
{
try
{
parser = new Parser(template);
parser.parse();
- ProcessVisitor visitor = new ProcessVisitor();
- //DumpVisitor visitor = new DumpVisitor();
- visitor.setContext(context);
- parser.getRoot().jjtAccept(visitor, null);
- this.output = visitor.getDocument();
- }
+ visitor = new ProcessVisitor();
+ root = parser.getRoot();
+ }
catch(Exception e)
{
System.out.println(e);
e.printStackTrace();
}
+
}
+
+ public void parse()
+ {
+ visitor.setContext(context);
+ root.jjtAccept(visitor, null);
+ System.out.println(visitor.getDocument());
+ }
}
1.4 +3 -1 jakarta-velocity/src/java/org/apache/velocity/Test.java
Index: Test.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/Test.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Test.java 2000/08/25 18:26:58 1.3
+++ Test.java 2000/08/26 07:55:07 1.4
@@ -73,9 +73,11 @@
context.put("list", al);
+
+ template.preParse();
+
template.setContext(context);
template.parse();
- System.out.println(template.getOutput());
}
public static void main(String[] args)
Re: cvs commit: jakarta-velocity/src/java/org/apache/velocity
Template.java Test.java Utils.java
Posted by Josh Lucas <jo...@stonecottage.com>.
So, how can one get the actual parsed data?
I didn't see a way so I created the getOutput() method and stored the
parsed data in a String.
That was the reason I sent the orginal patch.
josh