org.opencms.jsp
Class CmsJspBean

java.lang.Object
  extended by org.opencms.jsp.CmsJspBean
Direct Known Subclasses:
CmsJspActionElement

public class CmsJspBean
extends java.lang.Object

Superclass for OpenCms JSP beans that provides convient access to OpenCms core and VFS functionality.

If you have large chunks of code on your JSP that you want to move to a Class file, consider creating a subclass of this bean. Initialize this bean at the beginning of your JSP like this:

 <jsp:useBean id="cmsbean" class="org.opencms.jsp.CmsJspBean">
 <% cmsbean.init(pageContext, request, response); %>
 </jsp:useBean>
 

Since:
6.0.0
Version:
$Revision: 1.22 $
Author:
Alexander Kandzior

Constructor Summary
CmsJspBean()
          Empty constructor, required for every JavaBean.
 
Method Summary
 CmsObject getCmsObject()
          Returns the CmsObject from the wrapped request.
protected  CmsFlexController getController()
          Returns the Flex controller derived from the request this bean was initialized with.
 javax.servlet.jsp.PageContext getJspContext()
          Returns the JSP page context this bean was initialized with.
protected  java.lang.String getMessage(CmsMessageContainer container)
          Internally localizes the given CmsMessageContainer to a String.
 javax.servlet.http.HttpServletRequest getRequest()
          Returns the request this bean was initialized with.
 CmsRequestContext getRequestContext()
          Returns the current users OpenCms request context.
 javax.servlet.http.HttpServletResponse getResponse()
          Returns the response wrapped by this element.
protected  void handleException(java.lang.Throwable t)
          Handles any exception that might occur in the context of this element to ensure that templates are not disturbed.
 void init(javax.servlet.jsp.PageContext context, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Initialize this bean with the current page context, request and response.
protected  boolean isNotInitialized()
          Returns true if this bean has not been initialized (i.e. init() has not been called so far), false otherwise.
 boolean isSupressingExceptions()
          Returns true if Exceptions are handled by the class instance and suppressed on the output page, or false if they will be thrown and have to be handled by the calling class.
 void setContentType(java.lang.String type)
          Sets the content type for the HTTP response.
 void setStatus(int status)
          Sets the status code for the HTTP response.
 void setSupressingExceptions(boolean value)
          Controls if Exceptions that occur in methods of this class are suppressed (true) or not (false).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CmsJspBean

public CmsJspBean()
Empty constructor, required for every JavaBean.

Method Detail

getCmsObject

public CmsObject getCmsObject()
Returns the CmsObject from the wrapped request.

This is a convenience method in case you need access to the CmsObject in your JSP scriplets.

Returns:
the CmsObject from the wrapped request

getJspContext

public javax.servlet.jsp.PageContext getJspContext()
Returns the JSP page context this bean was initialized with.

Returns:
the JSP page context this bean was initialized with

getRequest

public javax.servlet.http.HttpServletRequest getRequest()
Returns the request this bean was initialized with.

Returns:
the request this bean was initialized with

getRequestContext

public CmsRequestContext getRequestContext()
Returns the current users OpenCms request context.

Returns:
the current users OpenCms request context

getResponse

public javax.servlet.http.HttpServletResponse getResponse()
Returns the response wrapped by this element.

Returns:
the response wrapped by this element

init

public void init(javax.servlet.jsp.PageContext context,
                 javax.servlet.http.HttpServletRequest req,
                 javax.servlet.http.HttpServletResponse res)
Initialize this bean with the current page context, request and response.

It is required to call one of the init() methods before you can use the instance of this bean.

Parameters:
context - the JSP page context object
req - the JSP request
res - the JSP response

isSupressingExceptions

public boolean isSupressingExceptions()
Returns true if Exceptions are handled by the class instance and suppressed on the output page, or false if they will be thrown and have to be handled by the calling class.

The default is true. If set to false Exceptions that occur internally will be wrapped into a RuntimeException and thrown to the calling class instance.

Returns:
true if Exceptions are suppressed, or false if they will be thrown and have to be handled by the calling class

setContentType

public void setContentType(java.lang.String type)
Sets the content type for the HTTP response.

This method is required since JSP's are handled in a special way for included template elements, so ServletResponse.setContentType(java.lang.String) won't work.

Please note that the content type set this way is never cached in the Flex cache, so you must make sure to not cache the element when you use this method.

Parameters:
type - the type to set
See Also:
ServletResponse.setContentType(java.lang.String)

setStatus

public void setStatus(int status)
Sets the status code for the HTTP response.

This method is required since JSP's are handled in a special way for included template elements, so HttpServletResponseWrapper.setStatus(int) won't work.

Please note that the status code set this way is never cached in the Flex cache, so you must make sure to not cache the element when you use this method.

Parameters:
status - the status code to set
See Also:
HttpServletResponseWrapper.setStatus(int)

setSupressingExceptions

public void setSupressingExceptions(boolean value)
Controls if Exceptions that occur in methods of this class are suppressed (true) or not (false).

The default is true. If set to false all Exceptions that occur internally will be wrapped into a RuntimeException and thrown to the calling class instance.

Parameters:
value - the value to set the Exception handing to

getController

protected CmsFlexController getController()
Returns the Flex controller derived from the request this bean was initialized with.

This is protected since the CmsFlexController this is really an internal OpenCms helper function, not part of the public OpenCms API. It must not be used on JSP pages, only from subclasses of this bean.

Returns:
the Flex controller derived from the request this bean was initialized with

getMessage

protected java.lang.String getMessage(CmsMessageContainer container)
Internally localizes the given CmsMessageContainer to a String.

If the user request context is at hand, the user's locale will be chosen. If no user request context is available, the default locale is used.

Parameters:
container - the message container that allows localization of the represented message.
Returns:
the message String of the container argument localized to the user's locale (if available) or to the default locale.

handleException

protected void handleException(java.lang.Throwable t)
Handles any exception that might occur in the context of this element to ensure that templates are not disturbed.

Parameters:
t - the Throwable that was caught

isNotInitialized

protected boolean isNotInitialized()
Returns true if this bean has not been initialized (i.e. init() has not been called so far), false otherwise.

Returns:
true if this bean has not been initialized