public class DustCompilingFilter
extends java.lang.Object
implements javax.servlet.Filter
DustCompiler
This allows to use JSP or any other framework to create dynamic templates.
Supports simple session-based cache and eTag support to control client-side caching of compiled templates
To setup filter in your application, add the definitions to yout web.xml:
<filter>
<filter-name>dustCompilingFilter</filter-name>
<filter-class>me.noroutine.dust4j.DustCompilingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>dustCompilingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Note that you should use /* as url-pattern, due to the fact that *.dust.js doesn't work as one would expect.
So filter will apply for any URL, but it will only compile those that match the templateNameRegex,
which is by default any URL that ends with .dust.js
This filter supports the following parameters:
| init-param name | Type | Default | Description |
|---|---|---|---|
| cache | boolean | true | Enable/disable internal cache |
| eTag | boolean | false | Enable/disable ETag support |
| compilerFactory | string | me.noroutine.dust4j.DefaultDustCompilerFactory | Canonical name of factory for obtaining DustCompiler instance. Should implement DustCompilerFactory interface |
| templateNameRegex | regular expression | /(.*).dust.js$ | Regex to apply to relative part of requests to generate template names. Should contain one and only matching group that will be used to infer template name |
Filter has a set of setters to use it as a component in DI framework like Spring. Spring provides a proxy servlet filter that can delegate filter processing to Spring-managed bean. To configure this, define your filter like this:
<filter>
<filter-name>dustCompilingFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>dustCompilingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
And define a bean with id dustCompilingFilterin your applicationContext.xml (NOT dispatcher servlet context)
<bean name="dustCompilingFilter" class="me.noroutine.dust4j.DustCompilingFilter">
<property name="compilerFactory">
<bean class="me.noroutine.dust4j.DefaultDustCompilerFactory" />
</property>
<property name="cacheEnabled" value="true" />
<property name="ETagEnabled" value="true" />
</bean>
| Constructor and Description |
|---|
DustCompilingFilter() |
| Modifier and Type | Method and Description |
|---|---|
void |
destroy() |
void |
doFilter(javax.servlet.ServletRequest req,
javax.servlet.ServletResponse resp,
javax.servlet.FilterChain chain) |
static java.lang.String |
getURL(javax.servlet.http.HttpServletRequest req) |
void |
init(javax.servlet.FilterConfig filterConfig) |
void |
setCacheEnabled(boolean cacheEnabled) |
void |
setCompilerFactory(DustCompilerFactory compilerFactory) |
void |
setETagEnabled(boolean eTagEnabled) |
void |
setTemplateNameRegex(java.lang.String templateNameRegex) |
public void init(javax.servlet.FilterConfig filterConfig)
throws javax.servlet.ServletException
init in interface javax.servlet.Filterjavax.servlet.ServletExceptionpublic void doFilter(javax.servlet.ServletRequest req,
javax.servlet.ServletResponse resp,
javax.servlet.FilterChain chain)
throws java.io.IOException,
javax.servlet.ServletException
doFilter in interface javax.servlet.Filterjava.io.IOExceptionjavax.servlet.ServletExceptionpublic void destroy()
destroy in interface javax.servlet.Filterpublic void setCacheEnabled(boolean cacheEnabled)
public void setETagEnabled(boolean eTagEnabled)
public void setCompilerFactory(DustCompilerFactory compilerFactory)
public void setTemplateNameRegex(java.lang.String templateNameRegex)
public static java.lang.String getURL(javax.servlet.http.HttpServletRequest req)
Copyright © 2013. All Rights Reserved.