Examples of SlingBindings


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

    public void service(ServletRequest req, ServletResponse res) {
        final SlingHttpServletRequest request = (SlingHttpServletRequest) req;

        try {
            // prepare the properties for the script
            final SlingBindings props = new SlingBindings();
            props.setRequest((SlingHttpServletRequest) req);
            props.setResponse((SlingHttpServletResponse) res);

            // try to set content type (unless included)
            if (request.getAttribute(SlingConstants.ATTR_INCLUDE_SERVLET_PATH) == null) {
                final String contentType = request.getResponseContentType();
                if (contentType != null) {
View Full Code Here

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

     */
    private void callServlet(final Bindings bindings,
                             final SlingScriptHelper scriptHelper,
                             final ScriptContext context) {
        // create a SlingBindings object
        final SlingBindings slingBindings = new SlingBindings();
        slingBindings.putAll(bindings);

        ResourceResolver resolver = (ResourceResolver) context.getAttribute(SlingScriptConstants.ATTR_SCRIPT_RESOURCE_RESOLVER,
                SlingScriptConstants.SLING_SCOPE);
        if ( resolver == null ) {
            resolver = scriptHelper.getScript().getScriptResource().getResourceResolver();
        }
        ioProvider.setRequestResourceResolver(resolver);

        final SlingHttpServletRequest request = slingBindings.getRequest();
        final Object oldValue = request.getAttribute(SlingBindings.class.getName());
        try {
            final ServletWrapper servlet = getWrapperAdapter(scriptHelper);

            request.setAttribute(SlingBindings.class.getName(), slingBindings);
            servlet.service(request, slingBindings.getResponse());
        } catch (SlingException se) {
            // rethrow as is
            throw se;
        } catch (IOException ioe) {
            throw new SlingIOException(ioe);
View Full Code Here

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

        resp.setContentType(contentType);
        if (contentType.startsWith("text/")) {
            resp.setCharacterEncoding("UTF-8");
        }
        final String script = getCodeValue(req);
        final SlingBindings bindings = new SlingBindings();
        final PrintWriter pw = resp.getWriter();
        //Populate bindings
        bindings.put(SlingBindings.REQUEST, req);
        bindings.put(SlingBindings.READER, new StringReader(script));
        bindings.put(SlingBindings.RESPONSE, resp);
        bindings.put(SlingBindings.OUT, pw);

        //Also expose the bundleContext to simplify scripts interaction with the
        //enclosing OSGi container
        bindings.put("bundleContext", bundleContext);

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

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

    // -----------------------------------------------------< private >---

    @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.SlingBindings

    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

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

        ioProvider.setRequestResourceResolver(scriptHelper.getRequest().getResourceResolver());
        try {
            JspServletWrapperAdapter jsp = getJspWrapperAdapter(scriptHelper);
            // create a SlingBindings object
            final SlingBindings slingBindings = new SlingBindings();
            slingBindings.putAll(bindings);
            jsp.service(slingBindings);
        } finally {
            ioProvider.resetRequestResourceResolver();
        }
    }
View Full Code Here

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

     * {@inheritDoc}
     */
    @Override
    public int doEndTag() throws JspException {
        final SlingHttpServletRequest request = TagUtil.getRequest(pageContext);
        final SlingBindings bindings = (SlingBindings) request.getAttribute(SlingBindings.class.getName());
        final DesignHtmlLibraryManager manager = bindings.getSling().getService(DesignHtmlLibraryManager.class);
        if (manager != null) {
            try {
                if (js && css) {
                    manager.writeIncludes(request, getDesign(), region, pageContext.getOut());
                } else if (js) {
View Full Code Here

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

        SlingHttpServletRequest request = (SlingHttpServletRequest) req;

        try {
            // prepare the properties for the script
            SlingBindings props = new SlingBindings();
            props.setRequest((SlingHttpServletRequest) req);
            props.setResponse((SlingHttpServletResponse) res);
            props.setFlush(true);

            res.setCharacterEncoding("UTF-8");
            // try to set content type
            final String contentType = request.getResponseContentType();
            if ( contentType != null ) {
View Full Code Here

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

        ioProvider.setRequestResourceResolver(scriptHelper.getRequest().getResourceResolver());
        try {
            JspServletWrapperAdapter jsp = getJspWrapperAdapter(scriptHelper);
            // create a SlingBindings object
            final SlingBindings slingBindings = new SlingBindings();
            slingBindings.putAll(bindings);
            jsp.service(slingBindings);
        } finally {
            ioProvider.resetRequestResourceResolver();
        }
    }
View Full Code Here

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

        SlingHttpServletRequest request = (SlingHttpServletRequest) req;

        try {
            // prepare the properties for the script
            SlingBindings props = new SlingBindings();
            props.setRequest((SlingHttpServletRequest) req);
            props.setResponse((SlingHttpServletResponse) res);

            // try to set content type
            final String contentType = request.getResponseContentType();
            if (contentType != null) {
                res.setContentType(contentType);
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.