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/28 00:59:09 UTC
cvs commit: jakarta-velocity/src/java/org/apache/velocity/injector Injector.java ForeachInjector.java IfInjector.java MethodInjector.java PropertyInjector.java VariableInjector.java
jvanzyl 00/08/27 15:59:08
Modified: src/java/org/apache/velocity/injector Injector.java
Removed: src/java/org/apache/velocity/injector ForeachInjector.java
IfInjector.java MethodInjector.java
PropertyInjector.java VariableInjector.java
Log:
- added class documentation for the injector.
Revision Changes Path
1.3 +107 -2 jakarta-velocity/src/java/org/apache/velocity/injector/Injector.java
Index: Injector.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/injector/Injector.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Injector.java 2000/08/26 18:47:01 1.2
+++ Injector.java 2000/08/27 22:59:06 1.3
@@ -54,7 +54,112 @@
* <http://www.apache.org/>.
*/
-public interface Injector
+import org.apache.velocity.Context;
+import org.apache.velocity.Template;
+import org.apache.velocity.parser.SimpleNode;
+import org.apache.velocity.visitor.InjectorVisitor;
+
+/**
+ * This class is responsible for storing the location
+ * of an injection point in a preparsed template, for
+ * storing the root of the <b>portion</b> of the AST
+ * responsible for producing dynamic content at the
+ * injection point.
+ *
+ * The Injector when called to fill in the preparsed
+ * template at the injection point by using a visitor
+ * to walk over the small portion of AST that is held
+ * in this object.
+ *
+ * For example, some dynamic content might be generated
+ * like this:
+ *
+ * #foreach $element in $list
+ * {
+ * This is the $element.
+ * }
+ *
+ * Now the AST for this small portion of the template
+ * may be represented like this (this was generated by
+ * the DumpVisitor):
+ *
+ * ForeachStatement
+ * Block
+ * Text
+ * Text
+ * Text
+ * Variable
+ * Text
+ *
+ * So to generate content at the injection point
+ * the Injector makes a visitor walk the little
+ * block listed above, the resultant content
+ * is placed into the preparsed template by
+ * the injector.
+ *
+ * So only where there is dynamic content will
+ * an Injector be used, all nodes that produced
+ * static text nodes by the original parsing
+ * process will be stored in the preparsed
+ * format. While all dynamic content locations
+ * or injection points will be stored and filled
+ * in when a request for the template is made.
+ *
+ * I still haven't thought about how to somehow
+ * store static portions within a dynamically
+ * generation section. Like above, it is a #foreach
+ * directive but there are static text nodes
+ * within. I'm not sure what performance impact
+ * might be gained by trying to store those
+ * static nodes. But if you had a very large
+ * $list to pass through the gain might be
+ * considerable. Regardless I haven't given
+ * it much thought other then it is a possible
+ * point of optimization.
+ *
+ * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
+ * @version $Id: Injector.java,v 1.3 2000/08/27 22:59:06 jvanzyl Exp $
+ */
+public abstract class Injector
{
- public void inject();
+ /** Where in the stream to inject this objects content */
+ protected int injectionLocation;
+ /** Context to build against */
+ protected Context context;
+ /**
+ * The root node of the _portion_ of the AST
+ * responsible for producing dynamic content
+ * this injector's location.
+ */
+ protected SimpleNode root;
+ /**
+ * The visitor used by the injector to generate
+ * dynamic content.
+ */
+ protected InjectorVisitor visitor;
+
+ // Actually we can reuse the visitor created by
+ // the template. So we can probably save the
+ // expense of visitor creation ... we just
+ // need access to the Template.
+
+ // Same actually goes for the context, we can
+ // just grab it from the Template. Sweet.
+
+ // And we probably don't need all these different
+ // types of injectors if we are going to reuse
+ // the visitor code. I'll leave things here for
+ // now. All we really need now in a concrete
+ // Injector.
+
+ public void inject()
+ {
+ }
+
+ public void setContext(Context context)
+ {
+ this.context = context;
+ }
+
+
}