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


Java Context.setLocale方法代碼示例

本文整理匯總了Java中org.thymeleaf.context.Context.setLocale方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.setLocale方法的具體用法?Java Context.setLocale怎麽用?Java Context.setLocale使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.thymeleaf.context.Context的用法示例。


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

示例1: getMembershipEmailHtml

import org.thymeleaf.context.Context; //導入方法依賴的package包/類
public String getMembershipEmailHtml(User user) {
    DateTimeFormatter formatter =
            DateTimeFormatter.ISO_LOCAL_DATE
                    .withZone(ZoneId.of("Europe/Tallinn"));
    Member member = user.getMemberOrThrow();
    String memberDate = formatter.format(member.getCreatedDate());

    Context ctx = new Context();
    ctx.setVariable("memberNumber", member.getMemberNumber());
    ctx.setVariable("firstName", user.getFirstName());
    ctx.setVariable("lastName", user.getLastName());
    ctx.setVariable("memberDate", memberDate);
    ctx.setLocale(localeResolver.resolveLocale(request));

    String htmlContent = templateEngine.process("membership", ctx);
    return htmlContent;
}
 
開發者ID:TulevaEE,項目名稱:onboarding-service,代碼行數:18,代碼來源:EmailContentService.java

示例2: sendConfirmationMail

import org.thymeleaf.context.Context; //導入方法依賴的package包/類
@Async
public void sendConfirmationMail(final RegistrationEntity registrationEntity, final Locale locale) {
    try {
        final Context context = new Context();
        context.setLocale(locale);
        context.setVariable("registration", registrationEntity);
        final Writer w = new StringWriter();
        templateEngine.process("registered", context, w);
        final String htmlText = w.toString();
        mailSender.send(mimeMessage -> {
            final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, StandardCharsets.UTF_8.name());
            message.setFrom(mailFrom);
            message.setTo(registrationEntity.getEmail());
            message.setSubject(messageSource.getMessage("registrationConfirmationSubject", new Object[]{registrationEntity.getEvent().getName()}, locale));
            message.setText(htmlTextToPlainText(htmlText), htmlText);

        });
        log.info("Sent confirmation email for '{}' to '{}'.", registrationEntity.getEvent().getName(), registrationEntity.getEmail());
    } catch (MailException e) {
        log.warn("Could not send an email to {} for event '{}': {}", registrationEntity.getEmail(), registrationEntity.getEvent().getName(), e.getMessage());
        log.debug("Full error", e);
    }
}
 
開發者ID:EuregJUG-Maas-Rhine,項目名稱:site,代碼行數:24,代碼來源:RegistrationService.java

示例3: sendEmailWithVerificationLink

import org.thymeleaf.context.Context; //導入方法依賴的package包/類
@Override
public void sendEmailWithVerificationLink(String xForwardedProto, String xForwardedHost, int xForwardedPort, String email, String emailToken, String recipientFullName) {
    Assert.hasText(emailToken, "emailToken must have text");
    Assert.hasText(email, "email must have text");
    Assert.hasText(recipientFullName, "recipientFullName must have text");
    final String fragment = emailSenderProperties.getPpUiVerificationEmailTokenArgName() + "=" + emailToken;

    final String verificationUrl = toPPUIVerificationUri(xForwardedProto, xForwardedHost, xForwardedPort, fragment);
    final Context ctx = new Context();
    ctx.setVariable(PARAM_RECIPIENT_NAME, recipientFullName);
    ctx.setVariable(PARAM_LINK_URL, verificationUrl);
    ctx.setVariable(PARAM_BRAND, emailSenderProperties.getBrand());
    ctx.setLocale(LocaleContextHolder.getLocale());// set locale to support multi-language
    sendEmail(ctx, email,
            PROP_EMAIL_VERIFICATION_LINK_SUBJECT,
            TEMPLATE_VERIFICATION_LINK_EMAIL,
            PROP_EMAIL_FROM_ADDRESS,
            PROP_EMAIL_FROM_PERSONAL,
            LocaleContextHolder.getLocale());
}
 
開發者ID:bhits,項目名稱:patient-user-api,代碼行數:21,代碼來源:EmailSenderImpl.java

示例4: sendEmailToConfirmVerification

import org.thymeleaf.context.Context; //導入方法依賴的package包/類
@Override
public void sendEmailToConfirmVerification(String xForwardedProto, String xForwardedHost, int xForwardedPort, String email, String recipientFullName) {
    Assert.hasText(email, "email must have text");
    Assert.hasText(recipientFullName, "recipientFullName must have text");

    final Context ctx = new Context();
    ctx.setVariable(PARAM_RECIPIENT_NAME, recipientFullName);
    ctx.setVariable(PARAM_LINK_URL, toPPUIBaseUri(xForwardedProto, xForwardedHost, xForwardedPort));
    ctx.setVariable(PARAM_BRAND, emailSenderProperties.getBrand());
    ctx.setLocale(LocaleContextHolder.getLocale());//should set Locale to support Multi-Language
    sendEmail(ctx, email,
            PROP_EMAIL_CONFIRM_VERIFICATION_SUBJECT,
            TEMPLATE_CONFIRM_VERIFICATION_EMAIL,
            PROP_EMAIL_FROM_ADDRESS,
            PROP_EMAIL_FROM_PERSONAL,
            LocaleContextHolder.getLocale());//
}
 
開發者ID:bhits,項目名稱:patient-user-api,代碼行數:18,代碼來源:EmailSenderImpl.java

示例5: sendEmailWithVerificationLinkAndLang

import org.thymeleaf.context.Context; //導入方法依賴的package包/類
@Override
public void sendEmailWithVerificationLinkAndLang(String xForwardedProto, String xForwardedHost, int xForwardedPort, String email, String emailToken, String recipientFullName, String language) {
    Assert.hasText(emailToken, "emailToken must have text");
    Assert.hasText(email, "email must have text");
    Assert.hasText(recipientFullName, "recipientFullName must have text");
    final String fragment = emailSenderProperties.getPpUiVerificationEmailTokenArgName() + "=" + emailToken;

    final String verificationUrl = toPPUIVerificationUri(xForwardedProto, xForwardedHost, xForwardedPort, fragment);
    final Context ctx = new Context();
    ctx.setVariable(PARAM_RECIPIENT_NAME, recipientFullName);
    ctx.setVariable(PARAM_LINK_URL, verificationUrl);
    ctx.setVariable(PARAM_BRAND, emailSenderProperties.getBrand());
    if (language == null || language.trim().isEmpty()) {
        language = "en";
    }
    Locale locale = new Locale(language);
    ctx.setLocale(locale);// set locale to support multi-language
    sendEmail(ctx, email,
            PROP_EMAIL_VERIFICATION_LINK_SUBJECT,
            TEMPLATE_VERIFICATION_LINK_EMAIL,
            PROP_EMAIL_FROM_ADDRESS,
            PROP_EMAIL_FROM_PERSONAL,
            locale);
}
 
開發者ID:bhits,項目名稱:patient-user-api,代碼行數:25,代碼來源:EmailSenderImpl.java

示例6: testThymeleafTemplate

import org.thymeleaf.context.Context; //導入方法依賴的package包/類
@Test
@Ignore
public void testThymeleafTemplate() throws IOException, MessagingException {

    ClassLoaderTemplateResolver templateResolver =
            new ClassLoaderTemplateResolver();

    templateResolver.setTemplateMode(TemplateMode.HTML);
    templateResolver.setPrefix("/templates/");
    templateResolver.setSuffix(".html");
    templateResolver.setCacheTTLMs(Long.valueOf(3600000L));

    templateResolver.setCharacterEncoding("UTF-8");
    templateResolver.setCacheable(true);

    TemplateEngine templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);

    Context ctx = new Context();
    ctx.setLocale(Locale.ENGLISH);
    ctx.setVariable("username", "ricky");
    ctx.setVariable("url", "http://www.thymeleaf.org");
    ctx.setVariable("email", "[email protected]");

    StringWriter sw = new StringWriter(1024);
    templateEngine.process("registry", ctx, sw);

    String output = sw.toString();
    System.out.println(output);

    Mail mail = Mail.newBuilder().from(from,"ricky fung")
            .to(to)
            .subject("測試郵件[模板郵件-Thymeleaf]")
            .html(output)
            .build();

    client.send(mail);
}
 
開發者ID:TFdream,項目名稱:okmail,代碼行數:39,代碼來源:OkMailClientTest.java

示例7: testApp

import org.thymeleaf.context.Context; //導入方法依賴的package包/類
@Test
@Ignore
public void testApp() throws IOException {

    //use thymeleaf
    ClassLoaderTemplateResolver templateResolver =
            new ClassLoaderTemplateResolver();

    templateResolver.setTemplateMode(TemplateMode.HTML);
    templateResolver.setPrefix("/templates/");
    templateResolver.setSuffix(".html");
    templateResolver.setCacheTTLMs(Long.valueOf(3600000L));

    templateResolver.setCharacterEncoding("UTF-8");
    templateResolver.setCacheable(true);

    TemplateEngine templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);

    Context ctx = new Context();
    ctx.setLocale(Locale.ENGLISH);
    ctx.setVariable("username", "ricky");
    ctx.setVariable("url", "http://www.thymeleaf.org");
    ctx.setVariable("email", "[email protected]");

    StringWriter sw = new StringWriter(1024);
    templateEngine.process("registry", ctx, sw);

    String output = sw.toString();
    System.out.println(output);
}
 
開發者ID:TFdream,項目名稱:okmail,代碼行數:32,代碼來源:ThymeleafTest.java

示例8: getMandateEmailHtml

import org.thymeleaf.context.Context; //導入方法依賴的package包/類
public String getMandateEmailHtml() {
    Context ctx = new Context();
    ctx.setLocale(localeResolver.resolveLocale(request));
    String htmlContent = templateEngine.process("mandate", ctx);
    return htmlContent;
}
 
開發者ID:TulevaEE,項目名稱:onboarding-service,代碼行數:7,代碼來源:EmailContentService.java


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