velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nbu...@apache.org
Subject svn commit: r679929 - in /velocity/engine/trunk/src/java/org/apache/velocity/runtime: ./ directive/ parser/node/
Date Fri, 25 Jul 2008 23:32:56 GMT
Author: nbubna
Date: Fri Jul 25 16:32:56 2008
New Revision: 679929

URL: http://svn.apache.org/viewvc?rev=679929&view=rev
Log:
BufferedReaders are rather pointless with StringReaders

Modified:
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeServices.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/VelocimacroManager.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Evaluate.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VMProxyArg.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java?rev=679929&r1=679928&r2=679929&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java Fri Jul
25 16:32:56 2008
@@ -1001,6 +1001,29 @@
      *  PARSER_POOL_SIZE property appropriately for their
      *  application.  We will revisit this.
      *
+     * @param string String to be parsed
+     * @param templateName name of the template being parsed
+     * @return A root node representing the template as an AST tree.
+     * @throws ParseException When the string could not be parsed as a template.
+     */
+    public SimpleNode parse(String string, String templateName)
+        throws ParseException
+    {
+        return parse(new StringReader(string), templateName);
+    }
+
+    /**
+     * Parse the input and return the root of
+     * AST node structure.
+     * <br><br>
+     *  In the event that it runs out of parsers in the
+     *  pool, it will create and let them be GC'd
+     *  dynamically, logging that it has to do that.  This
+     *  is considered an exceptional condition.  It is
+     *  expected that the user will set the
+     *  PARSER_POOL_SIZE property appropriately for their
+     *  application.  We will revisit this.
+     *
      * @param reader Reader retrieved by a resource loader
      * @param templateName name of the template being parsed
      * @return A root node representing the template as an AST tree.
@@ -1091,8 +1114,7 @@
     public boolean evaluate(Context context,  Writer out,
                             String logTag, String instring) throws IOException
     {
-        return evaluate(context, out, logTag,
-                        new BufferedReader(new StringReader(instring)));
+        return evaluate(context, out, logTag, new StringReader(instring));
     }
 
     /**

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeServices.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeServices.java?rev=679929&r1=679928&r2=679929&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeServices.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeServices.java Fri Jul
25 16:32:56 2008
@@ -150,6 +150,13 @@
     public void init(String configurationFile) throws Exception;
 
     /**
+     * Wraps the String in a StringReader and passes it off to
+     * {@link #parse(Reader,String)}.
+     */
+    public SimpleNode parse(String string, String templateName)
+        throws ParseException;
+
+    /**
      * Parse the input and return the root of
      * AST node structure.
      * <br><br>

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/VelocimacroManager.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/VelocimacroManager.java?rev=679929&r1=679928&r2=679929&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/VelocimacroManager.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/VelocimacroManager.java Fri
Jul 25 16:32:56 2008
@@ -19,8 +19,6 @@
  * under the License.    
  */
 
-import java.io.BufferedReader;
-import java.io.StringReader;
 import java.util.Hashtable;
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.exception.ParseErrorException;
@@ -483,9 +481,7 @@
         {
             try
             {
-                BufferedReader br = new BufferedReader(new StringReader(macroBody));
-
-                nodeTree = rsvc.parse(br, "VM:" + vmName, true);
+                nodeTree = rsvc.parse(macroBody, "VM:" + vmName);
                 nodeTree.init(ica, null);
             }
             catch (ParseException pex)

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Evaluate.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Evaluate.java?rev=679929&r1=679928&r2=679929&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Evaluate.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Evaluate.java Fri
Jul 25 16:32:56 2008
@@ -19,10 +19,7 @@
  * under the License.    
  */
 
-import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
 import java.io.Writer;
 
 import org.apache.velocity.context.EvaluateContext;
@@ -154,14 +151,12 @@
         /*
          * The new string needs to be parsed since the text has been dynamically generated.
          */
-        
-        Reader reader = new BufferedReader(new StringReader(sourceText));
         String templateName = context.getCurrentTemplateName();
         SimpleNode nodeTree = null;
 
         try
         {
-            nodeTree = rsvc.parse(reader, templateName);
+            nodeTree = rsvc.parse(sourceText, templateName);
         }
         catch (ParseException pex)
         {

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VMProxyArg.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VMProxyArg.java?rev=679929&r1=679928&r2=679929&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VMProxyArg.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VMProxyArg.java Fri
Jul 25 16:32:56 2008
@@ -19,10 +19,9 @@
  * under the License.    
  */
 
-import java.io.BufferedReader;
-import java.io.StringReader;
 import java.io.StringWriter;
 
+import org.apache.commons.lang.text.StrBuilder;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.context.InternalContextAdapterImpl;
@@ -395,14 +394,12 @@
                      *   just want the parser to consider our arg as a Directive/VM arg rather
than
                      *   as if inline in schmoo
                      */
+                    String buff = new StrBuilder("#include(")
+                        .append(callerReference)
+                        .append(")")
+                        .toString();
 
-                    String buff ="#include(" + callerReference + " ) ";
-
-                    //ByteArrayInputStream inStream = new ByteArrayInputStream( buff.getBytes()
);
-
-                    BufferedReader br = new BufferedReader( new StringReader( buff ) );
-
-                    nodeTree = rsvc.parse(br, "VMProxyArg:" + callerReference, true);
+                    nodeTree = rsvc.parse(buff, "VMProxyArg:" + callerReference);
 
                     /*
                      *  now, our tree really is the first DirectiveArg(), and only one

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java?rev=679929&r1=679928&r2=679929&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
Fri Jul 25 16:32:56 2008
@@ -382,13 +382,11 @@
     {
         try
         {
-            BufferedReader br = new BufferedReader( new StringReader( macroBody ) );
-
             /*
              *  now parse the macro - and don't dump the namespace
              */
 
-            nodeTree = rsvc.parse( br, namespace, false );
+            nodeTree = rsvc.parse(new StringReader(macroBody), namespace, false );
 
             /*
              *  now, to make null references render as proper schmoo

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java?rev=679929&r1=679928&r2=679929&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
Fri Jul 25 16:32:56 2008
@@ -17,7 +17,6 @@
  * the License.
  */
 
-import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.StringReader;
 import java.io.StringWriter;
@@ -148,8 +147,7 @@
             /*
              * now parse and init the nodeTree
              */
-            BufferedReader br = new BufferedReader(new StringReader(
-                    interpolateimage));
+            StringReader br = new StringReader(interpolateimage);
 
             /*
              * it's possible to not have an initialization context - or we don't



Mime
View raw message