Details
-
New Feature
-
Status: Closed
-
Major
-
Resolution: Fixed
-
WW 1.4, WW 2.0
-
None
Description
Here is a patch that allows the URLTag to be used to specify the scheme (eg http, https). The scheme is only used if different from the current scheme. ie. http is not appended when you are already on page using http.
Both the URLTag and the UrlHelper need to be patched:
Index: URLTag.java
===================================================================
retrieving revision 1.10
diff -u -r1.10 URLTag.java
— URLTag.java 17 Nov 2003 03:45:58 -0000 1.10
+++ URLTag.java 21 Dec 2003 19:26:38 -0000
@@ -64,6 +64,7 @@
// Attributes ----------------------------------------------------
protected String valueAttr;
+ protected String scheme = "http";
//~ Methods ////////////////////////////////////////////////////////////////
@@ -75,10 +76,21 @@
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();
Index: UrlHelper.java
===================================================================
retrieving revision 1.6
diff -u -r1.6 UrlHelper.java
— UrlHelper.java 19 Nov 2003 06:26:45 -0000 1.6
+++ UrlHelper.java 21 Dec 2003 19:30:26 -0000
@@ -29,15 +29,41 @@
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))
+ }
+
if (action != null) {
// Check if context path needs to be added
// Add path to absolute links
if (action.startsWith("/"))
-
+ else if (changedScheme)
+
// Add page
link.append(action);
} else {