Class FreemarkerResult
- All Implemented Interfaces:
- Serializable,- Result,- StrutsStatics
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected freemarker.template.Configurationprotected FreemarkerManagerprotected ActionInvocationprotected Stringprotected freemarker.template.ObjectWrapperFields inherited from class org.apache.struts2.result.StrutsResultSupportDEFAULT_PARAM, DEFAULT_URL_ENCODING, parseLocationFields inherited from interface org.apache.struts2.StrutsStaticsACTION_MAPPING, HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_ACTION_TAG_INVOCATION
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected freemarker.template.TemplateModelBuild the instance of the ScopesHashModel, including JspTagLib supportprotected LocaleReturns the locale used for theConfiguration.getTemplate(String, Locale)call.voiddoExecute(String locationArg, ActionInvocation invocation) Execute this result, using the specified template locationArg.protected freemarker.template.ConfigurationThis method is called fromdoExecute(String, ActionInvocation)to obtain the FreeMarker configuration object that this result will use for template loading.allow parameterization of the contentType the default being text/htmlprotected freemarker.template.ObjectWrapperThis method is called fromdoExecute(String, ActionInvocation)to obtain the FreeMarker object wrapper object that this result will use for adapting objects into template models.protected WriterThe default writer writes directly to the response writer.booleanprotected voidpostTemplateProcess(freemarker.template.Template template, freemarker.template.TemplateModel model) the default implementation of postTemplateProcess applies the contentType parameterprotected booleanpreTemplateProcess(freemarker.template.Template template, freemarker.template.TemplateModel model) Called before the execution is passed to template.process().voidsetContentType(String aContentType) voidvoidsetWriteIfCompleted(Boolean writeIfCompleted) voidMethods inherited from class org.apache.struts2.result.StrutsResultSupportconditionalParse, conditionalParseCollection, execute, getLastFinalLocation, getLocation, setEncode, setLocation, setParse
- 
Field Details- 
invocation
- 
configurationprotected freemarker.template.Configuration configuration
- 
wrapperprotected freemarker.template.ObjectWrapper wrapper
- 
freemarkerManager
- 
location
 
- 
- 
Constructor Details- 
FreemarkerResultpublic FreemarkerResult()
- 
FreemarkerResult
 
- 
- 
Method Details- 
setFreemarkerManager
- 
setContentType
- 
getContentTypeallow parameterization of the contentType the default being text/html- Returns:
- the content type
 
- 
doExecutepublic void doExecute(String locationArg, ActionInvocation invocation) throws IOException, freemarker.template.TemplateException Execute this result, using the specified template locationArg.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 - Specified by:
- doExecutein class- StrutsResultSupport
- Parameters:
- locationArg- location argument
- invocation- the action invocation
- Throws:
- IOException- in case of IO errors
- freemarker.template.TemplateException- in case of freemarker template errors
 
- 
getConfigurationprotected freemarker.template.Configuration getConfiguration() throws freemarker.template.TemplateExceptionThis 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. - Returns:
- the freemarker configuration object
- Throws:
- freemarker.template.TemplateException- in case of freemarker configuration errors
 
- 
getObjectWrapperprotected 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()- Returns:
- the object wrapper from configuration
 
- 
setWriter
- 
getWriterThe default writer writes directly to the response writer.- Returns:
- Writer the response writer
- Throws:
- IOException- in case of IO errors
 
- 
createModelprotected freemarker.template.TemplateModel createModel() throws freemarker.template.TemplateModelExceptionBuild the instance of the ScopesHashModel, including JspTagLib supportObjects added to the model are - Application - servlet context attributes hash model
- JspTaglibs - jsp tag lib factory model
- Request - request attributes hash model
- Session - session attributes hash model
- request - the HttpServletRequst object for direct access
- response - the HttpServletResponse object for direct access
- stack - the OgnLValueStack instance for direct access
- action - the action itself
- exception - optional : the JSP or Servlet exception as per the servlet spec (for JSP Exception pages)
- struts - instance of the StrutsUtil class
 - Returns:
- TemplateModel returns the created template model
- Throws:
- freemarker.template.TemplateModelException- in case of errors during creating the model
 
- 
deduceLocaleReturns the locale used for theConfiguration.getTemplate(String, Locale)call. The base implementation simply returns the locale setting of the action (assuming the action implementsLocaleProvider) or, if the action does not the configuration's locale is returned. Override this method to provide different behaviour,- Returns:
- the locale from action if action implements the LocaleProvider) or local from configuration
 
- 
postTemplateProcessprotected void postTemplateProcess(freemarker.template.Template template, freemarker.template.TemplateModel model) throws IOException the default implementation of postTemplateProcess applies the contentType parameter- Parameters:
- template- the freemarker template
- model- the template model
- Throws:
- IOException- in case of IO errors
 
- 
preTemplateProcessprotected boolean preTemplateProcess(freemarker.template.Template template, freemarker.template.TemplateModel model) throws IOException Called before the execution is passed to template.process(). This is a generic hook you might use in subclasses to perform a specific action before the template is processed. By default does nothing. A typical action to perform here is to inject application-specific objects into the model root- Parameters:
- template- the freemarker template
- model- the template model
- Returns:
- true to process the template, false to suppress template processing.
- Throws:
- IOException- in case of IO errors
 
- 
isWriteIfCompletedpublic boolean isWriteIfCompleted()
- 
setWriteIfCompleted- Parameters:
- writeIfCompleted- template is processed and flushed according to freemarker library policies
 
 
-