On Sat, Aug 26, 2006 at 12:18:50PM +0200, Oswald Buddenhagen wrote:
> this patch adds support for javascript: urls in display:table's
> requestURI attribute.
>
here is an updated patch that produces correct ampersands that work also
with mozilla. this fix is clearly related to
http://jira.codehaus.org/browse/DISPL-316

Index: main/java/org/displaytag/util/DefaultHref.java
===================================================================
--- main/java/org/displaytag/util/DefaultHref.java	(revision 1096)
+++ main/java/org/displaytag/util/DefaultHref.java	(working copy)
@@ -11,6 +11,8 @@
  */
 package org.displaytag.util;
 
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -67,8 +69,15 @@
      */
     public void setFullUrl(String baseUrl)
     {
+        this.anchor = null;
+
+        if (baseUrl.startsWith("javascript:"))
+        {
+            this.url = baseUrl;
+            return;
+        }
+
         this.url = null;
-        this.anchor = null;
         String noAnchorUrl;
         int anchorposition = baseUrl.indexOf('#');
 
@@ -296,11 +305,19 @@
     {
         StringBuffer buffer = new StringBuffer(30);
 
-        buffer.append(this.url);
+        boolean jsUrl = url.startsWith("javascript:");
 
+        if (!jsUrl)
+        {
+            buffer.append(this.url);
+        }
+
         if (this.parameters.size() > 0)
         {
-            buffer.append('?');
+            if (!jsUrl)
+            {
+                buffer.append('?');
+            }
             Set parameterSet = this.parameters.entrySet();
 
             Iterator iterator = parameterSet.iterator();
@@ -323,7 +340,14 @@
                     {
                         if (i > 0)
                         {
-                            buffer.append(TagConstants.AMPERSAND);
+                            if (jsUrl)
+                            {
+                                buffer.append('&');
+                            }
+                            else
+                            {
+                                buffer.append(TagConstants.AMPERSAND);
+                            }
                         }
 
                         buffer.append(key).append('=').append(values[i]);
@@ -336,11 +360,36 @@
 
                 if (iterator.hasNext())
                 {
-                    buffer.append(TagConstants.AMPERSAND);
+                    if (jsUrl)
+                    {
+                        buffer.append('&');
+                    }
+                    else
+                    {
+                        buffer.append(TagConstants.AMPERSAND);
+                    }
                 }
             }
         }
 
+        if (jsUrl)
+        {
+            int xoff = this.url.indexOf("{}", 11); // skip "javascript:"
+            if (xoff < 0)
+            {
+                return "javascript:alert('displayTag: fix requestURI!')";
+            }
+            try
+            {
+                // assuming the rest of the URL to be already encoded - otherwise we wouldn't have been able to put it in requestURI
+                return this.url.substring(0, xoff) + '\'' + URLEncoder.encode(buffer.toString(), "UTF-8") + '\'' + this.url.substring(xoff + 2);
+            }
+            catch (UnsupportedEncodingException e)
+            {
+                throw new RuntimeException(e);
+            }
+        }
+
         if (this.anchor != null)
         {
             buffer.append('#');
Index: main/java/org/displaytag/tags/TableTag.java
===================================================================
--- main/java/org/displaytag/tags/TableTag.java	(revision 1088)
+++ main/java/org/displaytag/tags/TableTag.java	(working copy)
@@ -1098,24 +1128,27 @@
         {
             // if user has added a requestURI create a new href
             String fullURI = requestUri;
-            if (!this.dontAppendContext)
+            if (!fullURI.startsWith("javascript:"))
             {
-                String contextPath = ((HttpServletRequest) this.pageContext.getRequest()).getContextPath();
+                if (!this.dontAppendContext)
+                {
+                    String contextPath = ((HttpServletRequest) this.pageContext.getRequest()).getContextPath();
 
-                // prepend the context path if any.
-                // actually checks if context path is already there for people which manually add it
-                if (!StringUtils.isEmpty(contextPath)
-                    && requestUri != null
-                    && requestUri.startsWith("/")
-                    && !requestUri.startsWith(contextPath))
-                {
-                    fullURI = contextPath + this.requestUri;
+                    // prepend the context path if any.
+                    // actually checks if context path is already there for people which manually add it
+                    if (!StringUtils.isEmpty(contextPath)
+                        && requestUri != null
+                        && requestUri.startsWith("/")
+                        && !requestUri.startsWith(contextPath))
+                    {
+                        fullURI = contextPath + this.requestUri;
+                    }
                 }
+
+                // call encodeURL to preserve session id when cookies are disabled
+                fullURI = ((HttpServletResponse) this.pageContext.getResponse()).encodeURL(fullURI);
             }
 
-            // call encodeURL to preserve session id when cookies are disabled
-            fullURI = ((HttpServletResponse) this.pageContext.getResponse()).encodeURL(fullURI);
-
             baseHref.setFullUrl(fullURI);
 
             // // ... and copy parameters from the current request
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
displaytag-devel mailing list
displaytag-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/displaytag-devel

Reply via email to