[seam-commits] Seam SVN: r9909 - trunk/src/main/org/jboss/seam/web.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Fri Jan 9 14:39:49 EST 2009
Author: norman.richards at jboss.com
Date: 2009-01-09 14:39:49 -0500 (Fri, 09 Jan 2009)
New Revision: 9909
Modified:
trunk/src/main/org/jboss/seam/web/RewritingResponse.java
Log:
JBSEAM-3771
Modified: trunk/src/main/org/jboss/seam/web/RewritingResponse.java
===================================================================
--- trunk/src/main/org/jboss/seam/web/RewritingResponse.java 2009-01-09 19:05:30 UTC (rev 9908)
+++ trunk/src/main/org/jboss/seam/web/RewritingResponse.java 2009-01-09 19:39:49 UTC (rev 9909)
@@ -2,6 +2,8 @@
import java.util.Collection;
+import java.net.*;
+
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
@@ -52,23 +54,43 @@
return encodeURL(url);
}
-
- public String encode(String originalUrl) {
- String url = originalUrl;
+
+ public String rewritePath(String path) {
String contextPath = request.getContextPath();
- if (url.startsWith(contextPath)) {
- url = url.substring(contextPath.length());
+ if (path.startsWith(contextPath)) {
+ path = path.substring(contextPath.length());
}
for (Pattern pattern: patterns) {
- Rewrite rewrite = pattern.matchOutgoing(url);
+ Rewrite rewrite = pattern.matchOutgoing(path);
if (rewrite != null) {
return request.getContextPath() + rewrite.rewrite();
}
}
- return originalUrl;
+ return path;
}
+ public boolean isLocalURL(URL url) {
+ return url.getHost().equals(request.getServerName());
+ }
+
+ public String encode(String originalUrl) {
+ if (originalUrl.startsWith("http://") || originalUrl.startsWith("https://")) {
+ try {
+ URL url = new URL(originalUrl);
+
+ if (isLocalURL(url)) {
+ URL newUrl = new URL(url, rewritePath(url.getFile()));
+ return newUrl.toExternalForm();
+ }
+ } catch (MalformedURLException e) {
+ // ignore - we simply don't care. we could log this at info/debug level.
+ }
+ }
+
+ return rewritePath(originalUrl);
+ }
+
}
More information about the seam-commits
mailing list