Commits

Anonymous committed 579c97c

Applied scheme changing patch - fix for WW-438

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@304573baa09-0c28-0410-bef9-dab3c582ae83

  • Participants
  • Parent commits 951ee85

Comments (0)

Files changed (2)

File src/java/com/opensymphony/webwork/views/jsp/URLTag.java

 
     // Attributes ----------------------------------------------------
     protected String valueAttr;
+    protected String scheme = "http";
 
     //~ Methods ////////////////////////////////////////////////////////////////
 
         valueAttr = aName;
     }
 
+    public void setScheme(String aScheme) {
+        scheme = aScheme;
+    }
+
     public int doEndTag() throws JspException {
         HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
         HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
-        String result = UrlHelper.buildUrl(value, request, response, params);
+        String result = UrlHelper.buildUrl(value, request, response, params, scheme);
 
         String id = getId();
 

File src/java/com/opensymphony/webwork/views/util/UrlHelper.java

     private static final String AMP = "&";
 
     public static String buildUrl(String action, HttpServletRequest request, HttpServletResponse response, Map params) {
+        return buildUrl(action, request, response, params, null);
+    }
+
+    public static String buildUrl(String action, HttpServletRequest request, HttpServletResponse response, Map params, String scheme) {
         StringBuffer link = new StringBuffer();
 
+         boolean changedScheme = false;
+
+        // only append scheme if it is different to the current scheme
+        if (scheme != null && !scheme.equals(request.getScheme())) {
+            changedScheme = true;
+            link.append(scheme);
+            link.append("://");
+            link.append(request.getServerName());
+
+            // do not append port for default ports
+            int port = request.getServerPort();
+            if (!(scheme.equals("http") && port == 80) && !(scheme.equals("https") && port == 443)) {
+                link.append(":");
+                link.append(port);
+            }
+        }
+
         if (action != null) {
             // Check if context path needs to be added
             // Add path to absolute links
             if (action.startsWith("/")) {
                 link.append(request.getContextPath());
             }
+            else if (changedScheme) {
+                String uri = request.getRequestURI();
+                link.append(uri.substring(0, uri.lastIndexOf('/')));
+            }
 
             // Add page
             link.append(action);