com.opencms.core
Class CmsResponseHttpServlet

java.lang.Object
  |
  +--com.opencms.core.CmsResponseHttpServlet
All Implemented Interfaces:
I_CmsResponse

public class CmsResponseHttpServlet
extends Object
implements I_CmsResponse

Implementation of the I_CmsResponse interface which wraps a HttpServletResponse and provides OpenCms with a facility to handle redirects.

Version:
$Revision: 1.29 $ $Date: 2003/03/19 08:43:10 $
Author:
Michael Emmerich

Method Summary
 void addHeader(String key, String value)
          Add a header-field in the response.
static boolean checkJsdk()
          Check the JSDK version available at runtime.
 boolean containsHeader(String key)
          Checks, if the header was set already.
 String getContentType()
          Returns the content type of the response which has previously been set using setContentType(java.lang.String).
 Object getOriginalResponse()
          Returns the original response that was used to create the CmsResponse.
 int getOriginalResponseType()
          Returns the type of the response that was used to create the CmsResponse, which will be a C_RESPONSE_HTTP value for this wrapper implementation.
 OutputStream getOutputStream()
          Returns an OutputStream for writing the response data.
 boolean isOutputWritten()
          Check if the output stream was written previously.
 boolean isRedirected()
          Check if the current request was redirected.
 void sendCmsRedirect(String location)
          Sets a redirect to send the responst to.
 void sendError(int code)
          Sets the error code that is returnd by the response.
 void sendError(int code, String msg)
          Sets the error code and a additional message that is returnd by the response.
 void sendRedirect(String location)
          Helper function for a redirect to the cluster url.
 void setContentLength(int len)
          Sets the length of the content being returned by the server.
 void setContentType(String type)
          Sets the content type of the response to the specified type.
 void setHeader(String key, String value)
          Sets a header-field in the response.
 void setLastModified(long time)
          Sets the last modified header-field in the response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

checkJsdk

public static boolean checkJsdk()
Check the JSDK version available at runtime.

Returns:
true if JSDK 2, false if JSDK 1

getOriginalResponse

public Object getOriginalResponse()
Returns the original response that was used to create the CmsResponse.

Specified by:
getOriginalResponse in interface I_CmsResponse
Returns:
The original response of the CmsResponse.

getOriginalResponseType

public int getOriginalResponseType()
Returns the type of the response that was used to create the CmsResponse, which will be a C_RESPONSE_HTTP value for this wrapper implementation.

Specified by:
getOriginalResponseType in interface I_CmsResponse
Returns:
The type of the CmsResponse which is C_RESPONSE_HTTP

getOutputStream

public OutputStream getOutputStream()
                             throws IOException
Returns an OutputStream for writing the response data.

Specified by:
getOutputStream in interface I_CmsResponse
Returns:
OutputStream for writing data.
Throws:
IOException - if an error occurs

isOutputWritten

public boolean isOutputWritten()
Check if the output stream was written previously.

Specified by:
isOutputWritten in interface I_CmsResponse
Returns:
true if getOutputStream() was called, false otherwise.

isRedirected

public boolean isRedirected()
Check if the current request was redirected. In this case, the servlet must not write any bytes to the output stream.

Specified by:
isRedirected in interface I_CmsResponse
Returns:
true if the request is redirected, false otherwise.

sendCmsRedirect

public void sendCmsRedirect(String location)
                     throws IOException
Sets a redirect to send the responst to. The original HttpServletResponse redirect is used here. Additional information about the servlets location is taken from the original HttpServletRequest.

Specified by:
sendCmsRedirect in interface I_CmsResponse
Parameters:
location - The location the response is send to.
Throws:
IOException - if an error occurs

sendError

public void sendError(int code)
               throws IOException
Sets the error code that is returnd by the response. The error code is specified by a numeric value.

Specified by:
sendError in interface I_CmsResponse
Parameters:
code - The error code to be set.
Throws:
IOException - if an error occurs

sendError

public void sendError(int code,
                      String msg)
               throws IOException
Sets the error code and a additional message that is returnd by the response. The error code is specified by a numeric value.

Specified by:
sendError in interface I_CmsResponse
Parameters:
code - The error code to be set.
msg - Additional error message.
Throws:
IOException - if an error occurs

sendRedirect

public void sendRedirect(String location)
                  throws IOException
Helper function for a redirect to the cluster url. If location has the same hostname as the host of this servlet use the cluster url.

Specified by:
sendRedirect in interface I_CmsResponse
Parameters:
location - a full url, eg. http://servername/servlets/opencms/index.html
Throws:
IOException - if an error occurs

setContentLength

public void setContentLength(int len)
Sets the length of the content being returned by the server.

Specified by:
setContentLength in interface I_CmsResponse
Parameters:
len - Number of bytes to be returned by the response.

setContentType

public void setContentType(String type)
Sets the content type of the response to the specified type.

Specified by:
setContentType in interface I_CmsResponse
Parameters:
type - The contnent type of the response.

getContentType

public String getContentType()
Returns the content type of the response which has previously been set using setContentType(java.lang.String).

Specified by:
getContentType in interface I_CmsResponse
Returns:
the content type of the response.

setHeader

public void setHeader(String key,
                      String value)
Sets a header-field in the response.

Specified by:
setHeader in interface I_CmsResponse
Parameters:
key - The key for the header.
value - The value for the header.

addHeader

public void addHeader(String key,
                      String value)
Add a header-field in the response.

Specified by:
addHeader in interface I_CmsResponse
Parameters:
key - The key for the header.
value - The value for the header.

setLastModified

public void setLastModified(long time)
Sets the last modified header-field in the response.

Specified by:
setLastModified in interface I_CmsResponse
Parameters:
time - The last-modified time.

containsHeader

public boolean containsHeader(String key)
Checks, if the header was set already.

Specified by:
containsHeader in interface I_CmsResponse
Returns:
true, if the header was set before else false.