public class FreemarkerResult extends StrutsResultSupport
Modifier and Type | Field and Description |
---|---|
protected freemarker.template.Configuration |
configuration |
protected FreemarkerManager |
freemarkerManager |
protected ActionInvocation |
invocation |
protected String |
location |
protected freemarker.template.ObjectWrapper |
wrapper |
DEFAULT_PARAM, DEFAULT_URL_ENCODING, parseLocation
HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_ACTION_TAG_INVOCATION, STRUTS_PORTLET_CONTEXT
Constructor and Description |
---|
FreemarkerResult() |
FreemarkerResult(String location) |
Modifier and Type | Method and Description |
---|---|
protected freemarker.template.TemplateModel |
createModel()
Build the instance of the ScopesHashModel, including JspTagLib support
|
protected Locale |
deduceLocale()
Returns the locale used for the
Configuration.getTemplate(String, Locale) call. |
void |
doExecute(String locationArg,
ActionInvocation invocation)
Execute this result, using the specified template locationArg.
|
protected freemarker.template.Configuration |
getConfiguration()
This method is called from
doExecute(String, ActionInvocation) to obtain the
FreeMarker configuration object that this result will use for template loading. |
String |
getContentType()
allow parameterization of the contentType
the default being text/html
|
protected freemarker.template.ObjectWrapper |
getObjectWrapper()
This method is called from
doExecute(String, ActionInvocation) to obtain the
FreeMarker object wrapper object that this result will use for adapting objects into template
models. |
protected Writer |
getWriter()
The default writer writes directly to the response writer.
|
boolean |
isWriteIfCompleted() |
protected void |
postTemplateProcess(freemarker.template.Template template,
freemarker.template.TemplateModel model)
the default implementation of postTemplateProcess applies the contentType parameter
|
protected boolean |
preTemplateProcess(freemarker.template.Template template,
freemarker.template.TemplateModel model)
Called before the execution is passed to template.process().
|
void |
setContentType(String aContentType) |
void |
setFreemarkerManager(FreemarkerManager mgr) |
void |
setWriteIfCompleted(Boolean writeIfCompleted) |
void |
setWriter(Writer writer) |
conditionalParse, conditionalParseCollection, execute, getLastFinalLocation, getLocation, setEncode, setLocation, setParse
protected ActionInvocation invocation
protected freemarker.template.Configuration configuration
protected freemarker.template.ObjectWrapper wrapper
protected FreemarkerManager freemarkerManager
protected String location
public FreemarkerResult()
public FreemarkerResult(String location)
public void setFreemarkerManager(FreemarkerManager mgr)
public void setContentType(String aContentType)
public String getContentType()
public void doExecute(String locationArg, ActionInvocation invocation) throws IOException, freemarker.template.TemplateException
The template locationArg has already been interpolated for any variable substitutions
this method obtains the freemarker configuration and the object wrapper from the provided hooks. It them implements the template processing workflow by calling the hooks for preTemplateProcess and postTemplateProcess
doExecute
in class StrutsResultSupport
locationArg
- location argumentinvocation
- the action invocationIOException
- in case of IO errorsfreemarker.template.TemplateException
- in case of freemarker template errorsprotected freemarker.template.Configuration getConfiguration() throws freemarker.template.TemplateException
This method is called from doExecute(String, ActionInvocation)
to obtain the
FreeMarker configuration object that this result will use for template loading. This is a
hook that allows you to custom-configure the configuration object in a subclass, or to fetch
it from an IoC container.
The default implementation obtains the configuration from the ConfigurationManager instance.
freemarker.template.TemplateException
- in case of freemarker configuration errorsprotected freemarker.template.ObjectWrapper getObjectWrapper()
This method is called from doExecute(String, ActionInvocation)
to obtain the
FreeMarker object wrapper object that this result will use for adapting objects into template
models. This is a hook that allows you to custom-configure the wrapper object in a subclass.
The default implementation returns Configurable.getObjectWrapper()
public void setWriter(Writer writer)
protected Writer getWriter() throws IOException
IOException
- in case of IO errorsprotected freemarker.template.TemplateModel createModel() throws freemarker.template.TemplateModelException
Objects added to the model are
freemarker.template.TemplateModelException
- in case of errors during creating the modelprotected Locale deduceLocale()
Configuration.getTemplate(String, Locale)
call. The base implementation
simply returns the locale setting of the action (assuming the action implements LocaleProvider
) or, if
the action does not the configuration's locale is returned. Override this method to provide different behaviour,LocaleProvider
) or local from configurationprotected void postTemplateProcess(freemarker.template.Template template, freemarker.template.TemplateModel model) throws IOException
template
- the freemarker templatemodel
- the template modelIOException
- in case of IO errorsprotected boolean preTemplateProcess(freemarker.template.Template template, freemarker.template.TemplateModel model) throws IOException
template
- the freemarker templatemodel
- the template modelIOException
- in case of IO errorspublic boolean isWriteIfCompleted()
public void setWriteIfCompleted(Boolean writeIfCompleted)
writeIfCompleted
- template is processed and flushed according to freemarker library policiesCopyright © 2000–2020 Apache Software Foundation. All rights reserved.