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


Java Context類代碼示例

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


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

示例1: renderNonWebAppTemplate

import org.thymeleaf.context.Context; //導入依賴的package包/類
@Test
public void renderNonWebAppTemplate() throws Exception {
	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
			ThymeleafAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	assertThat(context.getBeanNamesForType(ViewResolver.class).length).isEqualTo(0);
	try {
		TemplateEngine engine = context.getBean(TemplateEngine.class);
		Context attrs = new Context(Locale.UK,
				Collections.singletonMap("greeting", "Hello World"));
		String result = engine.process("message", attrs);
		assertThat(result).contains("Hello World");
	}
	finally {
		context.close();
	}
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:18,代碼來源:ThymeleafAutoConfigurationTests.java

示例2: getFutureContributionsFundMandateContentFile

import org.thymeleaf.context.Context; //導入依賴的package包/類
private MandateContentFile getFutureContributionsFundMandateContentFile(
        User user, Mandate mandate, List<Fund> funds, UserPreferences userPreferences) {
    String transactionId = UUID.randomUUID().toString();

    String documentNumber = mandate.getId().toString();

    Context ctx = ContextBuilder.builder()
            .mandate(mandate)
            .user(user)
            .userPreferences(userPreferences)
            .transactionId(transactionId)
            .documentNumber(documentNumber)
            .futureContributionFundIsin(mandate.getFutureContributionFundIsin().orElse(null))
            .funds(funds)
            .build();

    String htmlContent = templateEngine.process("future_contributions_fund", ctx);

    return MandateContentFile.builder()
            .name("valikuavaldus_" + documentNumber + ".html")
            .mimeType("text/html")
            .content(htmlContent.getBytes())
            .build();
}
 
開發者ID:TulevaEE,項目名稱:onboarding-service,代碼行數:25,代碼來源:HtmlMandateContentCreator.java

示例3: getFundTransferMandateContentFile

import org.thymeleaf.context.Context; //導入依賴的package包/類
private MandateContentFile getFundTransferMandateContentFile(
        List<FundTransferExchange> fundTransferExchanges,
        User user, Mandate mandate, List<Fund> funds, UserPreferences userPreferences
) {
    String transactionId = UUID.randomUUID().toString();
    String documentNumber = fundTransferExchanges.get(0).getId().toString();

    Context ctx = ContextBuilder.builder()
            .mandate(mandate)
            .user(user)
            .userPreferences(userPreferences)
            .transactionId(transactionId)
            .documentNumber(documentNumber)
            .fundTransferExchanges(fundTransferExchanges)
            .groupedTransferExchanges(fundTransferExchanges)
            .funds(funds)
            .build();

    String htmlContent = templateEngine.process("fund_transfer", ctx);

    return MandateContentFile.builder()
            .name("vahetuseavaldus_" + documentNumber + ".html")
            .mimeType("text/html")
            .content(htmlContent.getBytes())
            .build();
}
 
開發者ID:TulevaEE,項目名稱:onboarding-service,代碼行數:27,代碼來源:HtmlMandateContentCreator.java

示例4: 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

示例5: notify

import org.thymeleaf.context.Context; //導入依賴的package包/類
@Override
public void notify(SwingValidateContext context, String ... others) {
    final Context ctx = new Context(Locale.SIMPLIFIED_CHINESE);
    ctx.setVariable("context", context);
    ctx.setVariable("pushTime", new Date());
    final String htmlContent = this.templateEngine.process("mail/"+others[0], ctx);
    final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
    final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
    try {
        message.setFrom(EMAIL_FROM);
        message.setTo(others[1]);
        message.setSubject(others[2]);
        message.setText(htmlContent, true);
        this.mailSender.send(mimeMessage);
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
 
開發者ID:Justice-love,項目名稱:stockAnalysis,代碼行數:20,代碼來源:EmailNotifyService.java

示例6: testGuest

import org.thymeleaf.context.Context; //導入依賴的package包/類
@Test
public void testGuest() {
	Subject subjectUnderTest = new Subject.Builder(getSecurityManager()).buildSubject();
	setSubject(subjectUnderTest);


	Context context = new Context();
	String result;

	// Guest user
	result = templateEngine.process(TEST_TEMPL, context);
	assertFalse(result.contains("shiro:"));
	assertTrue(result.contains("GUEST1"));
	assertTrue(result.contains("GUEST2"));

	// Logged in user
	subjectUnderTest.login(new UsernamePasswordToken(USER1, PASS1));
	result = templateEngine.process(TEST_TEMPL, context);
	assertFalse(result.contains("shiro:"));
	assertFalse(result.contains("GUEST1"));
	assertFalse(result.contains("GUEST2"));
	subjectUnderTest.logout();

}
 
開發者ID:usydapeng,項目名稱:thymeleaf3-shiro,代碼行數:25,代碼來源:ShiroDialectTest.java

示例7: testUser

import org.thymeleaf.context.Context; //導入依賴的package包/類
@Test
public void testUser() {
	Subject subjectUnderTest = new Subject.Builder(getSecurityManager()).buildSubject();
	setSubject(subjectUnderTest);

	Context context = new Context();
	String result;

	// Guest user
	result = templateEngine.process(TEST_TEMPL, context);
	assertFalse(result.contains("shiro:"));
	assertFalse(result.contains("USER1"));
	assertFalse(result.contains("USER2"));

	// Logged in user
	subjectUnderTest.login(new UsernamePasswordToken(USER1, PASS1));
	result = templateEngine.process(TEST_TEMPL, context);
	assertFalse(result.contains("shiro:"));
	assertTrue(result.contains("USER1"));
	assertTrue(result.contains("USER2"));
	subjectUnderTest.logout();
}
 
開發者ID:usydapeng,項目名稱:thymeleaf3-shiro,代碼行數:23,代碼來源:ShiroDialectTest.java

示例8: testPrincipal

import org.thymeleaf.context.Context; //導入依賴的package包/類
@Test
public void testPrincipal() {
	Subject subjectUnderTest = new Subject.Builder(getSecurityManager()).buildSubject();
	setSubject(subjectUnderTest);

	Context context = new Context();
	String result;

	// Guest user
	result = templateEngine.process(TEST_TEMPL, context);
	assertNull(subjectUnderTest.getPrincipal()); // sanity
	assertFalse(result.contains("shiro:"));
	assertFalse(result.contains("DEFPRINCIPAL1"));
	assertFalse(result.contains("DEFPRINCIPAL2"));

	// Logged in user
	subjectUnderTest.login(new UsernamePasswordToken(USER1, PASS1));
	assertEquals(USER1, subjectUnderTest.getPrincipal()); // sanity
	result = templateEngine.process(TEST_TEMPL, context);
	assertFalse(result.contains("shiro:"));
	assertTrue(result.contains("DEFPRINCIPAL1<span>" + USER1 + "</span>DEFPRINCIPAL1"));
	assertTrue(result.contains("DEFPRINCIPAL2" + USER1 + "DEFPRINCIPAL2"));
	subjectUnderTest.logout();

}
 
開發者ID:usydapeng,項目名稱:thymeleaf3-shiro,代碼行數:26,代碼來源:ShiroDialectTest.java

示例9: testUserDemo

import org.thymeleaf.context.Context; //導入依賴的package包/類
@Test
public void testUserDemo() {
	Subject subjectUnderTest = new Subject.Builder(getSecurityManager()).buildSubject();
	setSubject(subjectUnderTest);

	Context context = new Context();
	String result;

	// Guest user
	result = templateEngine.process(TEST_TEMPL, context);
	System.out.println(result);

	System.out.println("-------------");

	// Logged in user
	subjectUnderTest.login(new UsernamePasswordToken(USER1, PASS1));
	result = templateEngine.process(TEST_TEMPL, context);
	System.out.println(result);
}
 
開發者ID:usydapeng,項目名稱:thymeleaf3-shiro,代碼行數:20,代碼來源:ShiroDialectTest.java

示例10: 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

示例11: main

import org.thymeleaf.context.Context; //導入依賴的package包/類
public static void main(String[] args) {
    ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver();
    resolver.setTemplateMode("XHTML");
    resolver.setSuffix(".html");
    TemplateEngine engine = new TemplateEngine();
    engine.setTemplateResolver(resolver);


    Context context = new Context(Locale.FRANCE);
    context.setVariable("date", new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime()));
    context.setVariable("contact", new Contact("John", "Doe"));

    List<Contact> contacts = new ArrayList<Contact>();
    contacts.add(new Contact("John","Doe"));
    contacts.add(new Contact("Jane","Doe"));
    context.setVariable("contacts",contacts);

    StringWriter writer = new StringWriter();
    engine.process("org/n3r/sandbox/thymeleaf/home", context, writer);

    System.out.println(writer.toString());
}
 
開發者ID:bingoohuang,項目名稱:javacode-demo,代碼行數:23,代碼來源:ThymeleafDemo.java

示例12: createMailContext

import org.thymeleaf.context.Context; //導入依賴的package包/類
private Context createMailContext(Email mail, boolean isEmail) throws MailSendingException {
    Map<String, Object> model;
    try {
        model = convertValueObjectJsonToMap(mail.getDataJson());
        if(isEmail){
            model.put("emailTemplate",true);
        }
    } catch (Exception ex) {
        String message = String.format("Failed to send mail. Could not deserialize data JSON: %s", mail.getDataJson());
        log.debug(message, ex);
        throw new MailSendingException(message, ex);
    }

    Context context = new Context();
    context.setVariables(model);
    return context;
}
 
開發者ID:mattpwest,項目名稱:entelect-spring-webapp-template,代碼行數:18,代碼來源:MailSenderImpl.java

示例13: sendForgotPasswordEmail

import org.thymeleaf.context.Context; //導入依賴的package包/類
/**
 * <p>sendForgotPasswordEmail.</p>
 *
 * @param email a {@link java.lang.String} object.
 * @param resetPwdURL a {@link java.lang.String} object.
 */
protected void sendForgotPasswordEmail(String email, String resetPwdURL) {
	try {

		// Prepare the evaluation context
		final Context ctx = new Context(Locale.ENGLISH);
		ctx.setVariable("resetPwdURL", resetPwdURL);

		// Create the HTML body using Thymeleaf
		final String htmlContent = this.templateEngine.process("forgot-password-email", ctx);

		emailService.sendEmail(email, getMessage(LABEL_PASSWORD_RESET_EMAIL_SUBJECT), htmlContent);
	} catch (SecuredAppException e) {
		log.error(e.getMessage());
	}
}
 
開發者ID:rajadilipkolli,項目名稱:springsecuredthymeleafapp,代碼行數:22,代碼來源:UserAuthController.java

示例14: 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

示例15: 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


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