You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by me...@apache.org on 2012/09/14 15:33:41 UTC

svn commit: r1384770 - /click/trunk/click/framework/src/org/apache/click/util/Format.java

Author: medgar
Date: Fri Sep 14 13:33:41 2012
New Revision: 1384770

URL: http://svn.apache.org/viewvc?rev=1384770&view=rev
Log:
Added encodeURL method

Modified:
    click/trunk/click/framework/src/org/apache/click/util/Format.java

Modified: click/trunk/click/framework/src/org/apache/click/util/Format.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/util/Format.java?rev=1384770&r1=1384769&r2=1384770&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/util/Format.java (original)
+++ click/trunk/click/framework/src/org/apache/click/util/Format.java Fri Sep 14 13:33:41 2012
@@ -28,8 +28,9 @@ import java.util.Date;
 import java.util.List;
 import java.util.Locale;
 
-import org.apache.click.Context;
+import javax.servlet.http.HttpServletResponse;
 
+import org.apache.click.Context;
 import org.apache.commons.lang.StringEscapeUtils;
 import org.apache.commons.lang.StringUtils;
 
@@ -534,6 +535,31 @@ public class Format implements Serializa
     }
 
     /**
+     * Encode the given URL using the servlet response to ensure session ID
+     * is available if required.
+     *
+     * @param value the URL value to encode
+     * @return the response encoded URL value
+     */
+    public String encodeURL(String value) {
+        if (value != null) {
+            Context context = Context.getThreadLocalContext();
+            HttpServletResponse response = context.getResponse();
+
+            // If starts with $context, the substitute context path
+            if (value.startsWith("$context")) {
+                value =
+                    context.getRequest().getContextPath()
+                    + value.substring("$context".length());
+            }
+
+            return response.encodeURL(value);
+        } else {
+            return getEmptyString();
+        }
+    }
+
+    /**
      * Escape the given object value as a string. The following
      * characters are escaped: <, >, ", ', &.
      * <p/>
@@ -807,4 +833,5 @@ public class Format implements Serializa
     public String url(Object object) {
         return ClickUtils.encodeUrl(object, Context.getThreadLocalContext());
     }
+
 }