Search in sources :

Example 11 with TemplateMode

use of org.thymeleaf.templatemode.TemplateMode in project sling by apache.

the class SlingResourceTemplateResolver method resolveTemplate.

@Override
public TemplateResolution resolveTemplate(final IEngineConfiguration engineConfiguration, final IContext context, final String ownerTemplate, final String template, final Map<String, Object> templateResolutionAttributes) {
    logger.debug("resolving template '{}'", template);
    if (context instanceof SlingContext) {
        final SlingContext slingContext = (SlingContext) context;
        final ResourceResolver resourceResolver = slingContext.getResourceResolver();
        final Resource resource = resourceResolver.getResource(template);
        if (resource == null) {
            logger.warn("resource for template '{}' is null, not resolving template", template);
            return null;
        }
        final ITemplateResource templateResource = new SlingTemplateResource(resource);
        final boolean templateResourceExistenceVerified = false;
        final TemplateMode templateMode = templateModeProvider.provideTemplateMode(resource);
        if (templateMode == null) {
            logger.warn("template mode for template '{}' is null, not resolving template", template);
            return null;
        } else {
            logger.debug("using template mode {} for template '{}'", templateMode, template);
            final boolean useDecoupledLogic = templateMode.isMarkup() && configuration.useDecoupledLogic();
            final ICacheEntryValidity validity = NonCacheableCacheEntryValidity.INSTANCE;
            return new TemplateResolution(templateResource, templateResourceExistenceVerified, templateMode, useDecoupledLogic, validity);
        }
    } else {
        logger.error("context is not an instance of SlingContext");
        return null;
    }
}
Also used : TemplateMode(org.thymeleaf.templatemode.TemplateMode) SlingContext(org.apache.sling.scripting.thymeleaf.SlingContext) TemplateResolution(org.thymeleaf.templateresolver.TemplateResolution) ITemplateResource(org.thymeleaf.templateresource.ITemplateResource) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ITemplateResource(org.thymeleaf.templateresource.ITemplateResource) Resource(org.apache.sling.api.resource.Resource) ICacheEntryValidity(org.thymeleaf.cache.ICacheEntryValidity)

Aggregations

TemplateMode (org.thymeleaf.templatemode.TemplateMode)11 Resource (org.apache.sling.api.resource.Resource)7 SyntheticResource (org.apache.sling.api.resource.SyntheticResource)6 Test (org.junit.Test)6 ICacheEntryValidity (org.thymeleaf.cache.ICacheEntryValidity)3 TemplateCacheKey (org.thymeleaf.cache.TemplateCacheKey)3 ITemplateParser (org.thymeleaf.templateparser.ITemplateParser)3 TemplateResolution (org.thymeleaf.templateresolver.TemplateResolution)3 IEngineContext (org.thymeleaf.context.IEngineContext)2 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 SlingContext (org.apache.sling.scripting.thymeleaf.SlingContext)1 ITemplateResource (org.thymeleaf.templateresource.ITemplateResource)1