Class PortletContentGenerator
- java.lang.Object
- org.springframework.context.support.ApplicationObjectSupport
- org.springframework.web.portlet.context.PortletApplicationObjectSupport
- org.springframework.web.portlet.handler.PortletContentGenerator
- All Implemented Interfaces:
Aware
,ApplicationContextAware
,PortletContextAware
- Direct Known Subclasses:
AbstractController
,AnnotationMethodHandlerAdapter
public abstract class PortletContentGenerator extends PortletApplicationObjectSupport
Convenient superclass for any kind of web content generator, likeAbstractController
. Can also be used for custom handlers that have their ownHandlerAdapter
.Supports portlet cache control options.
- Since:
- 2.0
- Author:
- Juergen Hoeller, John A. Lewis
- See Also:
setCacheSeconds(int)
,setRequireSession(boolean)
Field Summary
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
logger
Constructor Summary
Constructors Constructor Description PortletContentGenerator()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
applyCacheSeconds(MimeResponse response, int seconds)
Apply the given cache seconds to the render responseprotected void
cacheForSeconds(MimeResponse response, int seconds)
Set portlet response to allow caching for the given number of seconds.protected void
check(PortletRequest request, PortletResponse response)
Check and prepare the given request and response according to the settings of this generator.protected void
checkAndPrepare(PortletRequest request, MimeResponse response)
Check and prepare the given request and response according to the settings of this generator.protected void
checkAndPrepare(PortletRequest request, MimeResponse response, int cacheSeconds)
Check and prepare the given request and response according to the settings of this generator.int
getCacheSeconds()
Return the number of seconds that content is cached.boolean
isRequireSession()
Return whether a session is required to handle requests.protected void
preventCaching(MimeResponse response)
Prevent the render response from being cached.void
setCacheSeconds(int seconds)
Cache content for the given number of seconds.void
setRequireSession(boolean requireSession)
Set whether a session should be required to handle requests.Methods inherited from class org.springframework.web.portlet.context.PortletApplicationObjectSupport
getPortletContext, getTempDir, isContextRequired, setPortletContext
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, initApplicationContext, requiredContextClass, setApplicationContext
Constructor Detail
PortletContentGenerator
public PortletContentGenerator()
Method Detail
setRequireSession
public final void setRequireSession(boolean requireSession)
Set whether a session should be required to handle requests.
isRequireSession
public final boolean isRequireSession()
Return whether a session is required to handle requests.
setCacheSeconds
public final void setCacheSeconds(int seconds)
Cache content for the given number of seconds. Default is -1, indicating no override of portlet content caching.Only if this is set to 0 (no cache) or a positive value (cache for this many seconds) will this class override the portlet settings.
The cache setting can be overwritten by subclasses, before content is generated.
getCacheSeconds
public final int getCacheSeconds()
Return the number of seconds that content is cached.
check
protected final void check(PortletRequest request, PortletResponse response) throws PortletException
Check and prepare the given request and response according to the settings of this generator. Checks for a required session, and applies the number of cache seconds configured for this generator (if it is a render request/response).- Parameters:
request
- current portlet requestresponse
- current portlet response- Throws:
PortletException
- if the request cannot be handled because a check failed
checkAndPrepare
protected final void checkAndPrepare(PortletRequest request, MimeResponse response) throws PortletException
Check and prepare the given request and response according to the settings of this generator. Checks for a required session, and applies the number of cache seconds configured for this generator (if it is a render request/response).- Parameters:
request
- current portlet requestresponse
- current portlet response- Throws:
PortletException
- if the request cannot be handled because a check failed
checkAndPrepare
protected final void checkAndPrepare(PortletRequest request, MimeResponse response, int cacheSeconds) throws PortletException
Check and prepare the given request and response according to the settings of this generator. Checks for a required session, and applies the given number of cache seconds (if it is a render request/response).- Parameters:
request
- current portlet requestresponse
- current portlet responsecacheSeconds
- positive number of seconds into the future that the response should be cacheable for, 0 to prevent caching- Throws:
PortletException
- if the request cannot be handled because a check failed
preventCaching
protected final void preventCaching(MimeResponse response)
Prevent the render response from being cached.
cacheForSeconds
protected final void cacheForSeconds(MimeResponse response, int seconds)
Set portlet response to allow caching for the given number of seconds.- Parameters:
response
- current portlet render responseseconds
- number of seconds into the future that the response should be cacheable for
applyCacheSeconds
protected final void applyCacheSeconds(MimeResponse response, int seconds)
Apply the given cache seconds to the render response- Parameters:
response
- current portlet render responseseconds
- positive number of seconds into the future that the response should be cacheable for, 0 to prevent caching