velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nbu...@apache.org
Subject svn commit: r697212 - /velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java
Date Fri, 19 Sep 2008 19:47:16 GMT
Author: nbubna
Date: Fri Sep 19 12:47:16 2008
New Revision: 697212

URL: http://svn.apache.org/viewvc?rev=697212&view=rev
Log:
misc cleanup/refactoring

Modified:
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java?rev=697212&r1=697211&r2=697212&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java
Fri Sep 19 12:47:16 2008
@@ -56,11 +56,6 @@
     private String sourceTemplate;
 
     /**
-     * Internal context adapter of macro caller.
-     */
-    private InternalContextAdapter context = null;
-
-    /**
      * Literal text of the macro
      */
     private String literal = null;
@@ -112,43 +107,46 @@
 
     /**
      * Intialize the Runtime macro. At the init time no implementation so we
-     * just save the values to use at the rende time.
+     * just save the values to use at the render time.
      *
      * @param rs runtime services
-     * @param context InternalContexAdapter
-     * @param node node conating the macro call
+     * @param context InternalContextAdapter
+     * @param node node containing the macro call
      */
     public void init(RuntimeServices rs, InternalContextAdapter context,
                      Node node)
     {
         super.init(rs, context, node);
         rsvc = rs;
-        this.context = context;
         this.node = node;
     }
-    
+
     /**
      * It is probably quite rare that we need to render the macro literal
      * so do it only on-demand and then cache the value. This tactic helps to
      * reduce memory usage a bit.
      */
-    private void makeLiteral()
+    private String getLiteral()
     {
-        StrBuilder buffer = new StrBuilder();
-        Token t = node.getFirstToken();
-        
-        while (t != null && t != node.getLastToken())
+        if (literal == null)
         {
-            buffer.append(t.image);
-            t = t.next;
-        }
+            StrBuilder buffer = new StrBuilder();
+            Token t = node.getFirstToken();
 
-        if (t != null)
-        {
-            buffer.append(t.image);
+            while (t != null && t != node.getLastToken())
+            {
+                buffer.append(t.image);
+                t = t.next;
+            }
+
+            if (t != null)
+            {
+                buffer.append(t.image);
+            }
+
+            literal = buffer.toString();
         }
-        
-        literal = buffer.toString();
+        return literal;
     }
     
 
@@ -218,7 +216,7 @@
             try
             {
             	// mainly check the number of arguments
-                vmProxy.init(rsvc, this.context, this.node);
+                vmProxy.init(rsvc, context, node);
             }
             catch (TemplateInitException die)
             {
@@ -232,10 +230,7 @@
         /**
          * If we cannot find an implementation write the literal text
          */
-         if( literal == null )
-            makeLiteral();
-         
-        writer.write(literal);
+        writer.write(getLiteral());
         return true;
     }
 }



Mime
View raw message