public class ServletContextAttributeHelper extends Object
ServletContext. WroFilter & WroServletContextListener configurations, by
setting the attributes with a unique key computed based on provided name (using
getName(). Use this class to retrieve wro4j related attributes, instead of
hard-coding the name of the attribute to retrieve.
Usage scenario:
WroFilter and a
WroServletContextListener configured in web.xml. In order to retrieve/store attributes in servlet context
use:
ServletContextAttributeHelperhelper = newServletContextAttributeHelper(servletContext);WroConfigurationconfig = helper.getWroConfiguration();WroManagerFactorymanagerFactory = helper.getManagerFactory();
WroFilter configurations in web.xml (each should have a dedicated listener
extended form WroServletContextListener). In order to retrieve/store attributes in servlet context use:
String name = ..//the name of the filter (defined in init-param called name).
ServletContextAttributeHelper helper = new ServletContextAttributeHelper(servletContext, name);
WroConfiguration config = helper.getWroConfiguration();
WroManagerFactory managerFactory = helper.getManagerFactory();
WroFilter configurations in web.xml, you can retrieve/store attributes from
within a filter using:
This example is similar to previous, except that the name of the filter will be extracted in the factory method.ServletContextAttributeHelperhelper =ServletContextAttributeHelper.create(filterConfig);WroConfigurationconfig = helper.getWroConfiguration();WroManagerFactorymanagerFactory = helper.getManagerFactory();
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_NAME
Default value of the name init param.
|
| Constructor and Description |
|---|
ServletContextAttributeHelper(javax.servlet.ServletContext servletContext)
Uses default name for storing/retrieving attributes in
ServletContext. |
ServletContextAttributeHelper(javax.servlet.ServletContext servletContext,
String name)
Uses default name to work with
ServletContext attribute. |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Remove all attributes from
ServletContext. |
static ServletContextAttributeHelper |
create(javax.servlet.FilterConfig filterConfig)
Factory method which uses default name for storing/retrieving attributes in
ServletContext. |
WroManagerFactory |
getManagerFactory() |
WroConfiguration |
getWroConfiguration() |
void |
setManagerFactory(WroManagerFactory managerFactory)
Set the configuration object as a servletContext attribute.
|
void |
setWroConfiguration(WroConfiguration config)
Set the configuration object as a servletContext attribute.
|
public static final String DEFAULT_NAME
public ServletContextAttributeHelper(javax.servlet.ServletContext servletContext)
ServletContext.public ServletContextAttributeHelper(javax.servlet.ServletContext servletContext,
String name)
ServletContext attribute.servletContext - a not null ServletContext object.name - of the listener for which the helper will be used.public static ServletContextAttributeHelper create(javax.servlet.FilterConfig filterConfig)
ServletContext.public WroManagerFactory getManagerFactory()
WroManagerFactory stored in servletContext.public WroConfiguration getWroConfiguration()
WroConfiguration stored in servletContext.public void setWroConfiguration(WroConfiguration config)
public void setManagerFactory(WroManagerFactory managerFactory)
public void clear()
ServletContext.Copyright © 2008-2014. All Rights Reserved.