Examples of SlingScriptHelper


Examples of org.apache.sling.api.scripting.SlingScriptHelper

  public Object eval(Reader script, ScriptContext scriptContext)
      throws ScriptException {
    Bindings bindings = scriptContext
        .getBindings(ScriptContext.ENGINE_SCOPE);

    SlingScriptHelper helper = (SlingScriptHelper) bindings
        .get(SlingBindings.SLING);
    if (helper == null) {
      throw new ScriptException("SlingScriptHelper missing from bindings");
    }

    // ensure GET request
    if (helper.getRequest() != null && !"GET".equals(helper.getRequest().getMethod())) {
      throw new ScriptException(
          "Python scripting only supports GET requests");
    }

    final ClassLoader oldClassLoader = Thread.currentThread()
View Full Code Here

Examples of org.apache.sling.api.scripting.SlingScriptHelper

         * @see javax.script.ScriptEngine#eval(java.io.Reader, javax.script.ScriptContext)
         */
        public Object eval(Reader script, ScriptContext context)
        throws ScriptException {
            final Bindings props = context.getBindings(ScriptContext.ENGINE_SCOPE);
            final SlingScriptHelper scriptHelper = (SlingScriptHelper) props.get(SLING);
            if (scriptHelper != null) {
                ((JavaScriptEngineFactory)this.getFactory()).callServlet(props, scriptHelper, context);
            }
            return null;
        }
View Full Code Here

Examples of org.apache.sling.api.scripting.SlingScriptHelper

@Service
public class SlingScriptInfo extends AbstractScriptInfo {

    @Override
    public String getScriptClass(String script, ScriptContext context) throws ScriptException {
        SlingScriptHelper scriptHelper = getScriptHelper(context);

        String path = getRelativePath(scriptHelper.getScript().getScriptResource());
        if (path.endsWith(".scala")) {
            path = path.substring(0, path.length() - 6);
        }

        String[] parts = path.split("/");
View Full Code Here

Examples of org.apache.sling.api.scripting.SlingScriptHelper

    @SuppressWarnings("unchecked")
    private static SlingScriptHelper getScriptHelper(ScriptContext context) throws ScriptException {
        SlingBindings bindings = new SlingBindings();
        bindings.putAll(context.getBindings(ScriptContext.ENGINE_SCOPE));
        SlingScriptHelper scriptHelper = bindings.getSling();
        if (scriptHelper == null) {
            throw new ScriptException("Error retrieving Sling script helper from script context");
        }
        return scriptHelper;
    }
View Full Code Here

Examples of org.apache.sling.api.scripting.SlingScriptHelper

    super(factory);
  }

  public Object eval(Reader reader, ScriptContext scriptContext) throws ScriptException {
    Bindings bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
    SlingScriptHelper helper = (SlingScriptHelper) bindings.get(SlingBindings.SLING);
    if (helper == null) {
      throw new ScriptException("SlingScriptHelper missing from bindings");
    }
   
    String scriptName = helper.getScript().getScriptResource().getPath();
   
    try {
      XplBuilder xplBuilder = new XplBuilder();
      Pipeline xpl = (Pipeline) xplBuilder.build(reader);
      xpl.getEnv().setSling(helper);
View Full Code Here

Examples of org.apache.sling.api.scripting.SlingScriptHelper

    }

    public Object eval(Reader reader, ScriptContext scriptContext)
            throws ScriptException {
        Bindings bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
        SlingScriptHelper helper = (SlingScriptHelper) bindings.get(SlingBindings.SLING);
        if (helper == null) {
            throw new ScriptException("SlingScriptHelper missing from bindings");
        }

        // ensure GET request
        if (!"GET".equals(helper.getRequest().getMethod())) {
            throw new ScriptException(
                "FreeMarker templates only support GET requests");
        }

        String scriptName = helper.getScript().getScriptResource().getPath();

        try {
            Template tmpl = new Template(scriptName, reader, configuration);
            bindings.put("currentNode", new NodeModel((Node) bindings.get("currentNode")));
            tmpl.process(bindings, scriptContext.getWriter());
View Full Code Here

Examples of org.apache.sling.api.scripting.SlingScriptHelper

    }

    @Override
    public Object eval(final Reader reader, final ScriptContext scriptContext) throws ScriptException {
        final Bindings bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
        final SlingScriptHelper helper = (SlingScriptHelper) bindings.get(SlingBindings.SLING);

        if (helper == null) {
            throw new ScriptException("SlingScriptHelper missing from bindings");
        }

        final SlingHttpServletRequest request = helper.getRequest();
        final SlingHttpServletResponse response = helper.getResponse();
        final ServletContext servletContext = null; // only used by Thymeleaf's ServletContextResourceResolver

        final Locale locale = helper.getResponse().getLocale();
        final String scriptName = helper.getScript().getScriptResource().getPath();

        try {
            final IContext context = new SlingWebContext(request, response, servletContext, locale, bindings);
            thymeleafScriptEngineFactory.getTemplateEngine().process(scriptName, context, scriptContext.getWriter());
        } catch (Exception e) {
View Full Code Here

Examples of org.apache.sling.api.scripting.SlingScriptHelper

    public Object eval(Reader scriptReader, ScriptContext scriptContext)
            throws ScriptException {
        Bindings bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
        String scriptName = "NO_SCRIPT_NAME";
        {
            SlingScriptHelper helper = (SlingScriptHelper) bindings.get(SlingBindings.SLING);
            if(helper != null) {
                scriptName = helper.getScript().getScriptResource().getPath();
            }
        }

        // wrap the reader in an EspReader for ESP scripts
        if (scriptName.endsWith(RhinoJavaScriptEngineFactory.ESP_SCRIPT_EXTENSION)) {
View Full Code Here

Examples of org.apache.sling.api.scripting.SlingScriptHelper

        }

        public Object eval(Reader script, ScriptContext context)
                throws ScriptException {
            Bindings props = context.getBindings(ScriptContext.ENGINE_SCOPE);
            SlingScriptHelper scriptHelper = (SlingScriptHelper) props.get(SLING);
            if (scriptHelper != null) {
                try {
                    callJsp(props, scriptHelper);
                } catch (Exception e) {
                    throw new ScriptException(e);
View Full Code Here

Examples of org.apache.sling.api.scripting.SlingScriptHelper

        getLogger(cx, thisObj).info(message.toString());
    }

    private void load(Context cx, Scriptable thisObj, Object[] args) {

        SlingScriptHelper sling = getProperty(cx, thisObj, SlingBindings.SLING,
            SlingScriptHelper.class);
        if (sling == null) {
            throw new NullPointerException(SlingBindings.SLING);
        }

        Scriptable globalScope = ScriptableObject.getTopLevelScope(thisObj);

        Resource scriptResource = sling.getScript().getScriptResource();
        ResourceResolver resolver = scriptResource.getResourceResolver();

        // the path of the current script to resolve realtive paths
        String currentScript = sling.getScript().getScriptResource().getPath();
        String scriptParent = ResourceUtil.getParent(currentScript);

        for (Object arg : args) {
            String scriptName = ScriptRuntime.toString(arg);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.