org.jasig.springframework.web.portlet.filter
Class GenericPortletFilterBean

java.lang.Object
  extended by org.jasig.springframework.web.portlet.filter.GenericPortletFilterBean
All Implemented Interfaces:
javax.portlet.filter.ActionFilter, javax.portlet.filter.EventFilter, javax.portlet.filter.PortletFilter, javax.portlet.filter.RenderFilter, javax.portlet.filter.ResourceFilter, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.EnvironmentAware, org.springframework.web.portlet.context.PortletContextAware
Direct Known Subclasses:
DelegatingPortletFilterProxy

public abstract class GenericPortletFilterBean
extends Object
implements javax.portlet.filter.ActionFilter, javax.portlet.filter.EventFilter, javax.portlet.filter.RenderFilter, javax.portlet.filter.ResourceFilter, org.springframework.beans.factory.BeanNameAware, org.springframework.context.EnvironmentAware, org.springframework.web.portlet.context.PortletContextAware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean

Simple base implementation of ActionFilter, EventFilter, RenderFilter, and ResourceFilter which treats its config parameters (init-param entries within the filter tag in portlet.xml) as bean properties.

A handy superclass for any type of filter. Type conversion of config parameters is automatic, with the corresponding setter method getting invoked with the converted value. It is also possible for subclasses to specify required properties. Parameters without matching bean property setter will simply be ignored.

This filter leaves actual filtering to subclasses, which have to override the doFilter method(s) the correspond to the portlet filter interface(s) being used.

This generic filter base class has no dependency on the Spring ApplicationContext concept. Filters usually don't load their own context but rather access service beans from the Spring root application context, accessible via the filter's PortletContext (see PortletApplicationContextUtils2).

Version:
$Revision: 23744 $
Author:
Eric Dalquist

Field Summary
protected  org.apache.commons.logging.Log logger
          Logger available to subclasses
 
Constructor Summary
GenericPortletFilterBean()
           
 
Method Summary
protected  void addRequiredProperty(String property)
          Subclasses can invoke this method to specify that this property (which must match a JavaBean property they expose) is mandatory, and must be supplied as a config parameter.
 void afterPropertiesSet()
          Calls the initFilterBean() method that might contain custom initialization of a subclass.
 void destroy()
          Subclasses may override this to perform custom filter shutdown.
protected  void doCommonFilter(javax.portlet.PortletRequest request, javax.portlet.PortletResponse response, javax.portlet.filter.FilterChain chain)
          Can be implemented by subclasses to provide filter handling common to all request types.
 void doFilter(javax.portlet.ActionRequest request, javax.portlet.ActionResponse response, javax.portlet.filter.FilterChain chain)
          Calls doCommonFilter(PortletRequest, PortletResponse, FilterChain)
 void doFilter(javax.portlet.EventRequest request, javax.portlet.EventResponse response, javax.portlet.filter.FilterChain chain)
          Calls doCommonFilter(PortletRequest, PortletResponse, FilterChain)
 void doFilter(javax.portlet.RenderRequest request, javax.portlet.RenderResponse response, javax.portlet.filter.FilterChain chain)
          Calls doCommonFilter(PortletRequest, PortletResponse, FilterChain)
 void doFilter(javax.portlet.ResourceRequest request, javax.portlet.ResourceResponse response, javax.portlet.filter.FilterChain chain)
          Calls doCommonFilter(PortletRequest, PortletResponse, FilterChain)
 javax.portlet.filter.FilterConfig getFilterConfig()
          Make the FilterConfig of this filter available, if any.
protected  String getFilterName()
          Make the name of this filter available to subclasses.
protected  javax.portlet.PortletContext getPortletContext()
          Make the PortletContext of this filter available to subclasses.
 void init(javax.portlet.filter.FilterConfig filterConfig)
           
protected  void initBeanWrapper(org.springframework.beans.BeanWrapper bw)
          Initialize the BeanWrapper for this GenericPortletFilterBean, possibly with custom editors.
protected  void initFilterBean()
          Subclasses may override this to perform custom initialization.
 void setBeanName(String beanName)
          Stores the bean name as defined in the Spring bean factory.
 void setEnvironment(org.springframework.core.env.Environment environment)
          
 void setPortletContext(javax.portlet.PortletContext portletContext)
          Stores the PortletContext that the bean factory runs in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
Logger available to subclasses

Constructor Detail

GenericPortletFilterBean

public GenericPortletFilterBean()
Method Detail

setBeanName

public final void setBeanName(String beanName)
Stores the bean name as defined in the Spring bean factory.

Only relevant in case of initialization as bean, to have a name as fallback to the filter name usually provided by a FilterConfig instance.

Specified by:
setBeanName in interface org.springframework.beans.factory.BeanNameAware
See Also:
BeanNameAware, getFilterName()

setEnvironment

public void setEnvironment(org.springframework.core.env.Environment environment)

Any environment set here overrides the StandardPortletEnvironment provided by default.

This Environment object is used only for resolving placeholders in resource paths passed into init-parameters for this filter. If no init-params are used, this Environment can be essentially ignored.

Specified by:
setEnvironment in interface org.springframework.context.EnvironmentAware
See Also:
init(FilterConfig)

setPortletContext

public final void setPortletContext(javax.portlet.PortletContext portletContext)
Stores the PortletContext that the bean factory runs in.

Only relevant in case of initialization as bean, to have a PortletContext as fallback to the context usually provided by a FilterConfig instance.

Specified by:
setPortletContext in interface org.springframework.web.portlet.context.PortletContextAware
See Also:
PortletContextAware, getPortletContext()

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Calls the initFilterBean() method that might contain custom initialization of a subclass.

Only relevant in case of initialization as bean, where the standard init(FilterConfig) method won't be called.

Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
Exception
See Also:
initFilterBean(), init(FilterConfig)

addRequiredProperty

protected final void addRequiredProperty(String property)
Subclasses can invoke this method to specify that this property (which must match a JavaBean property they expose) is mandatory, and must be supplied as a config parameter. This should be called from the constructor of a subclass.

This method is only relevant in case of traditional initialization driven by a FilterConfig instance.

Parameters:
property - name of the required property

init

public void init(javax.portlet.filter.FilterConfig filterConfig)
          throws javax.portlet.PortletException
Specified by:
init in interface javax.portlet.filter.PortletFilter
Throws:
javax.portlet.PortletException

initBeanWrapper

protected void initBeanWrapper(org.springframework.beans.BeanWrapper bw)
                        throws org.springframework.beans.BeansException
Initialize the BeanWrapper for this GenericPortletFilterBean, possibly with custom editors.

This default implementation is empty.

Parameters:
bw - the BeanWrapper to initialize
Throws:
org.springframework.beans.BeansException - if thrown by BeanWrapper methods
See Also:
PropertyEditorRegistry.registerCustomEditor(java.lang.Class, java.beans.PropertyEditor)

getFilterConfig

public final javax.portlet.filter.FilterConfig getFilterConfig()
Make the FilterConfig of this filter available, if any. Analogous to GenericPortlet's getPortletConfig().

Public to resemble the getFilterConfig() method of the Portlet Filter version that shipped with WebLogic 6.1.

Returns:
the FilterConfig instance, or null if none available
See Also:
GenericPortlet.getPortletConfig()

getFilterName

protected final String getFilterName()
Make the name of this filter available to subclasses. Analogous to GenericPortlets's getPortletName().

Takes the FilterConfig's filter name by default. If initialized as bean in a Spring application context, it falls back to the bean name as defined in the bean factory.

Returns:
the filter name, or null if none available
See Also:
GenericPortlet.getPortletName(), FilterConfig.getFilterName(), setBeanName(java.lang.String)

getPortletContext

protected final javax.portlet.PortletContext getPortletContext()
Make the PortletContext of this filter available to subclasses. Analogous to GenericPortlet's getPortletContext().

Takes the FilterConfig's PortletContext by default. If initialized as bean in a Spring application context, it falls back to the PortletContext that the bean factory runs in.

Returns:
the PortletContext instance, or null if none available
See Also:
GenericPortlet.getPortletContext(), javax.portlet.FilterConfig#getPortletContext(), setPortletContext(javax.portlet.PortletContext)

initFilterBean

protected void initFilterBean()
                       throws javax.portlet.PortletException
Subclasses may override this to perform custom initialization. All bean properties of this filter will have been set before this method is invoked.

Note: This method will be called from standard filter initialization as well as filter bean initialization in a Spring application context. Filter name and PortletContext will be available in both cases.

This default implementation is empty.

Throws:
javax.portlet.PortletException - if subclass initialization fails
See Also:
getFilterName(), getPortletContext()

doFilter

public void doFilter(javax.portlet.ActionRequest request,
                     javax.portlet.ActionResponse response,
                     javax.portlet.filter.FilterChain chain)
              throws IOException,
                     javax.portlet.PortletException
Calls doCommonFilter(PortletRequest, PortletResponse, FilterChain)

Specified by:
doFilter in interface javax.portlet.filter.ActionFilter
Throws:
IOException
javax.portlet.PortletException

doFilter

public void doFilter(javax.portlet.EventRequest request,
                     javax.portlet.EventResponse response,
                     javax.portlet.filter.FilterChain chain)
              throws IOException,
                     javax.portlet.PortletException
Calls doCommonFilter(PortletRequest, PortletResponse, FilterChain)

Specified by:
doFilter in interface javax.portlet.filter.EventFilter
Throws:
IOException
javax.portlet.PortletException

doFilter

public void doFilter(javax.portlet.ResourceRequest request,
                     javax.portlet.ResourceResponse response,
                     javax.portlet.filter.FilterChain chain)
              throws IOException,
                     javax.portlet.PortletException
Calls doCommonFilter(PortletRequest, PortletResponse, FilterChain)

Specified by:
doFilter in interface javax.portlet.filter.ResourceFilter
Throws:
IOException
javax.portlet.PortletException

doFilter

public void doFilter(javax.portlet.RenderRequest request,
                     javax.portlet.RenderResponse response,
                     javax.portlet.filter.FilterChain chain)
              throws IOException,
                     javax.portlet.PortletException
Calls doCommonFilter(PortletRequest, PortletResponse, FilterChain)

Specified by:
doFilter in interface javax.portlet.filter.RenderFilter
Throws:
IOException
javax.portlet.PortletException

doCommonFilter

protected void doCommonFilter(javax.portlet.PortletRequest request,
                              javax.portlet.PortletResponse response,
                              javax.portlet.filter.FilterChain chain)
                       throws IOException,
                              javax.portlet.PortletException
Can be implemented by subclasses to provide filter handling common to all request types. Default implementation just uses PortletFilterUtils.doFilter(PortletRequest, PortletResponse, FilterChain)

Throws:
IOException
javax.portlet.PortletException

destroy

public void destroy()
Subclasses may override this to perform custom filter shutdown.

Note: This method will be called from standard filter destruction as well as filter bean destruction in a Spring application context.

This default implementation is empty.

Specified by:
destroy in interface javax.portlet.filter.PortletFilter
Specified by:
destroy in interface org.springframework.beans.factory.DisposableBean


Copyright © 2013 Jasig. All Rights Reserved.