public IEngineContext createEngineContext(
final IEngineConfiguration configuration, final TemplateData templateData,
final Map<String, Object> templateResolutionAttributes, final IContext context) {
Validate.notNull(context, "Context object cannot be null");
final Set<String> variableNames = context.getVariableNames();
if (variableNames == null || variableNames.isEmpty()) {
if (context instanceof ISpringWebFluxContext) {
final ISpringWebFluxContext srContext = (ISpringWebFluxContext)context;
return new SpringWebFluxEngineContext(
configuration, templateData, templateResolutionAttributes,
srContext.getExchange(), srContext.getLocale(), Collections.EMPTY_MAP);
}
return new EngineContext(
configuration, templateData, templateResolutionAttributes,
context.getLocale(), Collections.EMPTY_MAP);
}
final Map<String,Object> variables = new LinkedHashMap<>(variableNames.size() + 1, 1.0f);
for (final String variableName : variableNames) {
variables.put(variableName, context.getVariable(variableName));
}
if (context instanceof ISpringWebFluxContext) {
final ISpringWebFluxContext srContext = (ISpringWebFluxContext)context;
return new SpringWebFluxEngineContext(
configuration, templateData, templateResolutionAttributes,
srContext.getExchange(), srContext.getLocale(), variables);
}
return new EngineContext(
configuration, templateData, templateResolutionAttributes,
context.getLocale(), variables);
}