當前位置: 首頁>>代碼示例>>Java>>正文


Java FreeMarkerTemplateUtils類代碼示例

本文整理匯總了Java中org.springframework.ui.freemarker.FreeMarkerTemplateUtils的典型用法代碼示例。如果您正苦於以下問題:Java FreeMarkerTemplateUtils類的具體用法?Java FreeMarkerTemplateUtils怎麽用?Java FreeMarkerTemplateUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FreeMarkerTemplateUtils類屬於org.springframework.ui.freemarker包,在下文中一共展示了FreeMarkerTemplateUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: displayTestTemplate

import org.springframework.ui.freemarker.FreeMarkerTemplateUtils; //導入依賴的package包/類
@Override
public String displayTestTemplate(User user) {

    String applicationPropertyUrl = environment.getProperty("spring.application.url");
    String siteName = mailUI.getMessage("mail.site.name");
    String greeting = "YOUSA!";

    Map<String, Object> model = new Hashtable<>();
    model.put("siteName", siteName);
    model.put("greeting", greeting);
    model.put("user", user);
    model.put("applicationPropertyUrl", applicationPropertyUrl);

    String result = null;

    try {
        Template template = fm.getTemplate("tests/test.ftl");
        result = FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
    } catch (IOException | TemplateException e) {
        logger.error("Problem merging test template : " + e.getMessage());
    }
    return result;
}
 
開發者ID:mintster,項目名稱:nixmash-blog,代碼行數:24,代碼來源:FmServiceImpl.java

示例2: getTwitterTemplate

import org.springframework.ui.freemarker.FreeMarkerTemplateUtils; //導入依賴的package包/類
@Override
public  String getTwitterTemplate(PostMeta postMeta) {
    String result = null;
    Map<String, Object> model = new Hashtable<>();

    model.put("postMeta", postMeta);
    String twitterCard = postMeta.getTwitterCardType().name().toLowerCase();
    model.put("twitterCardType", twitterCard);
    try {
        result =  FreeMarkerTemplateUtils
                .processTemplateIntoString(fm.getTemplate("posts/twitter.ftl"), model);
    } catch (IOException | TemplateException e) {
        logger.error("Problem merging Twitter MetaTag template : " + e.getMessage());
    }
    return result;
}
 
開發者ID:mintster,項目名稱:nixmash-blog,代碼行數:17,代碼來源:FmServiceImpl.java

示例3: createRssPostContent

import org.springframework.ui.freemarker.FreeMarkerTemplateUtils; //導入依賴的package包/類
@Override
public String createRssPostContent(Post post) {
    String html = null;

    Map<String, Object> model = new Hashtable<>();

    model.put("post", post);
    model.put("baseurl", applicationSettings.getBaseUrl());

    try {
        Template template = fm.getTemplate("posts/rss_post.ftl");
        html = FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
    } catch (IOException | TemplateException e) {
        logger.error("Problem merging post template : " + e.getMessage());
    }
    return html;
}
 
開發者ID:mintster,項目名稱:nixmash-blog,代碼行數:18,代碼來源:FmServiceImpl.java

示例4: createPostHtml

import org.springframework.ui.freemarker.FreeMarkerTemplateUtils; //導入依賴的package包/類
@Override
public String createPostHtml(Post post, String templateName) {
    String html = null;
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM dd, yyyy");
    String postCreated = post.getPostDate().format(formatter);

    Map<String, Object> model = new Hashtable<>();

    model.put("post", post);
    model.put("postCreated", postCreated);
    model.put("shareSiteName",
            StringUtils.deleteWhitespace(applicationSettings.getSiteName()));
    model.put("shareUrl",
            String.format("%s/post/%s", applicationSettings.getBaseUrl(), post.getPostName()));

    String displayType = templateName == null ? post.getDisplayType().name().toLowerCase() : templateName;
    String ftl = String.format("posts/%s.ftl", displayType);

    try {
        Template template = fm.getTemplate(ftl);
        html = FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
    } catch (IOException | TemplateException e) {
        logger.error("Problem merging post template : " + e.getMessage());
    }
    return html;
}
 
開發者ID:mintster,項目名稱:nixmash-blog,代碼行數:27,代碼來源:FmServiceImpl.java

示例5: createPostAtoZs

import org.springframework.ui.freemarker.FreeMarkerTemplateUtils; //導入依賴的package包/類
@Override
public String createPostAtoZs() {
    String html = null;

    String backToTop = mailUI.getMessage("posts.az.page.backtotop");
    String azFileName = environment.getProperty("posts.az.file.name");
    String azFilePath = applicationSettings.getPostAtoZFilePath();

    Map<String, Object> model = new Hashtable<>();
    model.put("alphaLinks", postService.getAlphaLInks());
    model.put("alphaPosts", postService.getAlphaPosts());
    model.put("backToTop", backToTop);

    try {
        Template template = fm.getTemplate("posts/az.ftl");
        html = FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
        InputStream in = IOUtils.toInputStream(html, "UTF-8");
        FileUtils.copyInputStreamToFile(in, new File(azFilePath + azFileName));
    } catch (IOException | TemplateException e) {
        logger.error("Problem creating A-to-Z template or HTML file: " + e.getMessage());
    }
    return html;
}
 
開發者ID:mintster,項目名稱:nixmash-blog,代碼行數:24,代碼來源:FmServiceImpl.java

示例6: sendEmail

import org.springframework.ui.freemarker.FreeMarkerTemplateUtils; //導入依賴的package包/類
@Async("emailExecutor")
public void sendEmail(EmailVerifyCode code, User user) {
	LOGGER.info("Sending verify email to {} for {}", user.getEmail(), user.getId());
	try {
		mailSender.send(msg -> {
			msg.setFrom(emailSender());
			msg.setRecipients(RecipientType.TO, code.getEmail());
			msg.setSubject(subject());
			msg.setContent(FreeMarkerTemplateUtils.processTemplateIntoString(fmConfig.getTemplate("email/verify-code.ftl"), model(code, user)), "text/html");
		});
	} catch (Throwable e) {
		LOGGER.warn("Couldn't send verify email to {}", user.getEmail(), e);
		return;
	}
	LOGGER.info("Sent verify email to {}", user.getEmail());
}
 
開發者ID:yushijinhun,項目名稱:akir,代碼行數:17,代碼來源:VerifyEmailSender.java

示例7: sendTemplateMail

import org.springframework.ui.freemarker.FreeMarkerTemplateUtils; //導入依賴的package包/類
/**
     * 發送模板郵件
     * 在Spring Boot中也能使用模板引擎來實現模板化的郵件發送。
     * 關於模板郵件,SpringBoot 原本是支持 velocity,
     * 在 1.4 版本後又拋棄了 velocity,暫時隻支持 freemaker。
     *
     * <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-freemarker</artifactId>
     </dependency>
     */
    @Test
    public void sendTemplateMail() {
        MimeMessage message = null;
        try {
            message = mailSender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(message, true);
            helper.setFrom(Sender);
            helper.setTo(Sender);
            helper.setSubject("主題:模板郵件");

            Map<String, Object> model = new HashMap();
            model.put("username", "測試名");

            //修改 application.properties 文件中的讀取路徑
//            FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
//            configurer.setTemplateLoaderPath("classpath:templates");
            //讀取 html 模板
            Template template = freeMarkerConfigurer.getConfiguration().getTemplate("template.ftl");
            String html = FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
            helper.setText(html, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        mailSender.send(message);
    }
 
開發者ID:zhaoshuxue,項目名稱:springBoot,代碼行數:37,代碼來源:UnitTest.java

示例8: sendReplyJoinTeamEmail

import org.springframework.ui.freemarker.FreeMarkerTemplateUtils; //導入依賴的package包/類
private void sendReplyJoinTeamEmail(User user, Team team, TeamStatus status) {
    final Map<String, String> map = new HashMap<>();
    map.put(FIRST_NAME, user.getUserDetails().getFirstName());
    map.put(TEAM_NAME, team.getName());
    map.put("status", status == TeamStatus.APPROVED ? "approved" : "rejected");

    try {
        String[] to = new String[1];
        to[0] = user.getUserDetails().getEmail();
        String msgText = FreeMarkerTemplateUtils.processTemplateIntoString(replyJoinTeamRequestTemplate, map);
        mailService.send(TESTBED_EMAIL, to,
                "Apply To Join Team " + (status == TeamStatus.APPROVED ? "Approved" : "Rejected"),
                msgText, false, null, null);
    } catch (IOException | TemplateException e) {
        log.warn("{}", e);
    }
}
 
開發者ID:nus-ncl,項目名稱:services-in-one,代碼行數:18,代碼來源:RegistrationServiceImpl.java

示例9: sendApplyJoinTeamEmail

import org.springframework.ui.freemarker.FreeMarkerTemplateUtils; //導入依賴的package包/類
private void sendApplyJoinTeamEmail(User requester, User owner, Team team) {
    final Map<String, String> map = new HashMap<>();
    map.put(FIRST_NAME, owner.getUserDetails().getFirstName());
    map.put(TEAM_NAME, team.getName());
    map.put(FULL_NAME, requester.getUserDetails().getFirstName() + " " + requester.getUserDetails().getLastName());
    map.put(EMAIL, requester.getUserDetails().getEmail());
    map.put(PHONE, requester.getUserDetails().getPhone());
    map.put(JOB_TITLE, requester.getUserDetails().getJobTitle());
    map.put(INSTITUTION, requester.getUserDetails().getInstitution());
    map.put(COUNTRY, requester.getUserDetails().getAddress().getCountry());

    try {
        String[] to = new String[1];
        to[0] = owner.getUserDetails().getEmail();
        String msgText = FreeMarkerTemplateUtils.processTemplateIntoString(applyJoinTeamRequestTemplate, map);
        mailService.send(TESTBED_EMAIL, to,
                "Please Process New Request To Join Your Team",
                msgText, false, null, null);
    } catch (IOException | TemplateException e) {
        log.warn("{}", e);
    }
}
 
開發者ID:nus-ncl,項目名稱:services-in-one,代碼行數:23,代碼來源:RegistrationServiceImpl.java

示例10: sendReplyCreateTeamEmail

import org.springframework.ui.freemarker.FreeMarkerTemplateUtils; //導入依賴的package包/類
private void sendReplyCreateTeamEmail(User user, Team team, TeamStatus status, String reason) {
    final Map<String, String> map = new HashMap<>();
    map.put(FIRST_NAME, user.getUserDetails().getFirstName());
    map.put(TEAM_NAME, team.getName());
    map.put("status", status == TeamStatus.APPROVED ? "approved" : "rejected");
    if (reason != null)
        map.put("reason", reason);

    try {
        String[] to = new String[1];
        to[0] = user.getUserDetails().getEmail();
        String[] cc = new String[1];
        cc[0] = ADMIN_EMAIL;
        String msgText = FreeMarkerTemplateUtils.processTemplateIntoString(replyCreateTeamRequestTemplate, map);
        mailService.send(TESTBED_EMAIL, to,
                "Apply To Create New Team " + (status == TeamStatus.APPROVED ? "Approved" : "Rejected"),
                msgText, false, cc, null);
    } catch (IOException | TemplateException e) {
        log.warn("{}", e);
    }
}
 
開發者ID:nus-ncl,項目名稱:services-in-one,代碼行數:22,代碼來源:RegistrationServiceImpl.java

示例11: sendApplyCreateTeamEmail

import org.springframework.ui.freemarker.FreeMarkerTemplateUtils; //導入依賴的package包/類
private void sendApplyCreateTeamEmail(User user, Team team) {
    final Map<String, String> map = new HashMap<>();
    map.put(FIRST_NAME, "NCL Admin");
    map.put(TEAM_NAME, team.getName());
    map.put(FULL_NAME, user.getUserDetails().getFirstName() + " " + user.getUserDetails().getLastName());
    map.put(EMAIL, user.getUserDetails().getEmail());
    map.put(PHONE, user.getUserDetails().getPhone());
    map.put(JOB_TITLE, user.getUserDetails().getJobTitle());
    map.put(INSTITUTION, user.getUserDetails().getInstitution());
    map.put(COUNTRY, user.getUserDetails().getAddress().getCountry());

    try {
        String msgText = FreeMarkerTemplateUtils.processTemplateIntoString(applyCreateTeamRequestTemplate, map);
        mailService.send(TESTBED_EMAIL, ADMIN_EMAIL,
                "Please Process New Request To Create Team", msgText, false, null, null);
    } catch (IOException | TemplateException e) {
        log.warn("{}", e);
    }
}
 
開發者ID:nus-ncl,項目名稱:services-in-one,代碼行數:20,代碼來源:RegistrationServiceImpl.java

示例12: sendVerificationEmail

import org.springframework.ui.freemarker.FreeMarkerTemplateUtils; //導入依賴的package包/類
private void sendVerificationEmail(User user) {
    final Map<String, String> map = new HashMap<>();
    map.put("firstname", user.getUserDetails().getFirstName());
    map.put("domain", domainProperties.getDomain());
    map.put("id", user.getId());
    // email address may contain special characters (e.g. '+') which does not form a valid URI
    map.put("email", Base64.encodeBase64String(user.getUserDetails().getEmail().getBytes()));
    map.put("key", user.getVerificationKey());

    /*
     * If sending email fails, we catch the exceptions and log them,
     * rather than throw the exceptions. Hence, the email will not cause
     * the main application to fail. If users cannot receive emails after
     * a certain amount of time, they should send email to [email protected]
     */
    try {
        String msgText = FreeMarkerTemplateUtils.processTemplateIntoString(
                emailValidationTemplate, map);
        mailService.send(TESTBED_EMAIL, user.getUserDetails().getEmail(),
                "Please Verify Your Email Address", msgText, false, null, null);
        log.debug("Email sent: {}", msgText);
    } catch (IOException | TemplateException e) {
        log.warn("{}", e);
    }

}
 
開發者ID:nus-ncl,項目名稱:services-in-one,代碼行數:27,代碼來源:RegistrationServiceImpl.java

示例13: sendPasswordResetEmail

import org.springframework.ui.freemarker.FreeMarkerTemplateUtils; //導入依賴的package包/類
/**
 *
 * @param username the email address
 * @param key the random string before hash
 */
private void sendPasswordResetEmail(String username, String key) {

    final Map<String, String> map = new HashMap<>();
    map.put("username", username);
    map.put("domain", domainProperties.getDomain());
    map.put("key", key);

    /*
     * If sending email fails, we catch the exceptions and log them,
     * rather than throw the exceptions. Hence, the email will not cause
     * the main application to fail. If users cannot receive emails after
     * a certain amount of time, they should send email to [email protected]
     */
    try {
        String msgText = FreeMarkerTemplateUtils.processTemplateIntoString(
                passwordResetEmailTemplate, map);
        mailService.send("NCL Testbed Ops <[email protected]>", username,
                "Your Request To Reset Password", msgText, false, null, null);
        log.info("Password reset email sent: {}", msgText);
    } catch (IOException | TemplateException e) {
        log.warn("{}", e);
    }
}
 
開發者ID:nus-ncl,項目名稱:services-in-one,代碼行數:29,代碼來源:CredentialsServiceImpl.java

示例14: getContent

import org.springframework.ui.freemarker.FreeMarkerTemplateUtils; //導入依賴的package包/類
/**
 * 返回激活鏈接
 *
 * @param email email
 * @return 有3個參數 email password
 */
public static String getContent(String email, String password, Configuration configuration) {
    Long now = TimeUtil.getNowOfMills();
    Map<String, Object> data = new HashMap<>(10);
    StringBuilder sb = new StringBuilder("http://localhost:8080/user/validate?email=");
    sb.append(email);
    sb.append("&password=");
    sb.append(password);
    sb.append("&time=");
    sb.append(now);
    data.put("email", email);
    data.put("url", sb.toString());
    data.put("now", TimeUtil.getFormatDate(now, TimeUtil.DEFAULT_FORMAT));
    Template template;
    String readyParsedTemplate = null;
    try {
        template = configuration.getTemplate("email.ftl");
        readyParsedTemplate = FreeMarkerTemplateUtils.processTemplateIntoString(template, data);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return readyParsedTemplate;
}
 
開發者ID:xiaomoinfo,項目名稱:SpringBootUnity,代碼行數:29,代碼來源:MailUtil.java

示例15: innerProcess

import org.springframework.ui.freemarker.FreeMarkerTemplateUtils; //導入依賴的package包/類
private String innerProcess(final String template, final Map<String, Object> context, final Locale locale,
		final String filetype) throws TemplateNotFoundException {
	try {
		final String i18nTemplatePath = getI18nHtmlTemplate(locale, template, filetype);
		LOGGER.debug("Try to process template: '{}' with locale: '{}'", i18nTemplatePath,
				locale.getDisplayName(ENGLISH));

		final Template loadedTemplate = templateConfiguration.getTemplate(i18nTemplatePath);

		final Map<String, Object> enrichedContext = enrichtContextWithMessageSource(context, locale);
		return FreeMarkerTemplateUtils.processTemplateIntoString(loadedTemplate, enrichedContext);
	} catch (final TemplateNotFoundException tnfe) {
		// Will be handled by the outer process
		throw tnfe;
	} catch (final IOException | TemplateException e) {
		throw new RuntimeException(e);
	}
}
 
開發者ID:JanLoebel,項目名稱:uaa-service,代碼行數:19,代碼來源:TemplateResolver.java


注:本文中的org.springframework.ui.freemarker.FreeMarkerTemplateUtils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。