@Test public void compose() throws Exception { String templateFile = "/mail-composer-test.ftl"; ImmutableMap<String, Object> model = ImmutableMap.of("foo", "1", "bar", "2"); String composed = composer.compose(Locale.TAIWAN, templateFile, model); assertEquals("測試中\n" + "foo:1\n" + "bar:2", composed); composed = composer.compose(Locale.ENGLISH, templateFile, model); assertEquals("testing\n" + "foo:1\n" + "bar:2", composed); }
public String compose(Locale locale, String templateFile, Map<String, Object> model) throws MailException { try { Template template = configuration.getTemplate(templateFile, locale); StringWriter writer = new StringWriter(); Map<String, Object> i18nModel = createI18nModel(locale); i18nModel.putAll(model); template.process(i18nModel, writer); writer.flush(); return writer.toString(); } catch (IOException e) { throw new MailParseException("unexpect IO error", e); } catch (TemplateException e) { throw new MailParseException("template error", e); } }
MailComposer { public String compose(Locale locale, String templateFile, Map<String, Object> model) throws MailException { try { Template template = configuration.getTemplate(templateFile, locale); StringWriter writer = new StringWriter(); Map<String, Object> i18nModel = createI18nModel(locale); i18nModel.putAll(model); template.process(i18nModel, writer); writer.flush(); return writer.toString(); } catch (IOException e) { throw new MailParseException("unexpect IO error", e); } catch (TemplateException e) { throw new MailParseException("template error", e); } } }
MailComposer { public String compose(Locale locale, String templateFile, Map<String, Object> model) throws MailException { try { Template template = configuration.getTemplate(templateFile, locale); StringWriter writer = new StringWriter(); Map<String, Object> i18nModel = createI18nModel(locale); i18nModel.putAll(model); template.process(i18nModel, writer); writer.flush(); return writer.toString(); } catch (IOException e) { throw new MailParseException("unexpect IO error", e); } catch (TemplateException e) { throw new MailParseException("template error", e); } } MailComposer(); @VisibleForTesting  MailComposer(MessageSource messageSource,
      Configuration configuration,
      MailProperties mailProperties); }
MailComposer { public String compose(Locale locale, String templateFile, Map<String, Object> model) throws MailException { try { Template template = configuration.getTemplate(templateFile, locale); StringWriter writer = new StringWriter(); Map<String, Object> i18nModel = createI18nModel(locale); i18nModel.putAll(model); template.process(i18nModel, writer); writer.flush(); return writer.toString(); } catch (IOException e) { throw new MailParseException("unexpect IO error", e); } catch (TemplateException e) { throw new MailParseException("template error", e); } } MailComposer(); @VisibleForTesting  MailComposer(MessageSource messageSource,
      Configuration configuration,
      MailProperties mailProperties); Mail createMail(); String i18n(Locale locale, String key, Object... args); String compose(Locale locale, String templateFile, Map<String, Object> model); }
MailComposer { public String compose(Locale locale, String templateFile, Map<String, Object> model) throws MailException { try { Template template = configuration.getTemplate(templateFile, locale); StringWriter writer = new StringWriter(); Map<String, Object> i18nModel = createI18nModel(locale); i18nModel.putAll(model); template.process(i18nModel, writer); writer.flush(); return writer.toString(); } catch (IOException e) { throw new MailParseException("unexpect IO error", e); } catch (TemplateException e) { throw new MailParseException("template error", e); } } MailComposer(); @VisibleForTesting  MailComposer(MessageSource messageSource,
      Configuration configuration,
      MailProperties mailProperties); Mail createMail(); String i18n(Locale locale, String key, Object... args); String compose(Locale locale, String templateFile, Map<String, Object> model);  }