Search in sources :

Example 26 with Template

use of freemarker.template.Template in project jangaroo-tools by CoreMedia.

the class PropertyClassGenerator method generatePropertiesClass.

public void generatePropertiesClass(PropertiesClass propertiesClass, Writer out) throws IOException, TemplateException {
    Template template = cfg.getTemplate("properties_class.ftl");
    Environment env = template.createProcessingEnvironment(propertiesClass, out);
    env.setOutputEncoding(OUTPUT_CHARSET);
    env.process();
}
Also used : Environment(freemarker.core.Environment) Template(freemarker.template.Template)

Example 27 with Template

use of freemarker.template.Template in project jangaroo-tools by CoreMedia.

the class ExmlComponentClassGenerator method generateClass.

public void generateClass(final ExmlModel model, final Writer output) throws IOException, TemplateException {
    Configuration cfg = new Configuration();
    cfg.setClassForTemplateLoading(ExmlComponentClassModel.class, "/");
    cfg.setObjectWrapper(new DefaultObjectWrapper());
    Template template = cfg.getTemplate("/net/jangaroo/exml/templates/exml_component_class.ftl");
    ExmlComponentClassModel exmlComponentClassModel = new ExmlComponentClassModel(model);
    Environment env = template.createProcessingEnvironment(exmlComponentClassModel, output);
    env.setOutputEncoding(Exmlc.OUTPUT_CHARSET);
    env.process();
}
Also used : ExmlConfiguration(net.jangaroo.exml.config.ExmlConfiguration) Configuration(freemarker.template.Configuration) DefaultObjectWrapper(freemarker.template.DefaultObjectWrapper) Environment(freemarker.core.Environment) Template(freemarker.template.Template)

Example 28 with Template

use of freemarker.template.Template in project jangaroo-tools by CoreMedia.

the class ExmlConfigClassGenerator method generateClass.

private static void generateClass(final ConfigClass configClass, final Writer output) throws IOException, TemplateException {
    if (configClass.getSuperClassName() == null) {
        throw new ExmlcException("Config class " + configClass.getFullName() + "'s super class name is null!");
    }
    Configuration cfg = new Configuration();
    cfg.setClassForTemplateLoading(ConfigClass.class, "/");
    cfg.setObjectWrapper(new DefaultObjectWrapper());
    Template template = cfg.getTemplate("/net/jangaroo/exml/templates/exml_config_class.ftl");
    Environment env = template.createProcessingEnvironment(configClass, output);
    env.setOutputEncoding(Exmlc.OUTPUT_CHARSET);
    env.process();
}
Also used : Configuration(freemarker.template.Configuration) ExmlcException(net.jangaroo.exml.api.ExmlcException) DefaultObjectWrapper(freemarker.template.DefaultObjectWrapper) Environment(freemarker.core.Environment) Template(freemarker.template.Template)

Example 29 with Template

use of freemarker.template.Template in project jangaroo-tools by CoreMedia.

the class ExmlConfigPackageXsdGenerator method generateXsdFile.

public void generateXsdFile(final Collection<ConfigClass> configClasses, String configClassPackage, final Writer output) throws IOException, TemplateException {
    ExmlConfigPackage suite = new ExmlConfigPackage(configClasses, configClassPackage);
    Configuration cfg = new Configuration();
    cfg.setClassForTemplateLoading(ExmlConfigPackage.class, "/");
    cfg.setObjectWrapper(new DefaultObjectWrapper());
    Template template = cfg.getTemplate("/net/jangaroo/exml/templates/exml_config_package_xsd.ftl");
    Environment env = template.createProcessingEnvironment(suite, output);
    env.setOutputEncoding(Exmlc.OUTPUT_CHARSET);
    env.process();
}
Also used : Configuration(freemarker.template.Configuration) DefaultObjectWrapper(freemarker.template.DefaultObjectWrapper) Environment(freemarker.core.Environment) Template(freemarker.template.Template)

Example 30 with Template

use of freemarker.template.Template in project perun by CESNET.

the class PerunNotifTemplateManagerImpl method resolveSender.

private String resolveSender(String input, Map<String, Object> container) throws IOException {
    Matcher emailMatcher = Utils.emailPattern.matcher(input);
    String method = null;
    String email = null;
    if (input.contains(";")) {
        String[] parts = input.split(";", 2);
        method = parts[0];
        email = parts[1];
    } else if (!emailMatcher.find()) {
        method = input;
    } else {
        email = input;
    }
    if (method != null) {
        StringTemplateLoader stringTemplateLoader = (StringTemplateLoader) configuration.getTemplateLoader();
        stringTemplateLoader.putTemplate(EVALUATION_TEMPLATE, "${" + method + "}");
        configuration.clearTemplateCache();
        Template freeMarkerTemplate = this.configuration.getTemplate(EVALUATION_TEMPLATE);
        StringWriter stringWriter = new StringWriter(4096);
        try {
            // because for template messages the nulls are ignored, now we want to fail when null
            this.configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
            freeMarkerTemplate.process(container, stringWriter);
        } catch (TemplateException ex) {
            stringWriter = null;
            logger.info("Resolving sender for method " + method + " failed because of exception: ", ex);
        }
        if (stringWriter != null) {
            if (stringWriter.toString().trim().isEmpty()) {
                stringWriter = null;
            }
        }
        if (stringWriter == null) {
            return email;
        } else {
            return stringWriter.toString();
        }
    } else {
        return email;
    }
}
Also used : StringTemplateLoader(cz.metacentrum.perun.notif.StringTemplateLoader) StringWriter(java.io.StringWriter) Matcher(java.util.regex.Matcher) TemplateException(freemarker.template.TemplateException) Template(freemarker.template.Template)

Aggregations

Template (freemarker.template.Template)72 IOException (java.io.IOException)33 StringWriter (java.io.StringWriter)32 Configuration (freemarker.template.Configuration)30 Writer (java.io.Writer)26 HashMap (java.util.HashMap)26 TemplateException (freemarker.template.TemplateException)23 OutputStreamWriter (java.io.OutputStreamWriter)13 File (java.io.File)9 Map (java.util.Map)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 JSONObject (org.json.JSONObject)6 SimpleHash (freemarker.template.SimpleHash)5 ThirdEyeAnomalyConfiguration (com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration)4 StringTemplateLoader (freemarker.cache.StringTemplateLoader)4 Environment (freemarker.core.Environment)4 DefaultObjectWrapper (freemarker.template.DefaultObjectWrapper)4 BufferedWriter (java.io.BufferedWriter)4 FileOutputStream (java.io.FileOutputStream)4 StringReader (java.io.StringReader)4