Package org.apache.sling.api.scripting

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


     */
    public SlingScript findScript(final ResourceResolver resourceResolver, final String name)
    throws SlingException {

        // is the path absolute
        SlingScript script = null;
        if (name.startsWith("/")) {

            final String path = ResourceUtil.normalize(name);
            if ( this.isPathAllowed(path) ) {
                final Resource resource = resourceResolver.getResource(path);
                if ( resource != null ) {
                    script = resource.adaptTo(SlingScript.class);
                }
            }
        } else {

            // relative script resolution against search path
            final String[] path = resourceResolver.getSearchPath();
            for (int i = 0; script == null && i < path.length; i++) {
                final String scriptPath = ResourceUtil.normalize(path[i] + name);
                if ( this.isPathAllowed(scriptPath) ) {
                    final Resource resource = resourceResolver.getResource(scriptPath);
                    if (resource != null) {
                        script = resource.adaptTo(SlingScript.class);
                    }
                }
            }

        }

        // some logging
        if (script != null) {
            LOGGER.debug("findScript: Using script {} for {}", script.getScriptResource().getPath(), name);
        } else {
            LOGGER.info("findScript: No script {} found in path", name);
        }

        // and finally return the script (null or not)
View Full Code Here


        return wrapper;
    }

    private JspServletWrapper getJspWrapper(final SlingScriptHelper scriptHelper, final SlingBindings bindings)
    throws SlingException {
        final SlingScript script = scriptHelper.getScript();
        final String scriptName = script.getScriptResource().getPath();
        return getJspWrapper(scriptName, bindings);
    }
View Full Code Here

    }

    private ServletWrapper getWrapperAdapter(final SlingScriptHelper scriptHelper)
    throws SlingException {

        SlingScript script = scriptHelper.getScript();
        final String scriptName = script.getScriptResource().getPath();
        ServletWrapper wrapper = this.ioProvider.getServletCache().getWrapper(scriptName);
        if (wrapper != null) {
            return wrapper;
        }
View Full Code Here

        final String lang = WebConsoleUtil.getParameter(req, "lang");
        final Resource resource = new RuntimeScriptResource(lang, script);
        final boolean webClient = "webconsole".equals(WebConsoleUtil.getParameter(req,"client"));

        SlingScript slingScript = resource.adaptTo(SlingScript.class);
        try {
            log.debug("Executing script {}",script);
            slingScript.eval(bindings);
        } catch (Throwable t){
            if(!webClient){
                resp.setStatus(500);
            }
            pw.println(exceptionToString(t));
View Full Code Here

public class StandaloneScriptExecutionServlet extends SlingSafeMethodsServlet {

  @Override
  protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
  throws ServletException, IOException {
    final SlingScript script = request.getResource().adaptTo(SlingScript.class);
    if(script == null) {
      throw new ServletException("Resource does not adapt to a SlingScript:" + request.getResource().getPath());
    }
   
    // Execute the script without providing a request or response, in the simplest possible way
    final SlingBindings bindings = new SlingBindings();
    final StringWriter sw = new StringWriter();
    bindings.put("StandaloneScriptExecutionServletOutput", sw);
    script.eval(bindings);
   
    response.setContentType("text/plain");
    response.getWriter().write(sw.toString());
  }
View Full Code Here

    private JspServletWrapperAdapter getJspWrapperAdapter(
            SlingScriptHelper scriptHelper) throws SlingException {

        JspRuntimeContext rctxt = jspRuntimeContext;

        SlingScript script = scriptHelper.getScript();
        String scriptName = script.getScriptResource().getPath();
        JspServletWrapperAdapter wrapper = (JspServletWrapperAdapter) rctxt.getWrapper(scriptName);
        if (wrapper != null) {
            return wrapper;
        }
View Full Code Here

    public SlingScript findScript(ResourceResolver resourceResolver, String name)
            throws SlingException {

        // is the path absolute
        SlingScript script = null;
        if (name.startsWith("/")) {

            Resource resource = resourceResolver.getResource(name);
            if (resource != null) {
                script = resource.adaptTo(SlingScript.class);
            }

        } else {

            // relative script resolution against search path
            String[] path = resourceResolver.getSearchPath();
            for (int i = 0; script == null && i < path.length; i++) {
                String scriptPath = path[i] + name;
                Resource resource = resourceResolver.getResource(scriptPath);
                if (resource != null) {
                    script = resource.adaptTo(SlingScript.class);
                }
            }

        }

        // some logging
        if (script != null) {
            log.debug("findScript: Using script {} for {}",
                script.getScriptResource().getPath(), name);
        } else {
            log.info("findScript: No script {} found in path", name);
        }

        // and finally return the script (null or not)
View Full Code Here

    public SlingScript findScript(ResourceResolver resourceResolver, String name)
            throws SlingException {

        // is the path absolute
        SlingScript script = null;
        if (name.startsWith("/")) {

            Resource resource = resourceResolver.getResource(name);
            if (resource != null) {
                script = resource.adaptTo(SlingScript.class);
            }

        } else {

            // relative script resolution against search path
            String[] path = resourceResolver.getSearchPath();
            for (int i = 0; script == null && i < path.length; i++) {
                String scriptPath = path[i] + name;
                Resource resource = resourceResolver.getResource(scriptPath);
                if (resource != null) {
                    script = resource.adaptTo(SlingScript.class);
                }
            }

        }

        // some logging
        if (script != null) {
            log.debug("findScript: Using script {} for {}",
                script.getScriptResource().getPath(), name);
        } else {
            log.info("findScript: No script {} found in path", name);
        }

        // and finally return the script (null or not)
View Full Code Here

    private JspServletWrapperAdapter getJspWrapperAdapter(
            SlingScriptHelper scriptHelper) throws SlingException {

        JspRuntimeContext rctxt = jspRuntimeContext;

        SlingScript script = scriptHelper.getScript();
        String scriptName = script.getScriptResource().getPath();
        JspServletWrapperAdapter wrapper = (JspServletWrapperAdapter) rctxt.getWrapper(scriptName);
        if (wrapper != null) {
            return wrapper;
        }
View Full Code Here

TOP

Related Classes of org.apache.sling.api.scripting.SlingScript

Copyright © 2018 www.massapicom. 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.