public class ConfigurableSiteMeshFilter extends Object implements javax.servlet.Filter
The minimum required to make this useful is to add a decoratorMappings
init parameter.
<filter> <filter-name>sitemesh</filter-name> <filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class> <init-param> <param-name>decoratorMappings</param-name> <param-value> /*=/decorators/my-decorator.html /admin/*=/decorators/admin-decorator.html </param-value> </init-param> </filter> <filter-mapping> <filter-name>sitemesh</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
Alternatively the configuration can be specified in a separate XML file. This has the advantage that it can be changed at runtime without having to restart the web-application. Also, the same config file could potentially be reused to generate offline content.
<filter> <filter-name>sitemesh</filter-name> <filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class> </filter> <filter-mapping> <filter-name>sitemesh</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
<sitemesh> <mapping name="/*" decorator="/decorators/my-decorator.html"/> <mapping name="/admin/*" decorator="/decorators/admin-decorator.html"/> </sitemesh>
The default configuration path of /WEB-INF/sitemesh3.xml
can be changed by
adding a configFile
init-param to the filter.
decoratorMappings
: A list of mappings of path patterns to decorators.
Each entry should consist of pattern=decorator, separated by whitespace or commas. If multiple decorators
are required, they should be delimited with a pipe | char (and no whitespace)
e.g. /admin/*=/decorators/admin.html, *.secret=/decorators/secret.html|/decorators/common.html
mimeTypes
(optional): A list of mime-types, separated by whitespace
or commas, that should attempt to be decorated. Defaults to text/html
.
tagRuleBundles
(optional): The names of any
additional TagRuleBundle
s to install, separated by whitespace or commas.
These will be added to the default bundles (as set up in
BaseSiteMeshBuilder.setupDefaults()
):
CoreHtmlTagRuleBundle
and
DecoratorTagRuleBundle
.
Note: The contentProcessor
and tagRuleBundles
are mutually exclusive
- you should not set them both.
contentProcessor
(optional): The name of the
ContentProcessor
to use.
Note: The contentProcessor
and tagRuleBundles
are mutually exclusive
- you should not set them both.
exclude
(optional): A list of path patterns to exclude from
decoration, separated by whitespace or commas. e.g. /javadoc/*, somepage.html, *.jsp
Where a name is used, this means the fully qualified class name, which must have a default constructor.
PropertiesFilterConfigurator
Modifier and Type | Field and Description |
---|---|
static boolean |
AUTO_RELOAD_DEFAULT |
static String |
AUTO_RELOAD_PARAM |
static String |
CONFIG_FILE_DEFAULT |
static String |
CONFIG_FILE_PARAM |
Constructor and Description |
---|
ConfigurableSiteMeshFilter() |
Modifier and Type | Method and Description |
---|---|
protected void |
applyCustomConfiguration(SiteMeshFilterBuilder builder)
Override this to apply custom configuration after after the default configuration mechanisms.
|
protected void |
deployNewFilter(javax.servlet.Filter newFilter) |
void |
destroy() |
void |
doFilter(javax.servlet.ServletRequest servletRequest,
javax.servlet.ServletResponse servletResponse,
javax.servlet.FilterChain filterChain) |
protected boolean |
getAutoReload()
Whether the config file should be monitored for changes and automatically reloaded.
|
protected String |
getConfigFileName()
Gets the SiteMesh XML config file name.
|
protected Map<String,String> |
getConfigProperties(javax.servlet.FilterConfig filterConfig)
Return the configuration properties that are passed to
PropertiesFilterConfigurator . |
protected ObjectFactory |
getObjectFactory() |
void |
init(javax.servlet.FilterConfig filterConfig) |
protected Element |
loadConfigXml(javax.servlet.FilterConfig filterConfig,
String configFilePath)
Load the XML config file.
|
protected void |
reloadIfNecessary() |
protected boolean |
reloadRequired()
Determine if a reload is required.
|
protected javax.servlet.Filter |
setup() |
public static final String CONFIG_FILE_PARAM
public static final String CONFIG_FILE_DEFAULT
public static final String AUTO_RELOAD_PARAM
public static final boolean AUTO_RELOAD_DEFAULT
public void init(javax.servlet.FilterConfig filterConfig) throws javax.servlet.ServletException
init
in interface javax.servlet.Filter
javax.servlet.ServletException
public void doFilter(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse, javax.servlet.FilterChain filterChain) throws IOException, javax.servlet.ServletException
doFilter
in interface javax.servlet.Filter
IOException
javax.servlet.ServletException
public void destroy()
destroy
in interface javax.servlet.Filter
protected Map<String,String> getConfigProperties(javax.servlet.FilterConfig filterConfig)
PropertiesFilterConfigurator
.
This implementation simply reads them from the Filter's <init-param>
s in web.xml
.
To read from another place, override this.
protected javax.servlet.Filter setup() throws javax.servlet.ServletException
javax.servlet.ServletException
protected void applyCustomConfiguration(SiteMeshFilterBuilder builder)
protected boolean reloadRequired()
protected boolean getAutoReload()
protected String getConfigFileName()
protected ObjectFactory getObjectFactory()
protected Element loadConfigXml(javax.servlet.FilterConfig filterConfig, String configFilePath) throws javax.servlet.ServletException
- Will first search for a file on disk relative to the root of the web-app. - Then a file with the absolute path. - Then a file as a resource in the ServletContext (allowing for files embedded in a .war file). - If none of those find the file, null will be returned.
javax.servlet.ServletException
protected void reloadIfNecessary() throws javax.servlet.ServletException
javax.servlet.ServletException
protected void deployNewFilter(javax.servlet.Filter newFilter) throws javax.servlet.ServletException
javax.servlet.ServletException
Copyright © 2015. All Rights Reserved.