use of org.apache.sling.scripting.thymeleaf.SlingContext in project sling by apache.
the class SlingEngineContextFactory method createEngineContext.
@Override
public IEngineContext createEngineContext(final IEngineConfiguration configuration, final TemplateData templateData, final Map<String, Object> templateResolutionAttributes, final IContext context) {
if (context instanceof SlingContext) {
// TODO web context
final SlingContext slingContext = (SlingContext) context;
final ResourceResolver resourceResolver = slingContext.getResourceResolver();
final Locale locale = context.getLocale();
final Set<String> variableNames = context.getVariableNames();
final Map<String, Object> variables = new LinkedHashMap<>(variableNames.size() + 1, 1.0f);
for (final String variableName : variableNames) {
variables.put(variableName, context.getVariable(variableName));
}
return new SlingEngineContext(resourceResolver, configuration, templateData, templateResolutionAttributes, locale, variables);
} else {
throw new IllegalStateException("context is not an instance of SlingContext");
}
}
use of org.apache.sling.scripting.thymeleaf.SlingContext 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;
}
}
Aggregations