velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nbu...@apache.org
Subject svn commit: r545419 - in /velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic: AlternatorTool.java DisplayTool.java RenderTool.java ResourceTool.java
Date Fri, 08 Jun 2007 05:20:30 GMT
Author: nbubna
Date: Thu Jun  7 22:20:29 2007
New Revision: 545419

URL: http://svn.apache.org/viewvc?view=rev&rev=545419
Log:
use new config base classes

Modified:
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/AlternatorTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/DisplayTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/RenderTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/ResourceTool.java

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/AlternatorTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/AlternatorTool.java?view=diff&rev=545419&r1=545418&r2=545419
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/AlternatorTool.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/AlternatorTool.java
Thu Jun  7 22:20:29 2007
@@ -56,7 +56,7 @@
  * @version $Revision$ $Date$
  */
 @DefaultKey("alternator")
-public class AlternatorTool
+public class AlternatorTool extends AbstractLockConfig
 {
     /** @since VelocityTools 1.3 */
     public static final String AUTO_ALTERNATE_DEFAULT_KEY = "auto-alternate";
@@ -67,11 +67,9 @@
     /**
      * Looks for a default auto-alternate value in the given params,
      * if not, set the default to true.
-     * @since VelocityTools 1.3
      */
-    public void configure(Map params)
+    protected void configure(ValueParser parser)
     {
-        ValueParser parser = new ValueParser(params);
         // it's true by default in Alternator
         autoAlternateDefault =
             parser.getBoolean(AUTO_ALTERNATE_DEFAULT_KEY, true);

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/DisplayTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/DisplayTool.java?view=diff&rev=545419&r1=545418&r2=545419
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/DisplayTool.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/DisplayTool.java
Thu Jun  7 22:20:29 2007
@@ -19,10 +19,12 @@
  * under the License.    
  */
 
+import java.lang.reflect.Array;
 import java.util.Arrays;
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Iterator;
-import java.util.Map;
 import org.apache.velocity.tools.config.DefaultKey;
 
 /**
@@ -63,9 +65,8 @@
  * @version $Id: DisplayTool.java 463298 2006-10-12 16:10:32Z henning $
  */
 @DefaultKey("display")
-public class DisplayTool
+public class DisplayTool extends AbstractLockConfig
 {
-    public static final String LOCK_CONFIG_KEY = "lock-config";
     public static final String LIST_DELIM_KEY = "listDelim";
     public static final String LIST_FINAL_DELIM_KEY = "listFinalDelim";
     public static final String TRUNCATE_MAX_LENGTH_KEY = "truncateMaxLength";
@@ -77,23 +78,6 @@
     private int defaultMaxLength = 30;
     private String defaultSuffix = "...";
     private String defaultAlternate = "null";
-    private boolean configLocked = false;
-
-    /**
-     * Looks for configuration values in the given params.
-     */
-    public void configure(Map params)
-    {
-        if (!configLocked)
-        {
-            ValueParser values = new ValueParser(params);
-            configure(values);
-
-            // by default, lock down this method after use
-            // to prevent templates from re-configuring this instance
-            configLocked = values.getBoolean(LOCK_CONFIG_KEY, true);
-        }
-    }
 
     /**
      * Does the actual configuration. This is protected, so
@@ -195,14 +179,29 @@
      */
     public String list(Object list, String delim, String finaldelim)
     {
+        if (list == null)
+        {
+            return null;
+        }
         if (list instanceof Collection)
         {
             return format((Collection)list, delim, finaldelim);
         }
+        Collection items;
+        if (list.getClass().isArray())
+        {
+            int size = Array.getLength(list);
+            items = new ArrayList(size);
+            for (int i=0; i < size; i++)
+            {
+                items.add(Array.get(list, i));
+            }
+        }
         else
         {
-            return format(Arrays.asList(list), delim, finaldelim);
+            items = Collections.singletonList(list);
         }
+        return format(items, delim, finaldelim);
     }
 
     /**
@@ -212,6 +211,7 @@
     {
         StringBuilder sb = new StringBuilder();
         int size = list.size();
+System.out.println("formatting "+size+" items");
         Iterator iterator = list.iterator();
         for (int i = 0; i < size; i++)
         {

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/RenderTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/RenderTool.java?view=diff&rev=545419&r1=545418&r2=545419
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/RenderTool.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/RenderTool.java
Thu Jun  7 22:20:29 2007
@@ -82,7 +82,7 @@
  * @version $Revision$ $Date$
  */
 @DefaultKey("render")
-public class RenderTool
+public class RenderTool extends AbstractLockConfig
 {
     /**
      * The maximum number of loops allowed when recursing.
@@ -100,11 +100,9 @@
 
     /**
      * Looks for parse depth and catch.exceptions parameters.
-     * @since VelocityTools 1.3
      */
-    public void configure(Map params)
+    protected void configure(ValueParser parser)
     {
-        ValueParser parser = new ValueParser(params);
         int depth = parser.getInt(KEY_PARSE_DEPTH, DEFAULT_PARSE_DEPTH);
         setParseDepth(depth);
 

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/ResourceTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/ResourceTool.java?view=diff&rev=545419&r1=545418&r2=545419
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/ResourceTool.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/ResourceTool.java
Thu Jun  7 22:20:29 2007
@@ -22,7 +22,6 @@
 import java.text.MessageFormat;
 import java.util.List;
 import java.util.Locale;
-import java.util.Map;
 import java.util.ResourceBundle;
 import org.apache.velocity.tools.config.DefaultKey;
 
@@ -64,13 +63,11 @@
  * @since VelocityTools 1.3
  */
 @DefaultKey("text")
-public class ResourceTool
+public class ResourceTool extends LocaleConfig
 {
     public static final String BUNDLES_KEY = "bundles";
-    public static final String LOCALE_KEY = "locale";
 
     private String[] bundles = new String[] { "resources" };
-    private Locale locale = Locale.getDefault();
 
 
     protected final void setDefaultBundle(String bundle)
@@ -87,46 +84,43 @@
         return this.bundles[0];
     }
 
+    @Deprecated
     protected final void setDefaultLocale(Locale locale)
     {
         if (locale == null)
         {
             throw new NullPointerException("Default locale cannot be null");
         }
-        this.locale = locale;
+        super.setLocale(locale);
     }
 
+    @Deprecated
     protected final Locale getDefaultLocale()
     {
-        return this.locale;
+        return super.getLocale();
     }
 
 
-    public void configure(Map params)
+    protected void configure(ValueParser parser)
     {
-        ValueParser parser = new ValueParser(params);
         String[] bundles = parser.getStrings(BUNDLES_KEY);
         if (bundles != null)
         {
             this.bundles = bundles;
         }
 
-        Locale locale = parser.getLocale(LOCALE_KEY);
-        if (locale != null)
-        {
-            this.locale = locale;
-        }
+        super.configure(parser);
     }
 
 
     public Key get(String key)
     {
-        return new Key(key, this.bundles, this.locale, null);
+        return new Key(key, this.bundles, getLocale(), null);
     }
 
     public Key bundle(String bundle)
     {
-        return new Key(null, new String[] { bundle }, this.locale, null);
+        return new Key(null, new String[] { bundle }, getLocale(), null);
     }
 
     public Key locale(Locale locale)
@@ -136,7 +130,7 @@
 
     public Key insert(Object[] args)
     {
-        return new Key(null, this.bundles, this.locale, args);
+        return new Key(null, this.bundles, getLocale(), args);
     }
 
     public Key insert(List args)
@@ -168,7 +162,7 @@
         }
         if (locale == null)
         {
-            locale = this.locale;
+            locale = getLocale();
         }
 
         ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale);



Mime
View raw message