use of org.apache.sling.scripting.sightly.use.UseProvider in project sling by apache.
the class UseRuntimeExtension method call.
@Override
public Object call(final RenderContext renderContext, Object... arguments) {
ExtensionUtils.checkArgumentCount(RuntimeFunction.USE, arguments, 2);
RuntimeObjectModel runtimeObjectModel = renderContext.getObjectModel();
String identifier = runtimeObjectModel.toString(arguments[0]);
if (StringUtils.isEmpty(identifier)) {
throw new SightlyException("data-sly-use needs to be passed an identifier");
}
Map<String, Object> useArgumentsMap = runtimeObjectModel.toMap(arguments[1]);
Bindings useArguments = new SimpleBindings(Collections.unmodifiableMap(useArgumentsMap));
ArrayList<UseProvider> providers = new ArrayList<>(providersMap.values());
ListIterator<UseProvider> iterator = providers.listIterator(providers.size());
while (iterator.hasPrevious()) {
UseProvider provider = iterator.previous();
ProviderOutcome outcome = provider.provide(identifier, renderContext, useArguments);
Throwable failureCause;
if (outcome.isSuccess()) {
return outcome.getResult();
} else if ((failureCause = outcome.getCause()) != null) {
throw new SightlyException("Identifier " + identifier + " cannot be correctly instantiated by the Use API", failureCause);
}
}
throw new SightlyException("No use provider could resolve identifier " + identifier);
}
Aggregations