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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations