velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r998294 - in /velocity/sandbox/maven-reorg/tools/trunk: velocity-tools-generic/ velocity-tools-generic/src/main/java/org/apache/velocity/tools/ velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ velocity-tools-generic/s...
Date Fri, 17 Sep 2010 20:03:18 GMT
Author: apetrelli
Date: Fri Sep 17 20:03:18 2010
New Revision: 998294

URL: http://svn.apache.org/viewvc?rev=998294&view=rev
Log:
Merge from tools trunk to sandboxed 2.1.

Added:
    velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/BaseTestCase.java
      - copied, changed from r995744, velocity/tools/trunk/src/test/java/org/apache/velocity/tools/generic/BaseTestCase.java
    velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/MockLogChute.java
      - copied, changed from r995744, velocity/tools/trunk/src/test/java/org/apache/velocity/tools/generic/TestLogChute.java
    velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/Veltools128Tests.java
      - copied unchanged from r995744, velocity/tools/trunk/src/test/java/org/apache/velocity/tools/generic/Veltools128Tests.java
Modified:
    velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/   (props changed)
    velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ConversionUtils.java
    velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/DisplayTool.java
    velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LoopTool.java
    velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/LoopToolTests.java
    velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-view/   (props changed)
    velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java

Propchange: velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/
------------------------------------------------------------------------------
    svn:mergeinfo = /velocity/tools/trunk:990897-995744

Modified: velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ConversionUtils.java
URL: http://svn.apache.org/viewvc/velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ConversionUtils.java?rev=998294&r1=998293&r2=998294&view=diff
==============================================================================
--- velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ConversionUtils.java
(original)
+++ velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ConversionUtils.java
Fri Sep 17 20:03:18 2010
@@ -32,6 +32,8 @@ import java.util.Date;
 import java.util.Calendar;
 import java.util.Locale;
 import java.util.TimeZone;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * Utility methods for parsing or otherwise converting between types.
@@ -50,6 +52,9 @@ public class ConversionUtils
     //NOTE: '3' belongs to a non-public "scientific" style
     private static final int STYLE_INTEGER      = 4;
 
+    // cache custom formats
+    private static ConcurrentMap<String,NumberFormat> customFormatsCache = new ConcurrentHashMap<String,NumberFormat>();
+
     private ConversionUtils() {}
 
     public ConversionUtils getInstance()
@@ -83,7 +88,13 @@ public class ConversionUtils
         if (style < 0)
         {
             // we have a custom format
-            nf = new DecimalFormat(format, new DecimalFormatSymbols(locale));
+            String cacheKey = format + "%" + locale.toString();
+            nf = customFormatsCache.get(cacheKey);
+            if( nf == null )
+            {
+                nf = new DecimalFormat(format, new DecimalFormatSymbols(locale));
+                customFormatsCache.put(cacheKey,nf);
+            }
         }
         else
         {

Modified: velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/DisplayTool.java
URL: http://svn.apache.org/viewvc/velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/DisplayTool.java?rev=998294&r1=998293&r2=998294&view=diff
==============================================================================
--- velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/DisplayTool.java
(original)
+++ velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/DisplayTool.java
Fri Sep 17 20:03:18 2010
@@ -101,6 +101,8 @@ public class DisplayTool extends LocaleC
      */
     protected void configure(ValueParser values)
     {
+        super.configure(values);
+        
         String listDelim = values.getString(LIST_DELIM_KEY);
         if (listDelim != null)
         {

Modified: velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LoopTool.java
URL: http://svn.apache.org/viewvc/velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LoopTool.java?rev=998294&r1=998293&r2=998294&view=diff
==============================================================================
--- velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LoopTool.java
(original)
+++ velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/LoopTool.java
Fri Sep 17 20:03:18 2010
@@ -94,6 +94,7 @@ public class LoopTool
 {
     private Stack<ManagedIterator> iterators = new Stack<ManagedIterator>();
     private ManagedIterator last;
+    private Map<String,Object> lastSyncedValues;
 
     /**
      * <p>Tells the LoopTool to watch the specified Array, Collection, Map,
@@ -401,6 +402,14 @@ public class LoopTool
                 return iterator.get(key);
             }
         }
+        if (lastSyncedValues != null)
+        {
+            Object syncedValue = lastSyncedValues.get(key);
+            if (syncedValue != null)
+            {
+                return syncedValue;
+            }
+        }
         // shortest key would be "last_X" where X is the loop name
         if (key == null || key.length() < 6)
         {
@@ -553,7 +562,9 @@ public class LoopTool
      */
     protected ManagedIterator pop()
     {
-        return iterators.pop();
+        ManagedIterator i = iterators.pop();
+        this.lastSyncedValues = i.getLastSyncedValues();
+        return i;
     }
 
 
@@ -739,9 +750,6 @@ public class LoopTool
                     }
                 }
             }
-
-            // ok, looks like we have a next that met all the conditions
-            shiftSynced();
             return true;
         }
 
@@ -839,6 +847,8 @@ public class LoopTool
             Object value = this.next;
             // clear the cache
             this.next = null;
+            // call next on synced ones
+            shiftSynced();
             // return the no-longer-cached value
             return value;
         }
@@ -905,7 +915,7 @@ public class LoopTool
          * <p>Adds another iterator to be kept in sync with the one
          * being managed by this instance.  The values of the parallel
          * iterator can be retrieved from the LoopTool under the
-         * name s"synced" (e.g. $loop.synched or $loop.get('synced'))
+         * name s"synced" (e.g. $loop.synced or $loop.get('synced'))
          * and are automatically updated for each iteration by this instance.
          * </p><p><b>NOTE</b>: if you are sync'ing multiple iterators
          * with the same managed iterator, you must use 
@@ -948,6 +958,20 @@ public class LoopTool
             return this;
         }
 
+        public Map<String,Object> getLastSyncedValues()
+        {
+            if (synced == null)
+            {
+                return null;
+            }
+            Map<String,Object> syncs = new HashMap<String,Object>();
+            for (String key : synced.keySet())
+            {
+                syncs.put(key, synced.get(key).get());
+            }
+            return syncs;
+        }
+
         @Override
         public String toString()
         {

Copied: velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/BaseTestCase.java
(from r995744, velocity/tools/trunk/src/test/java/org/apache/velocity/tools/generic/BaseTestCase.java)
URL: http://svn.apache.org/viewvc/velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/BaseTestCase.java?p2=velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/BaseTestCase.java&p1=velocity/tools/trunk/src/test/java/org/apache/velocity/tools/generic/BaseTestCase.java&r1=995744&r2=998294&rev=998294&view=diff
==============================================================================
--- velocity/tools/trunk/src/test/java/org/apache/velocity/tools/generic/BaseTestCase.java
(original)
+++ velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/BaseTestCase.java
Fri Sep 17 20:03:18 2010
@@ -40,7 +40,7 @@ public abstract class BaseTestCase exten
     protected VelocityEngine engine;
     protected VelocityContext context;
     protected boolean DEBUG = false;
-    protected TestLogChute log;
+    protected MockLogChute log;
     protected String stringRepoName = "string.repo";
 
     public BaseTestCase(String name)
@@ -61,9 +61,9 @@ public abstract class BaseTestCase exten
         engine = new VelocityEngine();
 
         //by default, make the engine's log output go to the test-report
-        log = new TestLogChute(false, false);
-        log.setEnabledLevel(TestLogChute.INFO_ID);
-        log.setSystemErrLevel(TestLogChute.WARN_ID);
+        log = new MockLogChute(false, false);
+        log.setEnabledLevel(MockLogChute.INFO_ID);
+        log.setSystemErrLevel(MockLogChute.WARN_ID);
         engine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, log);
 
         // use string resource loader by default, instead of file

Modified: velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/LoopToolTests.java
URL: http://svn.apache.org/viewvc/velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/LoopToolTests.java?rev=998294&r1=998293&r2=998294&view=diff
==============================================================================
--- velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/LoopToolTests.java
(original)
+++ velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/LoopToolTests.java
Fri Sep 17 20:03:18 2010
@@ -306,16 +306,18 @@ public class LoopToolTests {
         // is, of course, impossible in a template, but it
         // makes writing a reasonable test for this method a lot
         // easier.
-        //NOTE: this reliese on the default name for synced iterators
+        //NOTE: this relies on the default name for synced iterators
         //      being "synced", for i being "loop0", and for j being "loop1"
         Iterator i = loop.watch(ARRAY).sync(other);
         Iterator j = loop.watch(other).sync(ARRAY);
         while (i.hasNext() && j.hasNext())
         {
+            Object ival = i.next();
+            Object jval = j.next();
             // i and loop.synced (aka loop.get("loop1","synced")) should match
-            assertEquals(i.next(), loop.get("synced"));
+            assertEquals(ival, loop.get("synced"));
             // j and loop.get("loop0","synced") should match
-            assertEquals(j.next(), loop.get("loop0", "synced"));
+            assertEquals(jval, loop.get("loop0", "synced"));
         }
     }
 

Copied: velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/MockLogChute.java
(from r995744, velocity/tools/trunk/src/test/java/org/apache/velocity/tools/generic/TestLogChute.java)
URL: http://svn.apache.org/viewvc/velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/MockLogChute.java?p2=velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/MockLogChute.java&p1=velocity/tools/trunk/src/test/java/org/apache/velocity/tools/generic/TestLogChute.java&r1=995744&r2=998294&rev=998294&view=diff
==============================================================================
--- velocity/tools/trunk/src/test/java/org/apache/velocity/tools/generic/TestLogChute.java
(original)
+++ velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/MockLogChute.java
Fri Sep 17 20:03:18 2010
@@ -34,7 +34,7 @@ import org.apache.velocity.runtime.log.S
  * @author Nathan Bubna
  * @version $Id: TestLogChute.java 749684 2009-03-03 18:38:16Z nbubna $
  */
-public class TestLogChute extends SystemLogChute
+public class MockLogChute extends SystemLogChute
 {
     public static final String TEST_LOGGER_LEVEL = "runtime.log.logsystem.test.level";
 
@@ -43,13 +43,13 @@ public class TestLogChute extends System
     private boolean suppress = true;
     private boolean capture = true;
 
-    public TestLogChute()
+    public MockLogChute()
     {
         log = new ByteArrayOutputStream();
         systemDotIn = new PrintStream(log, true);
     }
 
-    public TestLogChute(boolean suppress, boolean capture)
+    public MockLogChute(boolean suppress, boolean capture)
     {
         this();
         this.suppress = suppress;

Propchange: velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-view/
------------------------------------------------------------------------------
    svn:mergeinfo = /velocity/tools/trunk:990897-995744

Modified: velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java
URL: http://svn.apache.org/viewvc/velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java?rev=998294&r1=998293&r2=998294&view=diff
==============================================================================
--- velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java
(original)
+++ velocity/sandbox/maven-reorg/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java
Fri Sep 17 20:03:18 2010
@@ -337,14 +337,16 @@ public class VelocityViewServlet extends
                          HttpServletResponse response,
                          Throwable e)
     {
-        if (!response.isCommitted())
+        String path = ServletUtils.getPath(request);
+        if (response.isCommitted())
         {
+            getLog().error("An error occured but the response headers have already been sent.");
+            getLog().error("Error processing a template for path '" + path + "'", e);
             return;
         }
         
         try
         {
-            String path = ServletUtils.getPath(request);
             getLog().error("Error processing a template for path '" + path + "'", e);
             StringBuilder html = new StringBuilder();
             html.append("<html>\n");



Mime
View raw message