Author: chris.laprun(a)jboss.com
Date: 2010-03-08 17:30:43 -0500 (Mon, 08 Mar 2010)
New Revision: 2041
Modified:
components/common/trunk/common/src/main/java/org/gatein/common/
components/common/trunk/common/src/main/java/org/gatein/common/net/URLTools.java
Log:
- Added getServerAddressFrom method.
Property changes on: components/common/trunk/common/src/main/java/org/gatein/common
___________________________________________________________________
Name: svn:ignore
+ *.iml
.idea
Modified:
components/common/trunk/common/src/main/java/org/gatein/common/net/URLTools.java
===================================================================
---
components/common/trunk/common/src/main/java/org/gatein/common/net/URLTools.java 2010-03-08
18:10:56 UTC (rev 2040)
+++
components/common/trunk/common/src/main/java/org/gatein/common/net/URLTools.java 2010-03-08
22:30:43 UTC (rev 2041)
@@ -29,6 +29,7 @@
import org.gatein.common.text.FastURLEncoder;
import org.gatein.common.util.ParameterValidation;
+import javax.servlet.http.HttpServletRequest;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -59,6 +60,10 @@
public static final String FTP_PREFIX = "ftp://";
public static final String FILE_PREFIX = "/";
+ public static final String SCH_END = "://";
+ public static final String PORT_END = ":";
+ public static final String SLASH = "/";
+
private static final Logger log = LoggerFactory.getLogger(URLTools.class);
public static boolean isURLAbsolute(String url)
@@ -67,6 +72,21 @@
}
/**
+ * Returns the server address that originated the request, without final /.
+ *
+ * @param request
+ * @return
+ */
+ public static String getServerAddressFrom(HttpServletRequest request)
+ {
+ String scheme = request.getScheme();
+ String host = request.getServerName();
+ int port = request.getServerPort();
+
+ return scheme + SCH_END + host + PORT_END + port;
+ }
+
+ /**
* Fetches content from of the URL as a byte array or <code>null</code> if
a problem occurred. The timeout values
* must not be negative integers, when it is equals to zero it means that it does not
setup a timeout and use the
* default values.
@@ -470,23 +490,23 @@
public static String safeEncodeForHTMLId(String value)
{
- value = value.replace("=", EQUALS);
- value = value.replace("/", SLASH);
- value = value.replace(".", DOT);
- return value.replace("+", PLUS);
+ value = value.replace("=", EQUALS_REPLACEMENT);
+ value = value.replace("/", SLASH_REPLACEMENT);
+ value = value.replace(".", DOT_REPLACEMENT);
+ return value.replace("+", PLUS_REPLACEMENT);
}
public static String safeDecodeForHTMLId(String value)
{
- value = value.replace(EQUALS, "=");
- value = value.replace(SLASH, "/");
- value = value.replace(DOT, ".");
- return value.replace(PLUS, "+");
+ value = value.replace(EQUALS_REPLACEMENT, "=");
+ value = value.replace(SLASH_REPLACEMENT, "/");
+ value = value.replace(DOT_REPLACEMENT, ".");
+ return value.replace(PLUS_REPLACEMENT, "+");
}
- private static final String EQUALS = "_e";
- private static final String SLASH = "_s";
- private static final String DOT = "_d";
- private static final String PLUS = "_p";
+ private static final String EQUALS_REPLACEMENT = "_e";
+ private static final String SLASH_REPLACEMENT = "_s";
+ private static final String DOT_REPLACEMENT = "_d";
+ private static final String PLUS_REPLACEMENT = "_p";
}
Show replies by date