A SiteMesh filter that can be dropped in to web.xml, that does not require having to write any Java code.
Approach 1: Embed configuration as init-params
The minimum required to make this useful is to add a
decoratorMappings init parameter.
/WEB-INF/web.xml
<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>
Approach 2: Embed configuration as init-params
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.
/WEB-INF/web.xml
<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>
/WEB-INF/sitemesh3.xml
<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.
Reference
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
org.sitemesh.content.tagrules.TagRuleBundles to install, separated by whitespace or commas.
These will be added to the default bundles (as set up in
org.sitemesh.builder.BaseSiteMeshBuilder#setupDefaults()):
org.sitemesh.content.tagrules.html.CoreHtmlTagRuleBundle and
org.sitemesh.content.tagrules.decorate.DecoratorTagRuleBundle.
Note: The contentProcessor
and tagRuleBundles
are mutually exclusive
- you should not set them both.
contentProcessor
(optional): The name of the
org.sitemesh.content.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.