本文整理匯總了Java中freemarker.template.Template.createProcessingEnvironment方法的典型用法代碼示例。如果您正苦於以下問題:Java Template.createProcessingEnvironment方法的具體用法?Java Template.createProcessingEnvironment怎麽用?Java Template.createProcessingEnvironment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類freemarker.template.Template
的用法示例。
在下文中一共展示了Template.createProcessingEnvironment方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: render
import freemarker.template.Template; //導入方法依賴的package包/類
public Environment render(FreemarkerSectionResult result, Writer writer)
{
Thread currentThread = Thread.currentThread();
ClassLoader origLoader = currentThread.getContextClassLoader();
Template template = result.getTemplate();
Map<String, Object> rootObjects = new HashMap<String, Object>();
addRootObjects(rootObjects, result, writer);
Map<String, Object> extraObjects = result.getExtraObjects();
if( extraObjects != null )
{
rootObjects.putAll(extraObjects);
}
currentThread.setContextClassLoader(getContextClassLoader());
try
{
Environment environment = template.createProcessingEnvironment(rootObjects, writer);
setupEnvironment(writer, result, environment);
environment.process();
finishedRender(writer, result, environment);
return environment;
}
catch( Throwable te )
{
LOGGER.error("Error rendering " + result.getTemplate().getName());
throw Throwables.propagate(te);
}
finally
{
currentThread.setContextClassLoader(origLoader);
}
}
示例2: process
import freemarker.template.Template; //導入方法依賴的package包/類
/**
* @see org.alfresco.service.cmr.repository.TemplateProcessor#process(java.lang.String, java.lang.Object, java.io.Writer)
*/
public void process(String template, Object model, Writer out)
{
if (template == null || template.length() == 0)
{
throw new IllegalArgumentException("Template name is mandatory.");
}
if (model == null)
{
throw new IllegalArgumentException("Model is mandatory.");
}
if (out == null)
{
throw new IllegalArgumentException("Output Writer is mandatory.");
}
try
{
long startTime = 0;
if (logger.isDebugEnabled())
{
logger.debug("Executing template: " + template);// + " on model: " + model);
startTime = System.currentTimeMillis();
}
Template t = getConfig().getTemplate(template);
if (t != null)
{
try
{
// perform the template processing against supplied data model
Object freeMarkerModel = convertToFreeMarkerModel(model);
Environment env = t.createProcessingEnvironment(freeMarkerModel, out);
// set the locale to ensure dates etc. are appropriate localised
env.setLocale(I18NUtil.getLocale());
env.process();
}
catch (Throwable err)
{
throw new TemplateException(MSG_ERROR_TEMPLATE_FAIL, new Object[] {err.getMessage()}, err);
}
}
else
{
throw new TemplateException(MSG_ERROR_NO_TEMPLATE, new Object[] {template});
}
if (logger.isDebugEnabled())
{
long endTime = System.currentTimeMillis();
logger.debug("Time to execute template: " + (endTime - startTime) + "ms");
}
}
catch (IOException ioerr)
{
throw new TemplateException(MSG_ERROR_TEMPLATE_IO, new Object[] {template}, ioerr);
}
}