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/09/19 20:08:01 UTC
cvs commit: jakarta-velocity/src/java/org/apache/velocity/processor/javacc/visitor InjectorMode.java
jvanzyl 00/09/19 11:07:59
Modified: src/java/org/apache/velocity/processor/javacc/visitor
InjectorMode.java
Log:
- code cleanup, javadoc.
Revision Changes Path
1.2 +41 -14 jakarta-velocity/src/java/org/apache/velocity/processor/javacc/visitor/InjectorMode.java
Index: InjectorMode.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/processor/javacc/visitor/InjectorMode.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InjectorMode.java 2000/09/19 17:23:50 1.1
+++ InjectorMode.java 2000/09/19 18:07:55 1.2
@@ -69,17 +69,22 @@
import org.apache.velocity.processor.javacc.parser.*;
/**
- * This is an extension of the NoCacheMode visistor. Here
- * we are going to cache all the static content in the
- * top level block.
+ * This is an extension of the SinglePassMode visitor.
+ * This visitor passes over the AST storing all the static
+ * content and AST nodes in the top level. For each static
+ * text body and AST node pair an Injector is created. That
+ * is an Injector is created with a piece of static text
+ * and a node from the original AST. When this visitor
+ * is finished an array of Injectors is created.
*
- * Going to try and make a first version of an injector,
- * right now the injector will just hold a bit of the
- * AST. I would like to make this more efficient later
- * on, but this is a start.
+ * When the template is requested the array of Injectors
+ * is passed over: the static content is blown out and
+ * the SinglePassMode visitor is used to walk over the
+ * AST node held by a particular Injector. This is
+ * the first step toward an efficient caching system.
*
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
- * @version $Id: InjectorMode.java,v 1.1 2000/09/19 17:23:50 jvanzyl Exp $
+ * @version $Id: InjectorMode.java,v 1.2 2000/09/19 18:07:55 jvanzyl Exp $
*/
public class InjectorMode extends SinglePassMode
{
@@ -95,6 +100,14 @@
injectors = new ArrayList();
}
+ /**
+ * Take the parent node of the template
+ * and pass over it to create an array
+ * of injectors. Here we also instantiate
+ * a SinglePassMode visitor that will be
+ * used to merge the context with the
+ * static text of the template.
+ */
public void init(SimpleNode root)
{
visitor = new SinglePassMode();
@@ -108,6 +121,11 @@
size = injectorArray.length;
}
+ /**
+ * Merge the static text of the template
+ * with dynamic portions using the Context
+ * for the source of dynamic content.
+ */
public void merge() throws IOException
{
visitor.setContext(context);
@@ -119,6 +137,10 @@
writer.flush();
}
+ /**
+ * Create an Injector with a static piece of
+ * text and a node from the original AST.
+ */
private void createInjector(SimpleNode node)
{
// This is a hack to get only the top level
@@ -130,6 +152,11 @@
}
}
+ /**
+ * Create an array of injectors that can
+ * be subsequently passed over to create
+ * the finished document.
+ */
public Injector[] getInjectors()
{
int size = injectors.size();
@@ -141,41 +168,41 @@
return arrayOfInjectors;
}
+ /** Collect static elements of the template */
protected void print(String text)
{
staticBody.append(text);
}
+ /** Create an injector with an ASTReference node */
public Object visit(ASTReference node, Object data)
{
createInjector(node);
return data;
}
+ /** Create an injector with an ASTIfStatement node */
public Object visit(ASTIfStatement node, Object data)
{
createInjector(node);
return data;
}
+ // this can probably be removed. test.
public Object visit(ASTElseIfStatement node, Object data)
{
return data;
}
+ /** Create an injector with an ASTForeachStatement node */
public Object visit(ASTForeachStatement node, Object data)
{
createInjector(node);
return data;
}
+ /** Create an injector with an ASTSetStatement node */
public Object visit(ASTSetStatement node, Object data)
- {
- createInjector(node);
- return data;
- }
-
- public Object visit(ASTParamStatement node, Object data)
{
createInjector(node);
return data;