Package org.thymeleaf.templateresolver

Examples of org.thymeleaf.templateresolver.TemplateResolution


        final String templateName = templateProcessingParameters.getTemplateName();
        final String resourceName = templateName; // TODO
        final String characterEncoding = encoding;
        final String templateMode = computeTemplateMode(templateName);
        final ITemplateResolutionValidity validity = new NonCacheableTemplateResolutionValidity();
        return new TemplateResolution(templateName, resourceName, resourceResolver, characterEncoding, templateMode, validity);
    }
View Full Code Here


        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());

        templateEngine.initialize();
       
        final TemplateRepository templateRepository = templateEngine.getTemplateRepository();
View Full Code Here

            final IFragmentSpec fragmentSpec, final Writer writer) {
       
        final String templateName = templateProcessingParameters.getTemplateName();
       
        final Template template = this.templateRepository.getTemplate(templateProcessingParameters);
        final TemplateResolution templateResolution = template.getTemplateResolution();
        final String templateMode = templateResolution.getTemplateMode();

        Document document = template.getDocument();

        if (fragmentSpec != null) {
View Full Code Here

            }
        }
       
        final Configuration configuration = templateProcessingParameters.getConfiguration();
        final Set<ITemplateResolver> templateResolvers = configuration.getTemplateResolvers();
        TemplateResolution templateResolution = null;
        InputStream templateInputStream = null;
       
        for (final ITemplateResolver templateResolver : templateResolvers) {
               
                templateResolution = templateResolver.resolveTemplate(templateProcessingParameters);
               
                if (templateResolution != null) {
                   
                    final String resourceName = templateResolution.getResourceName();

                    final IResourceResolver resourceResolver = templateResolution.getResourceResolver();
                   
                    if (logger.isTraceEnabled()) {
                        logger.trace("[THYMELEAF][{}] Trying to resolve template \"{}\" as resource \"{}\" with resource resolver \"{}\"", new Object[] {TemplateEngine.threadIndex(), templateName, resourceName, resourceResolver.getName()});
                    }
                   
                    templateInputStream =
                        resourceResolver.getResourceAsStream(templateProcessingParameters, resourceName);
                   
                    if (templateInputStream == null) {
                        if (logger.isTraceEnabled()) {
                            logger.trace("[THYMELEAF][{}] Template \"{}\" could not be resolved as resource \"{}\" with resource resolver \"{}\"", new Object[] {TemplateEngine.threadIndex(), templateName, resourceName, resourceResolver.getName()});
                        }
                    } else {
                        if (logger.isDebugEnabled()) {
                            logger.debug("[THYMELEAF][{}] Template \"{}\" was correctly resolved as resource \"{}\" in mode {} with resource resolver \"{}\"", new Object[] {TemplateEngine.threadIndex(), templateName, resourceName, templateResolution.getTemplateMode(), resourceResolver.getName()});
                        }
                        break;
                    }
                   
                } else {
                   
                    if (logger.isTraceEnabled()) {
                        logger.trace("[THYMELEAF][{}] Skipping template resolver \"{}\" for template \"{}\"", new Object[] {TemplateEngine.threadIndex(), templateResolver.getName(), templateName});
                    }
                   
                }
           
        }
       
        if (templateResolution == null || templateInputStream == null) {
            throw new TemplateInputException(
                    "Error resolving template \"" + templateProcessingParameters.getTemplateName() + "\", " +
                    "template might not exist or might not be accessible by " +
                    "any of the configured Template Resolvers");
        }

       
        final String templateMode = templateResolution.getTemplateMode();
       
        final ITemplateParser templateParser = this.parsersByTemplateMode.get(templateMode);
        if (templateParser == null) {
            throw new TemplateInputException(
                    "Template mode \"" + templateMode + "\" has not been configured");
        }
       
        if (logger.isTraceEnabled()) {
            logger.trace("[THYMELEAF][{}] Starting parsing of template \"{}\"", TemplateEngine.threadIndex(), templateName);
        }
       
       
        final String characterEncoding = templateResolution.getCharacterEncoding();
        Reader reader = null;
        if (!StringUtils.isEmptyOrWhitespace(characterEncoding)) {
            try {
                reader = new InputStreamReader(templateInputStream, characterEncoding);
            } catch (final UnsupportedEncodingException e) {
                throw new TemplateInputException("Exception parsing document", e);
            }
        } else {
            reader = new InputStreamReader(templateInputStream);
        }
       
        final Document document =
                templateParser.parseTemplate(configuration, templateName, reader);
       
        if (logger.isTraceEnabled()) {
            logger.trace("[THYMELEAF][{}] Finished parsing of template \"{}\"", TemplateEngine.threadIndex(), templateName);
        }

        document.precompute(configuration);
       
        final Template template =
            new Template(templateName, templateResolution, document);

        if (this.templateCache != null) {
            if (templateResolution.getValidity().isCacheable()) {
                this.templateCache.put(templateName, template);
                return template.createDuplicate();
            }
        }
       
View Full Code Here

        String templateName = "CustomTemplate";
        String resourceName = "CustomResource";
        IResourceResolver resourceResolver = new FixedMemoryResourceResolver(templateContent);
        String characterEncoding = "utf-8";
        ITemplateResolutionValidity validity = new NonCacheableTemplateResolutionValidity();
        return new TemplateResolution(templateName, resourceName, resourceResolver, characterEncoding, templateMode, validity);
    }
View Full Code Here

TOP

Related Classes of org.thymeleaf.templateresolver.TemplateResolution

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.