|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.portlet.GenericPortlet org.springframework.web.portlet.GenericPortletBean org.springframework.web.portlet.FrameworkPortlet
public abstract class FrameworkPortlet
Base portlet for Spring's portlet framework. Provides integration with a Spring application context, in a JavaBean-based overall solution.
This class offers the following functionality:
ApplicationContext
instance per portlet. The portlet's configuration is determined by beans
in the portlet's namespace.
Subclasses must implement doActionService(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
and doRenderService(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
to handle action and render requests. Because this extends GenericPortletBean
rather than Portlet directly, bean properties are mapped onto it. Subclasses can
override initFrameworkPortlet()
for custom initialization.
Regards a "contextClass" parameter at the portlet init-param level,
falling back to the default context class
(XmlPortletApplicationContext
)
if not found. Note that, with the default FrameworkPortlet,
a context class needs to implement the
ConfigurablePortletApplicationContext
SPI.
Passes a "contextConfigLocation" portlet init-param to the context instance, parsing it into potentially multiple file paths which can be separated by any number of commas and spaces, like "test-portlet.xml, myPortlet.xml". If not explicitly specified, the context implementation is supposed to build a default location from the namespace of the portlet.
Note: In case of multiple config locations, later bean definitions will override ones defined in earlier loaded files, at least when using one of Spring's default ApplicationContext implementations. This can be leveraged to deliberately override certain bean definitions via an extra XML file.
The default namespace is "'portlet-name'-portlet", e.g. "test-portlet" for a portlet-name "test" (leading to a "/WEB-INF/test-portlet.xml" default location with XmlPortletApplicationContext). The namespace can also be set explicitly via the "namespace" portlet init-param.
doActionService(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
,
doRenderService(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
,
setContextClass(java.lang.Class)
,
setContextConfigLocation(java.lang.String)
,
setNamespace(java.lang.String)
Field Summary | |
---|---|
static Class |
DEFAULT_CONTEXT_CLASS
Default context class for FrameworkPortlet. |
static String |
DEFAULT_NAMESPACE_SUFFIX
Suffix for Portlet ApplicationContext namespaces. |
static String[] |
DEFAULT_USERINFO_ATTRIBUTE_NAMES
Default USER_INFO attribute names to search for the current username: "user.login.id", "user.name". |
static String |
PORTLET_CONTEXT_PREFIX
Prefix for the PortletContext attribute for the Portlet ApplicationContext. |
Fields inherited from class org.springframework.web.portlet.GenericPortletBean |
---|
logger |
Constructor Summary | |
---|---|
FrameworkPortlet()
|
Method Summary | |
---|---|
protected ApplicationContext |
createPortletApplicationContext(ApplicationContext parent)
Instantiate the PortletApplicationContext for this portlet, either a default XmlPortletApplicationContext or a custom context class if set. |
void |
destroy()
Close the PortletApplicationContext of this portlet. |
protected abstract void |
doActionService(ActionRequest request,
ActionResponse response)
Subclasses must implement this method to do the work of action request handling. |
protected void |
doDispatch(RenderRequest request,
RenderResponse response)
Delegate render requests to processRequest/doRenderService. |
protected abstract void |
doRenderService(RenderRequest request,
RenderResponse response)
Subclasses must implement this method to do the work of render request handling. |
Class |
getContextClass()
Return the custom context class. |
String |
getContextConfigLocation()
Return the explicit context config location, if any. |
String |
getNamespace()
Return the namespace for this portlet, falling back to default scheme if no custom namespace was set. |
ApplicationContext |
getPortletApplicationContext()
Return this portlet's ApplicationContext. |
String |
getPortletContextAttributeName()
Return the PortletContext attribute name for this portlets's PortletApplicationContext. |
String[] |
getUserinfoUsernameAttributes()
Returns the list of attributes that will be searched in the USER_INFO map when trying to find the username of the current user |
protected String |
getUsernameForRequest(PortletRequest request)
Determine the username for the given request. |
protected void |
initFrameworkPortlet()
This method will be invoked after any bean properties have been set and the PortletApplicationContext has been loaded. |
protected ApplicationContext |
initPortletApplicationContext()
Initialize and publish the PortletApplicationContext for this portlet. |
protected void |
initPortletBean()
Overridden method of GenericPortletBean, invoked after any bean properties have been set. |
boolean |
isPublishContext()
Return whether to publish this portlet's context as a PortletContext attribute. |
boolean |
isPublishEvents()
Return whether this portlet should publish a PortletRequestHandledEvent at the end of each request. |
void |
onApplicationEvent(ApplicationEvent event)
ApplicationListener endpoint that receives events from this servlet's WebApplicationContext. |
protected void |
onRefresh(ApplicationContext context)
Template method which can be overridden to add portlet-specific refresh work. |
void |
processAction(ActionRequest request,
ActionResponse response)
Delegate action requests to processRequest/doActionService. |
protected void |
processRequest(PortletRequest request,
PortletResponse response)
Process this request, publishing an event regardless of the outcome. |
void |
refresh()
Refresh this portlet's application context, as well as the dependent state of the portlet. |
void |
setContextClass(Class contextClass)
Set a custom context class. |
void |
setContextConfigLocation(String contextConfigLocation)
Set the context config location explicitly, instead of relying on the default location built from the namespace. |
void |
setNamespace(String namespace)
Set a custom namespace for this portlet, to be used for building a default context config location. |
void |
setPublishContext(boolean publishContext)
Set whether to publish this portlet's context as a PortletContext attribute, available to all objects in the web container. |
void |
setPublishEvents(boolean publishEvents)
Set whether this portlet should publish a PortletRequestHandledEvent at the end of each request. |
void |
setUserinfoUsernameAttributes(String[] userinfoUsernameAttributes)
Set the list of attributes to search in the USER_INFO map when trying to find the username of the current user. |
Methods inherited from class org.springframework.web.portlet.GenericPortletBean |
---|
addRequiredProperty, getPortletContext, getPortletName, init, initBeanWrapper |
Methods inherited from class javax.portlet.GenericPortlet |
---|
doEdit, doHelp, doView, getInitParameter, getInitParameterNames, getPortletConfig, getResourceBundle, getTitle, init, render |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Class DEFAULT_CONTEXT_CLASS
XmlPortletApplicationContext
public static final String DEFAULT_NAMESPACE_SUFFIX
public static final String PORTLET_CONTEXT_PREFIX
public static final String[] DEFAULT_USERINFO_ATTRIBUTE_NAMES
Constructor Detail |
---|
public FrameworkPortlet()
Method Detail |
---|
public void setContextClass(Class contextClass)
public Class getContextClass()
public void setNamespace(String namespace)
public String getNamespace()
public void setContextConfigLocation(String contextConfigLocation)
public String getContextConfigLocation()
public void setPublishContext(boolean publishContext)
This is especially handy during testing, although it is debatable whether it's good practice to let other application objects access the context this way.
public boolean isPublishContext()
public void setPublishEvents(boolean publishEvents)
PortletRequestHandledEvent
public boolean isPublishEvents()
public void setUserinfoUsernameAttributes(String[] userinfoUsernameAttributes)
public String[] getUserinfoUsernameAttributes()
protected final void initPortletBean() throws PortletException, BeansException
initPortletBean
in class GenericPortletBean
PortletException
- if subclass initialization fails
BeansException
protected ApplicationContext initPortletApplicationContext() throws BeansException
BeansException
- if the context couldn't be initializedcreatePortletApplicationContext(org.springframework.context.ApplicationContext)
protected ApplicationContext createPortletApplicationContext(ApplicationContext parent) throws BeansException
parent
- the parent ApplicationContext to use, or null if none
BeansException
- if the context couldn't be initializedsetContextClass(java.lang.Class)
,
XmlPortletApplicationContext
public String getPortletContextAttributeName()
public final ApplicationContext getPortletApplicationContext()
protected void initFrameworkPortlet() throws PortletException, BeansException
PortletException
- in case of an initialization exception
BeansException
- if thrown by ApplicationContext methodspublic void refresh() throws BeansException
BeansException
- in case of errorsgetPortletApplicationContext()
,
ConfigurableApplicationContext.refresh()
public void onApplicationEvent(ApplicationEvent event)
The default implementation calls onRefresh(org.springframework.context.ApplicationContext)
in case of a
ContextRefreshedEvent
,
triggering a refresh of this servlet's context-dependent state.
onApplicationEvent
in interface ApplicationListener
event
- the incoming ApplicationContext eventprotected void onRefresh(ApplicationContext context) throws BeansException
This implementation is empty.
context
- the current Portlet ApplicationContext
BeansException
- in case of errorsrefresh()
protected final void doDispatch(RenderRequest request, RenderResponse response) throws PortletException, IOException
doDispatch
in class GenericPortlet
PortletException
IOException
public final void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException
processAction
in interface Portlet
processAction
in class GenericPortlet
PortletException
IOException
protected final void processRequest(PortletRequest request, PortletResponse response) throws PortletException, IOException
doActionService()
and doRenderService()
template methods.
protected String getUsernameForRequest(PortletRequest request)
request
- current portlet request
PortletRequest.getUserPrincipal()
,
PortletRequest.getRemoteUser()
,
PortletRequest.USER_INFO
,
setUserinfoUsernameAttributes(String[])
protected abstract void doRenderService(RenderRequest request, RenderResponse response) throws Exception
The contract is essentially the same as that for the doDispatch
method of GenericPortlet.
This class intercepts calls to ensure that exception handling and event publication takes place.
request
- current render requestresponse
- current render response
Exception
- in case of any kind of processing failureGenericPortlet.doDispatch(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
protected abstract void doActionService(ActionRequest request, ActionResponse response) throws Exception
The contract is essentially the same as that for the processAction
method of GenericPortlet.
This class intercepts calls to ensure that exception handling and event publication takes place.
request
- current action requestresponse
- current action response
Exception
- in case of any kind of processing failureGenericPortlet.processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
public void destroy()
destroy
in interface Portlet
destroy
in class GenericPortlet
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |