Search in sources :

Example 1 with Environment

use of freemarker.core.Environment 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 2 with Environment

use of freemarker.core.Environment 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 3 with Environment

use of freemarker.core.Environment 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 4 with Environment

use of freemarker.core.Environment 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 5 with Environment

use of freemarker.core.Environment in project perun by CESNET.

the class PerunNotifTemplateManagerImpl method compileTemplate.

private String compileTemplate(final String templateName, Locale locale, Map<String, Object> container) throws IOException, TemplateException {
    class NotificationTemplateExceptionHandler implements TemplateExceptionHandler {

        @Override
        public void handleTemplateException(TemplateException te, Environment env, java.io.Writer out) throws TemplateException {
            if (te instanceof InvalidReferenceException) {
                // skip undefined values
                logger.info("Undefined value found in the TemplateMessage " + templateName + ".", te);
            } else {
                throw te;
            }
        }
    }
    this.configuration.setTemplateExceptionHandler(new NotificationTemplateExceptionHandler());
    StringWriter stringWriter = new StringWriter(4096);
    Template freeMarkerTemplate = null;
    try {
        freeMarkerTemplate = this.configuration.getTemplate(templateName + "_" + locale.getLanguage(), locale);
    } catch (FileNotFoundException ex) {
        if (!(locale.equals(DEFAULT_LOCALE))) {
            // if we do not know the language, try to send it at least in default locale
            freeMarkerTemplate = this.configuration.getTemplate(templateName + "_" + DEFAULT_LOCALE.getLanguage(), DEFAULT_LOCALE);
            logger.info("There is no message with template " + templateName + " in locale " + locale.getLanguage() + ", therefore the message will be sent in " + DEFAULT_LOCALE.getLanguage() + " locale.");
        } else {
            throw ex;
        }
    }
    freeMarkerTemplate.process(container, stringWriter);
    return stringWriter.toString();
}
Also used : StringWriter(java.io.StringWriter) TemplateException(freemarker.template.TemplateException) FileNotFoundException(java.io.FileNotFoundException) Environment(freemarker.core.Environment) TemplateExceptionHandler(freemarker.template.TemplateExceptionHandler) StringWriter(java.io.StringWriter) InvalidReferenceException(freemarker.core.InvalidReferenceException) Template(freemarker.template.Template)

Aggregations

Environment (freemarker.core.Environment)5 Template (freemarker.template.Template)5 Configuration (freemarker.template.Configuration)3 DefaultObjectWrapper (freemarker.template.DefaultObjectWrapper)3 InvalidReferenceException (freemarker.core.InvalidReferenceException)1 TemplateException (freemarker.template.TemplateException)1 TemplateExceptionHandler (freemarker.template.TemplateExceptionHandler)1 FileNotFoundException (java.io.FileNotFoundException)1 StringWriter (java.io.StringWriter)1 ExmlcException (net.jangaroo.exml.api.ExmlcException)1 ExmlConfiguration (net.jangaroo.exml.config.ExmlConfiguration)1