Example usage for org.springframework.web.servlet.view.freemarker FreeMarkerConfigurer getConfiguration

List of usage examples for org.springframework.web.servlet.view.freemarker FreeMarkerConfigurer getConfiguration

Introduction

In this page you can find the example usage for org.springframework.web.servlet.view.freemarker FreeMarkerConfigurer getConfiguration.

Prototype

@Override
public Configuration getConfiguration() 

Source Link

Document

Return the Configuration object wrapped by this bean.

Usage

From source file:com.lingxiang2014.util.FreemarkerUtils.java

public static String process(String template, Map<String, ?> model) throws IOException, TemplateException {
    Configuration configuration = null;
    ApplicationContext applicationContext = SpringUtils.getApplicationContext();
    if (applicationContext != null) {
        FreeMarkerConfigurer freeMarkerConfigurer = SpringUtils.getBean("freeMarkerConfigurer",
                FreeMarkerConfigurer.class);
        if (freeMarkerConfigurer != null) {
            configuration = freeMarkerConfigurer.getConfiguration();
        }//  w  w w  .ja v  a2  s  .co m
    }
    return process(template, model, configuration);
}

From source file:net.groupbuy.util.FreemarkerUtils.java

/**
 * ??//from   w w  w.  ja  v a2 s . c o m
 * 
 * @param template
 *            ?
 * @param model
 *            ?
 * @return ??
 */
public static String process(String template, Map<String, ?> model) throws IOException, TemplateException {
    Configuration configuration = null;
    ApplicationContext applicationContext = SpringUtils.getApplicationContext();
    if (applicationContext != null) {
        FreeMarkerConfigurer freeMarkerConfigurer = SpringUtils.getBean("freeMarkerConfigurer",
                FreeMarkerConfigurer.class);
        if (freeMarkerConfigurer != null) {
            configuration = freeMarkerConfigurer.getConfiguration();
        }
    }
    return process(template, model, configuration);
}

From source file:net.cloudkit.enterprises.infrastructure.utilities.FreemarkerHelper.java

/**
 * Process Template//  w w  w. j av a  2  s. c  o  m
 *
 * @param templateName
 * @param model
 * @param writer
 * @return
 */
public static String process(String templateName, Map<String, ?> model, Writer writer) {

    /*
    // Where you initialize the cfg *singleton* (happens just once in the application life-cycle):
    cfg = new Configuration(Configuration.VERSION_2_3_22);
    ...
    cfg.setObjectWrapper(new MyAppObjectWrapper(cfg.getIncompatibleImprovements()));
    */

    Configuration cfg = null;
    ApplicationContext localApplicationContext = SpringHelper.getApplicationContext();
    if (localApplicationContext != null) {
        FreeMarkerConfigurer freeMarkerConfigurer = (FreeMarkerConfigurer) SpringHelper
                .getBean("freeMarkerConfigurer", FreeMarkerConfigurer.class);
        if (freeMarkerConfigurer != null) {
            cfg = freeMarkerConfigurer.getConfiguration();
        }
    }
    try {
        // cfg.setDirectoryForTemplateLoading(new File(filePath));
        cfg.setObjectWrapper(new BeansWrapper(Configuration.VERSION_2_3_22));
        Template template = cfg.getTemplate(templateName);
        // template.setEncoding("UTF-8");
        template.process(model, writer);
        // new Template("template", new StringReader(template), cfg).process(model, writer);
    } catch (TemplateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        logger.error(e.getMessage());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        logger.error(e.getMessage());
    }
    return writer.toString();
}

From source file:org.hdiv.web.servlet.view.freemarker.FreeMarkerConfigurerTests.java

public void testTemplateLoaders() throws Exception {
    FreeMarkerConfigurer fc = new FreeMarkerConfigurer();
    fc.setTemplateLoaders(new TemplateLoader[] {});
    fc.afterPropertiesSet();//from ww  w. j  av  a 2s. c o  m
    assertTrue(fc.getConfiguration().getTemplateLoader() instanceof ClassTemplateLoader);

    fc = new FreeMarkerConfigurer();
    fc.setTemplateLoaders(new TemplateLoader[] { new ClassTemplateLoader() });
    fc.afterPropertiesSet();
    assertTrue(fc.getConfiguration().getTemplateLoader() instanceof MultiTemplateLoader);
}

From source file:net.naijatek.myalumni.util.mail.FreeMarkerTemplateMailerImpl.java

/** @spring.property ref="freemarkerConfig" */
public void setConfiguration(FreeMarkerConfigurer freeMarkerConfigurer) {
    this.configuration = freeMarkerConfigurer.getConfiguration();
}

From source file:org.ambraproject.user.action.ImportUsersCompleteAction.java

@Required
public void setFreemarkerConfig(final FreeMarkerConfigurer freemarkerConfig) {
    this.freeMarkerConfig = freemarkerConfig.getConfiguration();
}

From source file:org.topazproject.ambra.email.impl.FreemarkerTemplateMailer.java

/**
 * Set the free marker configurer/*ww w.ja v  a2  s . c o m*/
 * @param freemarkerConfig freeMarkerConfigurer
 */
public void setFreemarkerConfig(final FreeMarkerConfigurer freemarkerConfig) {
    this.configuration = freemarkerConfig.getConfiguration();
}

From source file:net.naijatek.myalumni.util.mail.SendMailUtil.java

/** @spring.property ref="freemarkerConfig" */
public void setFreeMarker(FreeMarkerConfigurer _freeMarker) {
    configuration = _freeMarker.getConfiguration();
    freeMarker = _freeMarker;/*from   www  . j a va  2s  .c om*/
}