Java Code Examples for freemarker.template.Configuration#VERSION_2_3_21
The following examples show how to use
freemarker.template.Configuration#VERSION_2_3_21 .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HeaderSampler.java From log-synth with Apache License 2.0 | 6 votes |
private void setupTemplate() throws IOException { Configuration cfg = new Configuration(Configuration.VERSION_2_3_21); cfg.setDefaultEncoding("UTF-8"); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); cfg.setTemplateLoader(new ClassTemplateLoader(getClass(), "/web-headers")); String templateName = "header"; switch (headerType) { case MAL3: templateName = "mal3"; break; case ABABIL: templateName = "ababil"; break; default: break; } template = cfg.getTemplate(templateName); }
Example 2
Source File: JiraContentFormatter.java From incubator-pinot with Apache License 2.0 | 6 votes |
private String buildDescription(String jiraTemplate, Map<String, Object> templateValues) { String description; // Render the values in templateValues map to the jira ftl template file ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (Writer out = new OutputStreamWriter(baos, CHARSET)) { Configuration freemarkerConfig = new Configuration(Configuration.VERSION_2_3_21); freemarkerConfig.setClassForTemplateLoading(getClass(), "/org/apache/pinot/thirdeye/detector"); freemarkerConfig.setDefaultEncoding(CHARSET); freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); Template template = freemarkerConfig.getTemplate(jiraTemplate); template.process(templateValues, out); description = new String(baos.toByteArray(), CHARSET); } catch (Exception e) { description = "Found an exception while constructing the description content. Pls report & reach out" + " to the Thirdeye team. Exception = " + e.getMessage(); } return description; }
Example 3
Source File: DynamicHqlUtils.java From bamboobsc with Apache License 2.0 | 6 votes |
public static String process(String resource, String queryName, Map<String, Object> paramMap) throws Exception { DynamicHql dynamicHql = loadResource(resource); if (null == dynamicHql) { logger.error( "no dynamic hql resource." ); throw new Exception( "no dynamic hql resource." ); } String hql = ""; for (int i=0; i<dynamicHql.getQuery().size() && hql.length()<1; i++) { Query queryObj = dynamicHql.getQuery().get(i); if (!queryObj.getName().equals(queryName)) { continue; } StringTemplateLoader templateLoader = new StringTemplateLoader(); templateLoader.putTemplate(TEMPLATE_ID, queryObj.getContent()); Configuration cfg = new Configuration( Configuration.VERSION_2_3_21 ); cfg.setTemplateLoader(templateLoader); Template template = cfg.getTemplate(TEMPLATE_ID, Constants.BASE_ENCODING); Writer out = new StringWriter(); template.process(paramMap, out); hql = out.toString(); } if (StringUtils.isBlank(hql)) { logger.warn( "hql is blank." ); } return hql; }
Example 4
Source File: Users.java From jeeshop with Apache License 2.0 | 6 votes |
private void sendMail(User user, Mails mailType) { MailTemplate mailTemplate = mailTemplateFinder.findByNameAndLocale(mailType.name(), user.getPreferredLocale()); if (mailTemplate == null) { LOG.debug("Mail template " + mailType + " is not configured."); return; } try { Template mailContentTpl = new Template(mailType.name(), mailTemplate.getContent(), new Configuration(Configuration.VERSION_2_3_21)); final StringWriter mailBody = new StringWriter(); mailContentTpl.process(user, mailBody); mailer.sendMail(mailTemplate.getSubject(), user.getLogin(), mailBody.toString()); } catch (Exception e) { LOG.error("Unable to send mail " + mailType + " to user " + user.getLogin(), e); } return; }
Example 5
Source File: DefaultPaymentTransactionEngine.java From jeeshop with Apache License 2.0 | 6 votes |
protected void sendOrderConfirmationMail(Order order) { User user = order.getUser(); MailTemplate mailTemplate = mailTemplateFinder.findByNameAndLocale(orderValidated.name(), user.getPreferredLocale()); if (mailTemplate == null){ LOG.warn("orderValidated e-mail template does not exist. Configure this missing template to allow user e-mail notification"); return; } try { Template mailContentTpl = new Template(orderValidated.name(), mailTemplate.getContent(), new Configuration(Configuration.VERSION_2_3_21)); final StringWriter mailBody = new StringWriter(); mailContentTpl.process(order, mailBody); mailer.sendMail(mailTemplate.getSubject(), user.getLogin(), mailBody.toString()); } catch (Exception e) { LOG.error("Unable to send mail " + orderValidated + " to user " + user.getLogin(), e); } }
Example 6
Source File: FreeMarkerFormatter.java From ofexport2 with Apache License 2.0 | 6 votes |
public FreeMarkerFormatter(String templateName) throws IOException { // If the resource doesn't exist abort so we can look elsewhere try ( InputStream in = this.getClass().getResourceAsStream(TEMPLATES + "/" + templateName)) { if (in == null) { throw new IOException("Resource not found:" + templateName); } } this.templateName = templateName; Configuration cfg = new Configuration(Configuration.VERSION_2_3_21); TemplateLoader templateLoader = new ClassTemplateLoader(this.getClass(), TEMPLATES); cfg.setTemplateLoader(templateLoader); cfg.setDefaultEncoding("UTF-8"); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); // This is fatal - bomb out of application try { template = cfg.getTemplate(templateName); } catch (IOException e) { throw new IllegalArgumentException(e); } }
Example 7
Source File: Freemarker.java From aws-scala-sdk with Apache License 2.0 | 5 votes |
public Freemarker() { Configuration config = new Configuration(Configuration.VERSION_2_3_21); config.setClassForTemplateLoading(Freemarker.class, "/templates"); config.setDefaultEncoding("UTF-8"); CONFIGURATION = config; }
Example 8
Source File: FreemarkerTemplateService.java From lemon with Apache License 2.0 | 5 votes |
@PostConstruct public void init() throws IOException { configuration = new Configuration(Configuration.VERSION_2_3_21); File templateDir = new File(baseDir); templateDir.mkdirs(); configuration.setDirectoryForTemplateLoading(templateDir); }
Example 9
Source File: Freemarker.java From aws-scala-sdk with Apache License 2.0 | 5 votes |
public Freemarker() { Configuration config = new Configuration(Configuration.VERSION_2_3_21); config.setClassForTemplateLoading(Freemarker.class, "/templates"); config.setDefaultEncoding("UTF-8"); CONFIGURATION = config; }
Example 10
Source File: MailTestCases.java From kaif with Apache License 2.0 | 5 votes |
@Before public void mailSetup() { configuration = new Configuration(Configuration.VERSION_2_3_21); configuration.setDefaultEncoding("UTF-8"); configuration.setTemplateLoader(new ClassTemplateLoader(MailComposer.class, "/mail")); //keep config same as application.yml and WebConfiguration.java messageSource = new ResourceBundleMessageSource(); messageSource.setBasename("i18n/messages"); messageSource.setDefaultEncoding("UTF-8"); messageSource.setFallbackToSystemLocale(false); }
Example 11
Source File: CodeGeneratorUtil.java From bamboobsc with Apache License 2.0 | 5 votes |
private static void generatorProcess(String packageName, String headName, String templateFilePath) throws Exception { Configuration cfg = new Configuration( Configuration.VERSION_2_3_21 ); cfg.setClassForTemplateLoading(CodeGeneratorUtil.class, ""); Template template = cfg.getTemplate(templateFilePath, "utf-8"); Map<String, Object> params = new HashMap<String, Object>(); params.put("packageName", packageName); params.put("headName", headName); params.put("headNameSmall", headName.substring(0, 1).toLowerCase() + headName.substring(1, headName.length())); String outDir = System.getProperty("user.dir") + "/out"; String outFilePath = outDir + "/" + getOutFileFootName(headName, templateFilePath); Writer file = new FileWriter (new File(outFilePath)); template.process(params, file); file.flush(); file.close(); }
Example 12
Source File: ComponentResourceUtils.java From bamboobsc with Apache License 2.0 | 5 votes |
public static String generatorResource(Class<?> c, String type, String metaInfFile, Map<String, Object> params) throws Exception { StringTemplateLoader templateLoader = new StringTemplateLoader(); templateLoader.putTemplate("resourceTemplate", getResourceSrc(c, type, metaInfFile) ); Configuration cfg = new Configuration( Configuration.VERSION_2_3_21 ); cfg.setTemplateLoader(templateLoader); Template template = cfg.getTemplate("resourceTemplate", Constants.BASE_ENCODING); Writer out = new StringWriter(); template.process(params, out); return out.toString(); }
Example 13
Source File: TemplateUtils.java From bamboobsc with Apache License 2.0 | 5 votes |
/** * 單獨提供單處理 template 取出結果 * * @param name * @param classLoader * @param templateResource * @param parameter * @return * @throws Exception */ public static String processTemplate(String name, ClassLoader classLoader, String templateResource, Map<String, Object> parameter) throws Exception { StringTemplateLoader templateLoader = new StringTemplateLoader(); templateLoader.putTemplate("resourceTemplate", getResourceSrc(classLoader, templateResource) ); Configuration cfg = new Configuration( Configuration.VERSION_2_3_21 ); cfg.setTemplateLoader(templateLoader); Template template = cfg.getTemplate("resourceTemplate", Constants.BASE_ENCODING); Writer out = new StringWriter(); template.process(parameter, out); return out.toString(); }
Example 14
Source File: TemplateUtils.java From bamboobsc with Apache License 2.0 | 5 votes |
private static String processTemplate(String resource, Map<String, Object> params) throws Exception { StringTemplateLoader templateLoader = new StringTemplateLoader(); templateLoader.putTemplate("sysTemplate", resource); Configuration cfg = new Configuration( Configuration.VERSION_2_3_21 ); cfg.setTemplateLoader(templateLoader); Template template = cfg.getTemplate("sysTemplate", Constants.BASE_ENCODING); Writer out = new StringWriter(); template.process(params, out); return out.toString(); }
Example 15
Source File: FreeMarkerConfigFactory.java From youran with Apache License 2.0 | 5 votes |
public FreeMarkerConfigFactory() { this.cache = new ConcurrentHashMap<>(); this.beansWrapperBuilder = new BeansWrapperBuilder(Configuration.VERSION_2_3_21); this.beansWrapperBuilder.setExposeFields(true); this.metaConstTypeModel = getStaticModel(MetaConstType.class); this.jFieldTypeModel = getStaticModel(JFieldType.class); this.queryTypeModel = getStaticModel(QueryType.class); this.editTypeModel = getStaticModel(EditType.class); this.metaSpecialFieldModel = getStaticModel(MetaSpecialField.class); this.primaryKeyStrategyModel = getStaticModel(PrimaryKeyStrategy.class); this.commonTemplateFunctionModel = getStaticModel(CommonTemplateFunction.class); this.javaTemplateFunctionModel = getStaticModel(JavaTemplateFunction.class); this.sqlTemplateFunctionModel = getStaticModel(SqlTemplateFunction.class); }
Example 16
Source File: FreemarkerExecutor.java From cantor with BSD 3-Clause "New" or "Revised" License | 4 votes |
public FreemarkerExecutor() { this.configuration = new Configuration(Configuration.VERSION_2_3_21); this.configuration.setClassForTemplateLoading(getClass(), "/"); }
Example 17
Source File: MailTemplates.java From jeeshop with Apache License 2.0 | 4 votes |
private void sendMail(MailTemplate mailTemplate, String recipient, Object properties) throws Exception { Template mailContentTpl = new Template(mailTemplate.getName(), mailTemplate.getContent(), new Configuration(Configuration.VERSION_2_3_21)); final StringWriter mailBody = new StringWriter(); mailContentTpl.process(properties, mailBody); mailer.sendMail(mailTemplate.getSubject(), recipient, mailBody.toString()); }
Example 18
Source File: FreemarkerTemplateEngine.java From pippo with Apache License 2.0 | 4 votes |
@Override public void init(Application application) { super.init(application); Router router = getRouter(); PippoSettings pippoSettings = getPippoSettings(); configuration = new Configuration(Configuration.VERSION_2_3_21); configuration.setDefaultEncoding(PippoConstants.UTF8); configuration.setOutputEncoding(PippoConstants.UTF8); configuration.setLocalizedLookup(true); configuration.setClassForTemplateLoading(FreemarkerTemplateEngine.class, getTemplatePathPrefix()); // We also do not want Freemarker to chose a platform dependent // number formatting. Eg "1000" could be printed out by FTL as "1,000" // on some platforms. // See also: // http://freemarker.sourceforge.net/docs/app_faq.html#faq_number_grouping configuration.setNumberFormat("0.######"); // now it will print 1000000 if (pippoSettings.isDev()) { configuration.setTemplateUpdateDelayMilliseconds(0); // disable cache } else { // never update the templates in production or while testing... configuration.setTemplateUpdateDelayMilliseconds(Integer.MAX_VALUE); // Hold 20 templates as strong references as recommended by: // http://freemarker.sourceforge.net/docs/pgui_config_templateloading.html configuration.setCacheStorage(new freemarker.cache.MruCacheStorage(20, Integer.MAX_VALUE)); } // set global template variables configuration.setSharedVariable("contextPath", new SimpleScalar(router.getContextPath())); configuration.setSharedVariable("appPath", new SimpleScalar(router.getApplicationPath())); webjarResourcesMethod = new WebjarsAtMethod(router); publicResourcesMethod = new PublicAtMethod(router); // allow custom initialization init(application, configuration); }