Search in sources :

Example 6 with RuntimeObjectModel

use of org.apache.sling.scripting.sightly.render.RuntimeObjectModel in project sling by apache.

the class I18nRuntimeExtension method call.

@Override
public Object call(final RenderContext renderContext, Object... arguments) {
    ExtensionUtils.checkArgumentCount(RuntimeFunction.I18N, arguments, 2);
    RuntimeObjectModel runtimeObjectModel = renderContext.getObjectModel();
    String text = runtimeObjectModel.toString(arguments[0]);
    Map<String, Object> options = (Map<String, Object>) arguments[1];
    String locale = runtimeObjectModel.toString(options.get("locale"));
    String hint = runtimeObjectModel.toString(options.get("hint"));
    String basename = runtimeObjectModel.toString(options.get("basename"));
    final Bindings bindings = renderContext.getBindings();
    return get(bindings, text, locale, basename, hint);
}
Also used : RuntimeObjectModel(org.apache.sling.scripting.sightly.render.RuntimeObjectModel) Map(java.util.Map) Bindings(javax.script.Bindings)

Example 7 with RuntimeObjectModel

use of org.apache.sling.scripting.sightly.render.RuntimeObjectModel in project sling by apache.

the class IncludeRuntimeExtension method call.

@Override
public Object call(final RenderContext renderContext, Object... arguments) {
    ExtensionUtils.checkArgumentCount(RuntimeFunction.INCLUDE, arguments, 2);
    RuntimeObjectModel runtimeObjectModel = renderContext.getObjectModel();
    String originalPath = runtimeObjectModel.toString(arguments[0]);
    Map options = (Map) arguments[1];
    String path = buildPath(originalPath, options);
    StringWriter output = new StringWriter();
    final Bindings bindings = renderContext.getBindings();
    SlingHttpServletRequest request = BindingsUtils.getRequest(bindings);
    Map originalAttributes = ExtensionUtils.setRequestAttributes(request, (Map) options.remove(OPTION_REQUEST_ATTRIBUTES));
    includeScript(bindings, path, new PrintWriter(output));
    ExtensionUtils.setRequestAttributes(request, originalAttributes);
    return output.toString();
}
Also used : StringWriter(java.io.StringWriter) RuntimeObjectModel(org.apache.sling.scripting.sightly.render.RuntimeObjectModel) Map(java.util.Map) Bindings(javax.script.Bindings) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) PrintWriter(java.io.PrintWriter)

Aggregations

RuntimeObjectModel (org.apache.sling.scripting.sightly.render.RuntimeObjectModel)7 Map (java.util.Map)5 Bindings (javax.script.Bindings)4 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Locale (java.util.Locale)1 TimeZone (java.util.TimeZone)1 SimpleBindings (javax.script.SimpleBindings)1 Resource (org.apache.sling.api.resource.Resource)1 SyntheticResource (org.apache.sling.api.resource.SyntheticResource)1 SightlyException (org.apache.sling.scripting.sightly.SightlyException)1 ProviderOutcome (org.apache.sling.scripting.sightly.use.ProviderOutcome)1 UseProvider (org.apache.sling.scripting.sightly.use.UseProvider)1