public class HtmlParserFilter extends ContextBuilderConfigurator implements Filter
This filter uses the WuicFacade
to configure the related ContextBuilder
with workflow
built on the fly when an HTML page is filtered. The created workflow uses default engines.
This filters uses an internal NutDao
to retrieve referenced nuts when parsing HTML.
By default, the DAO built from a RequestDispatcherNutDao
. DAO is configured
like this for consistency reason because the version number must be computed from content when scripts are declared
inside tag. User can takes control over NutDao
creation by extending this class and
overriding the createContextNutDaoBuilder(String, com.github.wuic.context.ContextBuilder, String)
method.
WUIC considers that a filtered content is static by default and could be cached as any other resource. This will be
the cache for many applications that does not use server-side HTML generation. However, if the content is dynamic,
e.g it is not the same for two different users, WUIC should not cache it to serve an up-to-date response body. The
filter detects a dynamic content when it has been generated with a tag officially provided by WUIC (like taglib for
JSP or processor for Thymeleaf). In case of a dynamic content generated otherwise, you can use the init-param
FORCE_DYNAMIC_CONTENT
to tell WUIC to consider the content always dynamic.
This filter supports server-hint mode. Server-hint is enabled by default. It associates to all resources that should be loaded as soon as possible by the HTML page a "Link" header with "preload" rel value. Other resources are associated to a "prefetch" rel value to tell the browser to download them with a low priority. Note that proxy like "nghttpx" can use this header to push the resource over HTTP/2.
Server-push is also supported. It relies on a PushService
implementation discovered in the classpath.
It will be enabled by default if an implementation is found by the ServiceLoader
. You can disable the
server-push with the DISABLE_SERVER_PUSH
init-param.
PollingScheduler.Polling
Modifier and Type | Field and Description |
---|---|
static String |
DISABLE_SERVER_PUSH
Property that tells the filter to use or not HTTP2 server push.
|
static String |
FORCE_DYNAMIC_CONTENT
An init parameter that tells the filter how to consider the filtered content dynamic or not.
|
static String |
SKIP_FILTER
If an attribute with this name is defined in the filtered request, then this filter will skip its related operation.
|
Constructor and Description |
---|
HtmlParserFilter()
Builds a new instance.
|
HtmlParserFilter(WuicFacade wuicFacade)
Builds a new instance with a specific
WuicFacade and the default RequestDispatcherNutDao builder
as root NutDao builder. |
HtmlParserFilter(WuicFacade wuicFacade,
String rootNuDaoBuilderId)
Builds a new instance with a specific
WuicFacade and a root NutDao builder. |
Modifier and Type | Method and Description |
---|---|
protected ByteArrayNut |
configureBuilder(HttpServletRequest request,
String path,
ContextBuilder contextBuilder,
String workflowId,
byte[] content)
Configures the workflow corresponding to the given ID in the specified context builder.
|
protected ContextBuilder.ContextNutDaoBuilder |
createContextNutDaoBuilder(String id,
ContextBuilder contextBuilder,
String rootNutDaoBuilderId)
Creates a new
ContextBuilder.ContextNutDaoBuilder with the given ContextBuilder . |
void |
destroy() |
void |
doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain) |
protected Long |
getLastUpdateTimestampFor(String path)
Retrieves a timestamp that indicates the last time this nut has changed.
|
ProcessContext |
getProcessContext()
Gets the process context associated to the tag while configuring.
|
String |
getTag()
Gets the tag to use to identify the set of settings defined when
ContextBuilderConfigurator.configure(ContextBuilder)
is called. |
void |
init(FilterConfig filterConfig) |
int |
internalConfigure(ContextBuilder ctxBuilder)
Configures the given context internally.
|
configure, run, setMultipleConfigurations
getNutObservers, getPollingInterval, observe, setPollingInterval
public static final String DISABLE_SERVER_PUSH
public static final String FORCE_DYNAMIC_CONTENT
public static final String SKIP_FILTER
public HtmlParserFilter(WuicFacade wuicFacade, String rootNuDaoBuilderId)
Builds a new instance with a specific WuicFacade
and a root NutDao
builder.
wuicFacade
- the WUIC facaderootNuDaoBuilderId
- the root nut DAO builder IDpublic HtmlParserFilter(WuicFacade wuicFacade)
Builds a new instance with a specific WuicFacade
and the default RequestDispatcherNutDao
builder
as root NutDao
builder.
wuicFacade
- the WUIC facadepublic HtmlParserFilter()
Builds a new instance. The internal WuicFacade
will be initialized when init(javax.servlet.FilterConfig)
method will be invoked. At this moment, this class will get the object from WuicServletContextListener
.
In this case, the listener must be declared in th servlet container configuration.
public void init(FilterConfig filterConfig) throws ServletException
init
in interface Filter
ServletException
protected ContextBuilder.ContextNutDaoBuilder createContextNutDaoBuilder(String id, ContextBuilder contextBuilder, String rootNutDaoBuilderId)
Creates a new ContextBuilder.ContextNutDaoBuilder
with the given ContextBuilder
.
id
- the IDcontextBuilder
- the context builder to userootNutDaoBuilderId
- the root NutDao
builder which should be extended by the new builderpublic void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
doFilter
in interface Filter
IOException
ServletException
protected ByteArrayNut configureBuilder(HttpServletRequest request, String path, ContextBuilder contextBuilder, String workflowId, byte[] content) throws IOException, WuicException
Configures the workflow corresponding to the given ID in the specified context builder.
request
- the requestpath
- the filtered nut pathcontextBuilder
- the builderworkflowId
- the workflow IDWuicException
- if context can't be refreshedIOException
- if any I/O error occurspublic int internalConfigure(ContextBuilder ctxBuilder)
Configures the given context internally. This method is called just after the ContextBuilder
has been
tagged with the value returned by ContextBuilderConfigurator.getTag()
method. Once the
execution of this method is terminated, the tag is released.
To activate polling on this configurator, this method should returns a positive integer representing the polling interval in seconds.
internalConfigure
in class ContextBuilderConfigurator
ctxBuilder
- the builderpublic String getTag()
Gets the tag to use to identify the set of settings defined when ContextBuilderConfigurator.configure(ContextBuilder)
is called.
getTag
in class ContextBuilderConfigurator
protected Long getLastUpdateTimestampFor(String path) throws IOException
Retrieves a timestamp that indicates the last time this nut has changed.
getLastUpdateTimestampFor
in class PollingScheduler<ContextBuilderConfigurator>
path
- the real path of the nutIOException
- if any I/O error occurspublic ProcessContext getProcessContext()
Gets the process context associated to the tag while configuring.
getProcessContext
in class ContextBuilderConfigurator
Copyright © 2012-2015. All Rights Reserved.