velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nbu...@apache.org
Subject svn commit: r707708 - /velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/LinkTool.java
Date Fri, 24 Oct 2008 18:41:57 GMT
Author: nbubna
Date: Fri Oct 24 11:41:56 2008
New Revision: 707708

URL: http://svn.apache.org/viewvc?rev=707708&view=rev
Log:
fix a String[] param bug and prepare to have other LinkTools extend this

Modified:
    velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/LinkTool.java

Modified: velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/LinkTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/LinkTool.java?rev=707708&r1=707707&r2=707708&view=diff
==============================================================================
--- velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/LinkTool.java (original)
+++ velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/LinkTool.java Fri
Oct 24 11:41:56 2008
@@ -116,9 +116,8 @@
     protected String queryDelim;
     protected boolean appendParams;
     protected boolean forceRelative;
-
-    private boolean opaque;
-    private final LinkTool self;
+    protected boolean opaque;
+    protected final LinkTool self;
 
 
     /**
@@ -141,6 +140,11 @@
         self = this;
     }
 
+    protected final void debug(String msg, Object... args)
+    {
+        debug(msg, null, args);
+    }
+
     protected final void debug(String msg, Throwable t, Object... args)
     {
         if (LOG != null && LOG.isDebugEnabled())
@@ -523,7 +527,7 @@
         if (this.query == null)
         {
             this.query = new LinkedHashMap();
-            query.put(key, value);
+            putParam(key, value);
         }
         else if (append)
         {
@@ -531,7 +535,7 @@
         }
         else
         {
-            query.put(key, value);
+            putParam(key, value);
         }
     }
 
@@ -549,15 +553,29 @@
                 List vals = new ArrayList();
                 vals.add(cur);
                 addToList(vals, value);
-                query.put(key, vals);
+                putParam(key, vals);
             }
         }
         else
         {
-            query.put(key, value);
+            putParam(key, value);
         }
     }
 
+    private void putParam(Object key, Object value)
+    {
+        if (value instanceof Object[])
+        {
+            List vals = new ArrayList();
+            for (Object v : ((Object[])value))
+            {
+                vals.add(v);
+            }
+            value = vals;
+        }
+        query.put(key, value);
+    }
+
     private void addToList(List vals, Object value)
     {
         if (value instanceof List)
@@ -1253,17 +1271,29 @@
         String pth;
         if (obj == null)
         {
-            pth = getDirectory();
+            pth = getContextPath();
         }
         else
         {
-            pth = combinePath(getDirectory(), String.valueOf(obj));
+            pth = combinePath(getContextPath(), String.valueOf(obj));
         }
         copy.setPath(pth);
         return copy;
     }
 
     /**
+     * At this level, this only returns the result of {@link #getDirectory}.
+     * It is here as an extension hook for subclasses to change the
+     * "context" for relative links.
+     * @see #relative(Object)
+     * @see #getDirectory
+     */
+    public String getContextPath()
+    {
+        return getDirectory();
+    }
+
+    /**
      * Returns true if this instance has a scheme value
      * and is not being forced to create relative URIs.
      */



Mime
View raw message