net.sf.j2ep
Class UrlRewritingResponseWrapper

java.lang.Object
  extended by HttpServletResponseWrapper
      extended by net.sf.j2ep.UrlRewritingResponseWrapper

public final class UrlRewritingResponseWrapper
extends HttpServletResponseWrapper

A wrapper for the normal HttpServletResponse, based on the content-type either the normal output stream of a wrapped stream will be returned. The wrapped stream can handle rewrite of links found in the source. This class also handles rewriting of the headers Location and Set-Cookie.

Author:
Anders Nyman

Constructor Summary
UrlRewritingResponseWrapper(HttpServletResponse response, Server server, java.lang.String ownHostName, java.lang.String contextPath, ServerChain serverChain)
          Basic constructor.
 
Method Summary
 void addHeader(java.lang.String name, java.lang.String originalValue)
          Checks if we have to rewrite the header and if so will rewrite it.
 ServletOutputStream getOutputStream()
          Based on the value in the content-type header we either return the default stream or our own stream that can rewrite links.
 java.io.PrintWriter getWriter()
          Based on the value in the content-type header we either return the default writer or our own writer.
 void processStream()
          Rewrites the output stream to change any links.
 void setHeader(java.lang.String name, java.lang.String originalValue)
          Checks if we have to rewrite the header and if so will rewrite it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UrlRewritingResponseWrapper

public UrlRewritingResponseWrapper(HttpServletResponse response,
                                   Server server,
                                   java.lang.String ownHostName,
                                   java.lang.String contextPath,
                                   ServerChain serverChain)
                            throws java.io.IOException
Basic constructor.

Parameters:
response - The response we are wrapping
server - The server that was matched
ownHostName - String we are rewriting servers to
Throws:
java.io.IOException - When there is a problem with the streams
Method Detail

addHeader

public void addHeader(java.lang.String name,
                      java.lang.String originalValue)
Checks if we have to rewrite the header and if so will rewrite it.

See Also:
javax.servlet.http.HttpServletResponse#addHeader(java.lang.String, java.lang.String)

setHeader

public void setHeader(java.lang.String name,
                      java.lang.String originalValue)
Checks if we have to rewrite the header and if so will rewrite it.

See Also:
javax.servlet.http.HttpServletResponse#setHeader(java.lang.String, java.lang.String)

getOutputStream

public ServletOutputStream getOutputStream()
                                    throws java.io.IOException
Based on the value in the content-type header we either return the default stream or our own stream that can rewrite links.

Throws:
java.io.IOException
See Also:
javax.servlet.ServletResponse#getOutputStream()

getWriter

public java.io.PrintWriter getWriter()
                              throws java.io.IOException
Based on the value in the content-type header we either return the default writer or our own writer. Our own writer will write to the stream that can rewrite links.

Throws:
java.io.IOException
See Also:
javax.servlet.ServletResponse#getWriter()

processStream

public void processStream()
                   throws java.io.IOException
Rewrites the output stream to change any links. Also closes all the streams and writers. We need the user to flush and close the streams himself as usual but we can't be sure that the writers created are used by the client and therefor we close them here.

Throws:
java.io.IOException - Is thrown when there is a problem with the streams