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