[seam-commits] Seam SVN: r9921 - trunk/src/main/org/jboss/seam/web.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Mon Jan 12 14:16:42 EST 2009
Author: norman.richards at jboss.com
Date: 2009-01-12 14:16:42 -0500 (Mon, 12 Jan 2009)
New Revision: 9921
Modified:
trunk/src/main/org/jboss/seam/web/RewritingResponse.java
Log:
JBSEAM-3875
Modified: trunk/src/main/org/jboss/seam/web/RewritingResponse.java
===================================================================
--- trunk/src/main/org/jboss/seam/web/RewritingResponse.java 2009-01-12 18:50:23 UTC (rev 9920)
+++ trunk/src/main/org/jboss/seam/web/RewritingResponse.java 2009-01-12 19:16:42 UTC (rev 9921)
@@ -4,6 +4,7 @@
import java.net.*;
+import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
@@ -19,45 +20,64 @@
private HttpServletRequest request;
private Collection<Pattern> patterns;
-
public RewritingResponse(HttpServletRequest request,
- HttpServletResponse response,
- Collection<Pattern> patterns)
+ HttpServletResponse response,
+ Collection<Pattern> patterns)
{
super(response);
this.request = request;
this.patterns = patterns;
}
-
+
@Override
+ public String encodeRedirectUrl(String url) {
+ return encodeRedirectURL(url);
+ }
+
+ @Override
public String encodeUrl(String url) {
return encodeURL(url);
}
+
@Override
- public String encodeRedirectUrl(String url) {
- return encodeRedirectURL(url);
+ public String encodeRedirectURL(String url) {
+ String result = rewriteURL(url);
+ log.debug("encodeRedirectURL " + url + " -> " + result);
+ return wrappedEncodeRedirectURL(result);
}
-
+ private String wrappedEncodeRedirectURL(String result) {
+ ServletResponse response = getResponse();
+ if (response instanceof HttpServletResponse) {
+ return ((HttpServletResponse)response).encodeRedirectURL(result);
+ }
+ return result;
+ }
+
@Override
public String encodeURL(String url) {
- String result = encode(url);
+ String result = super.encodeUrl(rewriteURL(url));
log.debug("encodeURL " + url + " -> " + result);
- return result;
+ return wrappedEncodeURL(result);
}
- @Override
- public String encodeRedirectURL(String url) {
- log.debug("encode redirectURL called with " + url);
- return encodeURL(url);
+ private String wrappedEncodeURL(String result) {
+ ServletResponse response = getResponse();
+ if (response instanceof HttpServletResponse) {
+ return ((HttpServletResponse)response).encodeRedirectURL(result);
+ }
+ return result;
}
+
+ public boolean isLocalURL(URL url) {
+ return url.getHost().equals(request.getServerName());
+ }
-
public String rewritePath(String path) {
String contextPath = request.getContextPath();
-
+
if (path.startsWith(contextPath)) {
path = path.substring(contextPath.length());
}
@@ -68,29 +88,25 @@
return request.getContextPath() + rewrite.rewrite();
}
}
-
+
return path;
}
- public boolean isLocalURL(URL url) {
- return url.getHost().equals(request.getServerName());
- }
+ public String rewriteURL(String originalUrl) {
+ if (originalUrl.startsWith("http://") || originalUrl.startsWith("https://")) {
+ try {
+ URL url = new URL(originalUrl);
- 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.
- }
- }
+ 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);
+ return rewritePath(originalUrl);
}
}
More information about the seam-commits
mailing list