FreemarkerResult.class
public
class
FreemarkerResult
extends
WebWorkResultSupport
... {
protected ActionInvocation invocation;
protected Configuration configuration;
protected ObjectWrapper wrapper;
protected String filename; // 要转换的静态页面名称
protected String template; // 静态页面模板的路径
protected String filepath; // 文件夹名
protected String location;
private String pContentType = "text/html";
public void doExecute(String location, ActionInvocation invocation) throws IOException,
TemplateException
...{
this.location = location;
this.invocation = invocation;
this.configuration = getConfiguration();
this.wrapper = getObjectWrapper();
this.filename ="/"+ (String) conditionalParse(filename, invocation);
this.template = (String) conditionalParse(template, invocation);
this.filepath = ((String) conditionalParse(filepath, invocation))==null?"":((String) conditionalParse(filepath, invocation));
// 跳转页面的模板类
Template template = configuration.getTemplate(location, deduceLocale());
// 转换静台页面的的模板类
Template statictemplate = configuration.getTemplate(this.template, deduceLocale());
TemplateModel model = createModel();
String path = ServletActionContext.getServletContext().getRealPath(filepath)
+ File.separator;
this.delFile(path + filename);
Writer out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(path + filename)));
if (preTemplateProcess(template, model))
...{
try
...{
// 在指定路径生成静态页面
statictemplate.process(model, out);
// 生成跳转的页面
template.process(model, getWriter());
} finally
...{
postTemplateProcess(template, model);
postTemplateProcess(statictemplate, model);
}
}
}
}
... {
protected ActionInvocation invocation;
protected Configuration configuration;
protected ObjectWrapper wrapper;
protected String filename; // 要转换的静态页面名称
protected String template; // 静态页面模板的路径
protected String filepath; // 文件夹名
protected String location;
private String pContentType = "text/html";
public void doExecute(String location, ActionInvocation invocation) throws IOException,
TemplateException
...{
this.location = location;
this.invocation = invocation;
this.configuration = getConfiguration();
this.wrapper = getObjectWrapper();
this.filename ="/"+ (String) conditionalParse(filename, invocation);
this.template = (String) conditionalParse(template, invocation);
this.filepath = ((String) conditionalParse(filepath, invocation))==null?"":((String) conditionalParse(filepath, invocation));
// 跳转页面的模板类
Template template = configuration.getTemplate(location, deduceLocale());
// 转换静台页面的的模板类
Template statictemplate = configuration.getTemplate(this.template, deduceLocale());
TemplateModel model = createModel();
String path = ServletActionContext.getServletContext().getRealPath(filepath)
+ File.separator;
this.delFile(path + filename);
Writer out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(path + filename)));
if (preTemplateProcess(template, model))
...{
try
...{
// 在指定路径生成静态页面
statictemplate.process(model, out);
// 生成跳转的页面
template.process(model, getWriter());
} finally
...{
postTemplateProcess(template, model);
postTemplateProcess(statictemplate, model);
}
}
}
}
xwork.xml
<
result
-
types
>
< result - type name = " staticview " class = " msocweb.common.FreemarkerResult " ></ result - type >
</ result - types >
< action name = " staticViewAction " class = " msocweb.sitemanage_u.action.StaticViewAction " >
< external - ref name = " newsService " > newsService </ external - ref >
< result name = " success " type = " staticview " >
< param name = " location " > websitemanage / success.ftl </ param >
< param name = " filename " > $ ... {filename} </ param >
< param name = " template " > index / newsdetail.ftl </ param >
< param name = " filepath " >/ static </ param >
</ result >
</ action >
< result - type name = " staticview " class = " msocweb.common.FreemarkerResult " ></ result - type >
</ result - types >
< action name = " staticViewAction " class = " msocweb.sitemanage_u.action.StaticViewAction " >
< external - ref name = " newsService " > newsService </ external - ref >
< result name = " success " type = " staticview " >
< param name = " location " > websitemanage / success.ftl </ param >
< param name = " filename " > $ ... {filename} </ param >
< param name = " template " > index / newsdetail.ftl </ param >
< param name = " filepath " >/ static </ param >
</ result >
</ action >