Package org.thymeleaf.context

Examples of org.thymeleaf.context.Context


    /**
     * {@inheritDoc}
     */
    @Override
    public void execute(ActionContext actionContext) throws Exception {
        Context ctx = new Context();
        if (object != null) {
            ctx.setVariable("context", object);
        } else {
            ctx.setVariable("context", new HashMap<String, String>());
        }
        String result = engine.process(path, ctx);
        actionContext.addResponseHeader("Content-Type", contentType);
        actionContext.sendResponseHeaders(200, result.getBytes().length + 2);
        // actionContext.sendResponseHeaders(200, 0);
View Full Code Here


    }

    @Test
    public void simple()
    {
        IContext context = new Context();
        context.getVariables().put("titulo", "Mi título en la plantilla");

        String result = templateEngine.process("simple", context);

        assertTrue(result.contains("<h1>Mi título en la plantilla</h1>"));
    }
View Full Code Here

    public void bean()
    {
        Dato dato = new Dato();
        dato.setTitulo("Mi título en la plantilla");

        IContext context = new Context();
        context.getVariables().put("dato", dato);

        String result = templateEngine.process("bean", context);

        assertTrue(result.contains("<h1>Mi título en la plantilla</h1>"));
    }
View Full Code Here

    }

    @Test
    public void simpleMultilang()
    {
        String result = templateEngine.process("simple_multilang", new Context(new Locale("en")));
        assertTrue(result.contains("<h1>Wellcome to Genbeta Dev web!!</h1>"));

        result = templateEngine.process("simple_multilang", new Context());
        assertTrue(result.contains("<h1>Bienvenido a la web de Genbeta Dev!!</h1>"));
    }
View Full Code Here

    {
        Producto producto = new Producto();
        producto.setId(1);
        producto.setNombre("Producto 1");

        IContext context = new Context();
        context.getVariables().put("productos", Collections.singletonList(producto));

        String result = templateEngine.process("colecciones", context);
        System.out.println(result);
        assertTrue(result.contains("<td>Producto 1</td>"));
    }
View Full Code Here

        templateEngine.setTemplateModeHandlers(StandardTemplateModeHandlers.ALL_TEMPLATE_MODE_HANDLERS);
       
        final String templateName = "output";

        final TemplateProcessingParameters templateProcessingParameters =
                new TemplateProcessingParameters(templateEngine.getConfiguration(), templateName, new Context());
       
        final TemplateResolution templateResolution =
                new TemplateResolution(templateName, "resource:"+templateName,
                        new ClassLoaderResourceResolver(), "UTF-8", templateMode, new AlwaysValidTemplateResolutionValidity());
View Full Code Here

    @Override
    public String buildMessageBody(EmailInfo info, Map<String,Object> props) {
        BroadleafRequestContext blcContext = BroadleafRequestContext.getBroadleafRequestContext();
       
        final Context thymeleafContext = new Context();
        if (blcContext != null && blcContext.getJavaLocale() != null) {
            thymeleafContext.setLocale(blcContext.getJavaLocale());            
        }          
       
        if (props != null) {
            Iterator<String> propsIterator = props.keySet().iterator();
            while(propsIterator.hasNext()) {
                String key = propsIterator.next();
                thymeleafContext.setVariable(key, props.get(key));
            }
        }
       
        return this.templateEngine.process( info.getEmailTemplate(), thymeleafContext);
    }
View Full Code Here

                if (domainUserRequest != null) {
                    DomainEntityService domainEntityService = domainEntityServiceFactory.getDomainEntityService(domainUserRequest.getDomain().getDomainType());
                    Set<User> users = domainEntityService.getDomainRequestUsersForNotification(domainUserRequest.getDomain());

                    for (User user : users) {
                        Context ctx = new Context(locale);
                        ctx.setVariable("name", user.getFullName());
                        ctx.setVariable("request", domainUserRequest);

                        ctx.setVariable("url", request.generateURL("/manager"));
                        if(domainUserRequest.getDomain().getDomainType().equals(DomainType.ORGANIZATION)) {
                            applyBranding((Organization)domainUserRequest.getDomain(), ctx);
                        }

                        // Create the HTML body using Thymeleaf
View Full Code Here

                Locale locale = LocaleContextHolder.getLocale();

                message.setFrom(fromAddress);

                if (user != null && !user.isActivated()) {
                    Context ctx = new Context(locale);
                    ctx.setVariable("name", user.getFullName());
                    ctx.setVariable("activationCode", user.getActivationCode());
                    ctx.setVariable("organizationName", organizationName);

                    String servletPath = "/activate/" + user.getActivationCode();
                    ctx.setVariable("url", request.generateURL(servletPath));
                    applyBranding(organization, ctx);

                    // Create the HTML body using Thymeleaf
                    final String htmlContent = this.templateEngine.process("email-accountActivationTH", ctx);
                    message.setText(htmlContent, true /* isHtml */);
 
View Full Code Here

                Locale locale = LocaleContextHolder.getLocale();

                message.setFrom(fromAddress);

                if (user != null && user.isActivated()) {
                    Context ctx = new Context(locale);
                    ctx.setVariable("name", user.getFullName());
                    ctx.setVariable("organizationName", organizationName);
                    String servletPath = "/";
                    ctx.setVariable("url", request.generateURL(servletPath));
                    applyBranding(organization, ctx);

                    final String htmlContent = this.templateEngine.process("email-accountActivationSuccessTH", ctx);
                    message.setText(htmlContent, true);
                    message.setTo(user.getEmail());
View Full Code Here

TOP

Related Classes of org.thymeleaf.context.Context

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.