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


Java Environment.process方法代碼示例

本文整理匯總了Java中freemarker.core.Environment.process方法的典型用法代碼示例。如果您正苦於以下問題:Java Environment.process方法的具體用法?Java Environment.process怎麽用?Java Environment.process使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在freemarker.core.Environment的用法示例。


在下文中一共展示了Environment.process方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: render

import freemarker.core.Environment; //導入方法依賴的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: renderTemplate

import freemarker.core.Environment; //導入方法依賴的package包/類
/**
 * Renders a Template instance.
 * @param template A Template instance
 * @param context The context Map
 * @param outWriter The Writer to render to
 */
public static Environment renderTemplate(Template template, Map<String, Object> context, Appendable outWriter) throws TemplateException, IOException {
    // SCIPIO: 2015-12-15: we want a patch around the processing code to remove our saved copy of
    // the FTL environment. within this call we know that FTL will store its own environment and make accessible via
    // Environment.getCurrentEnvironment().
    // ideally we want at most one of the two to be non-null at any given time.
    // this method is the best effort we can do to try to enforce that.
    // @see FreeMarkerWorker#getCurrentEnvironment
    Environment savedEnv = threadEnv.get();
    threadEnv.set(null);
    try {
        // make sure there is no "null" string in there as FreeMarker will try to use it
        context.remove("null");
        // Since the template cache keeps a single instance of a Template that is shared among users,
        // and since that Template instance is immutable, we need to create an Environment instance and
        // use it to process the template with the user's settings.
        //
        // FIXME: the casting from Appendable to Writer is a temporary fix that could cause a
        //        run time error if in the future we will pass a different class to the method
        //        (such as a StringBuffer).
        Environment env = template.createProcessingEnvironment(context, (Writer) outWriter);
        applyUserSettings(env, context);
        env.process();
        return env;
    }
    finally {
        threadEnv.set(savedEnv);
    }
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:35,代碼來源:FreeMarkerWorker.java

示例3: process

import freemarker.core.Environment; //導入方法依賴的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

示例4: freemarkerTemplateStream

import freemarker.core.Environment; //導入方法依賴的package包/類
protected Resolution freemarkerTemplateStream(String content, String cacheFor) {
    StringWriter sw = new StringWriter();

    try {
        if (cacheFor != null) {
            // Set cache header for caching server.
            getResponse().setHeader("X-CB-Cache-Page", cacheFor);
        }

        ClassLoader cl = getClass().getClassLoader();
        Module m = null;

        if (cl instanceof ModuleClassLoader) {
            ModuleClassLoader mcl = (ModuleClassLoader) (cl);
            m = mcl.getModule();
        }

        Configuration conf = FreemarkerHelper.newConfig(app.servletContext(), m);

        getResponse().setLocale(conf.getLocale());
        getResponse().setCharacterEncoding("UTF-8");

        TemplateModel tm = FreemarkerHelper.createModel(ObjectWrapper.DEFAULT_WRAPPER, app.servletContext(),
            getRequest(), getResponse());

        app.registryPut(FreemarkerConstant.FREEMARKER_REQUEST_TEMPLATE_MODEL, tm);

        Template t = new Template("templateName", new StringReader(content), conf);

        Environment env = t.createProcessingEnvironment(tm, sw);
        env.setLocale(conf.getLocale());
        env.process();
    } catch (Throwable th) {
        if (app.isDevPrintErrorMessages()) {
            System.out.println("An error occured while rendering template from string :  " + content);
            th.printStackTrace();
        }

        throw new RuntimeException(th.getMessage(), th);
    }

    Resolution r = new StreamingResolution("text/html", sw.toString());

    return r;
}
 
開發者ID:geetools,項目名稱:geeCommerce-Java-Shop-Software-and-PIM,代碼行數:46,代碼來源:BaseActionBean.java

示例5: process

import freemarker.core.Environment; //導入方法依賴的package包/類
public void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    App app = App.get();

    String path = requestUrlToTemplatePath(request);
    String viewPath = app.getViewPath();

    if (viewPath == null && !Str.isEmpty(path)) {
        int pos1 = path.indexOf(BASE_PAGES_PATH) + BASE_PAGES_PATH.length();
        int pos2 = path.lastIndexOf(Char.DOT);

        app.setViewPath(path.substring(pos1, pos2));
    }

    StringWriter sw = new StringWriter();
    Template t = null;

    try {
        Module m = app.getTargetModule();

        if (m == null) {
            m = app.getCurrentModule();
        }

        Configuration conf = FreemarkerHelper.newConfig(app.servletContext(), m);

        app.servletResponse().setLocale(conf.getLocale());
        app.servletResponse().setCharacterEncoding("UTF-8");

        TemplateModel tm = FreemarkerHelper.createModel(ObjectWrapper.DEFAULT_WRAPPER, app.servletContext(),
            app.servletRequest(), app.servletResponse());

        app.registryPut(FreemarkerConstant.FREEMARKER_REQUEST_TEMPLATE_MODEL, tm);

        t = conf.getTemplate(path, conf.getLocale(), "UTF-8");

        Environment env = t.createProcessingEnvironment(tm, sw);

        env.setLocale(conf.getLocale());

        env.process(); // process the template

        response.getWriter().write(sw.toString());
    } catch (Throwable th) {
        th.printStackTrace();

        if (app.isDevPrintErrorMessages()) {
            System.out.println("An error occured while rendering template: " + (t == null ? path : t.getName()));
            th.printStackTrace();
        }

        throw new RuntimeException(th.getMessage(), th);
    }
}
 
開發者ID:geetools,項目名稱:geeCommerce-Java-Shop-Software-and-PIM,代碼行數:54,代碼來源:FreemarkerServlet.java


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