當前位置: 首頁>>代碼示例>>Java>>正文


Java Template.createProcessingEnvironment方法代碼示例

本文整理匯總了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);
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:32,代碼來源:AbstractFreemarkerFactory.java

示例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);
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:61,代碼來源:FreeMarkerProcessor.java


注:本文中的freemarker.template.Template.createProcessingEnvironment方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。