当前位置: 首页>>代码示例>>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;未经允许,请勿转载。