Package org.apache.sling.api.servlets

Examples of org.apache.sling.api.servlets.HtmlResponse


            return getClass().getSimpleName() + " for " + delegatee.getClass().getName();
        }

        public void run(SlingHttpServletRequest request, PostResponse response,
                SlingPostProcessor[] processors) {
            HtmlResponse apiResponse = new HtmlResponseProxy(response);
            delegatee.run(request, apiResponse, processors);
        }
View Full Code Here


     * meethod with a proxy for the Sling API <code>HtmlResponse</code>.
     */
    protected void doRun(SlingHttpServletRequest request,
            PostResponse response, List<Modification> changes)
            throws RepositoryException {
        final HtmlResponse htmlResponseProxy = (response instanceof HtmlPostResponseProxy)
                ? ((HtmlPostResponseProxy) response).getHtmlResponse()
                : new HtmlResponseProxy(response);
        doRun(request, htmlResponseProxy, changes);
    }
View Full Code Here

public class HtmlResponseServlet extends SlingSafeMethodsServlet {

    @Override
    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
    throws ServletException,IOException {
        final HtmlResponse hr = new HtmlResponse();
        // Specific status to help recognize this servlet in tests
        final int status = HttpServletResponse.SC_GATEWAY_TIMEOUT;
        hr.setStatus(status, getClass().getName() + ": GET always fails with status " + status);
        hr.setLocation("Location: some <script>");
        hr.setTitle(getClass().getName() + ": fake response to test <escaping>");
        hr.send(response, true);
    }
View Full Code Here

  @Override
  protected void doPost(SlingHttpServletRequest request,
      SlingHttpServletResponse httpResponse) throws ServletException,
      IOException {
        // prepare the response
        HtmlResponse htmlResponse = new HtmlResponse();
        htmlResponse.setReferer(request.getHeader("referer"));

        // calculate the paths
        String path = getItemPath(request);
        htmlResponse.setPath(path);

        // location
        htmlResponse.setLocation(externalizePath(request, path));

        // parent location
        path = ResourceUtil.getParent(path);
        if (path != null) {
          htmlResponse.setParentLocation(externalizePath(request, path));
        }

        Session session = request.getResourceResolver().adaptTo(Session.class);

        final List<Modification> changes = new ArrayList<Modification>();
       
        try {
            handleOperation(request, htmlResponse, changes);
           
            //TODO: maybe handle SlingAuthorizablePostProcessor handlers here
           
            // set changes on html response
            for(Modification change : changes) {
                switch ( change.getType() ) {
                    case MODIFY : htmlResponse.onModified(change.getSource()); break;
                    case DELETE : htmlResponse.onDeleted(change.getSource()); break;
                    case MOVE :   htmlResponse.onMoved(change.getSource(), change.getDestination()); break;
                    case COPY :   htmlResponse.onCopied(change.getSource(), change.getDestination()); break;
                    case CREATE : htmlResponse.onCreated(change.getSource()); break;
                    case ORDER : htmlResponse.onChange("ordered", change.getSource(), change.getDestination()); break;
                }
            }
           
            if (session.hasPendingChanges()) {
                session.save();
            }
        } catch (ResourceNotFoundException rnfe) {
            htmlResponse.setStatus(HttpServletResponse.SC_NOT_FOUND,
                rnfe.getMessage());
        } catch (Throwable throwable) {
            log.debug("Exception while handling POST "
                + request.getResource().getPath() + " with "
                + getClass().getName(), throwable);
            htmlResponse.setError(throwable);
        } finally {
            try {
                if (session.hasPendingChanges()) {
                    session.refresh(false);
                }
            } catch (RepositoryException e) {
                log.warn("RepositoryException in finally block: {}",
                    e.getMessage(), e);
            }
        }
       
        // check for redirect URL if processing succeeded
        if (htmlResponse.isSuccessful()) {
            String redirect = getRedirectUrl(request, htmlResponse);
            if (redirect != null) {
                httpResponse.sendRedirect(redirect);
                return;
            }
        }

        // create a html response and send if unsuccessful or no redirect
        htmlResponse.send(httpResponse, isSetStatus(request));
  }
View Full Code Here

    @Override
    protected void doPost(SlingHttpServletRequest request,
            SlingHttpServletResponse response) throws IOException {

        // prepare the response
        HtmlResponse htmlResponse = new HtmlResponse();
        htmlResponse.setReferer(request.getHeader("referer"));

        SlingPostOperation operation = getSlingPostOperation(request);
        if (operation == null) {

            htmlResponse.setStatus(
                HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                "Invalid operation specified for POST request");

        } else {

            try {
                operation.run(request, htmlResponse);
            } catch (ResourceNotFoundException rnfe) {
                htmlResponse.setStatus(HttpServletResponse.SC_NOT_FOUND,
                    rnfe.getMessage());
            } catch (Throwable throwable) {
                htmlResponse.setError(throwable);
            }

        }

        // check for redirect URL if processing succeeded
        if (htmlResponse.isSuccessful()) {
            String redirect = getRedirectUrl(request, htmlResponse);
            if (redirect != null) {
                response.sendRedirect(redirect);
                return;
            }
        }

        // create a html response and send if unsuccessful or no redirect
        htmlResponse.send(response, isSetStatus(request));
    }
View Full Code Here

    @Override
    protected void doPost(SlingHttpServletRequest request,
            SlingHttpServletResponse response) throws IOException {

        // prepare the response
        HtmlResponse htmlResponse = new HtmlResponse();
        htmlResponse.setReferer(request.getHeader("referer"));

        SlingPostOperation operation = getSlingPostOperation(request);
        if (operation == null) {

            htmlResponse.setStatus(
                HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                "Invalid operation specified for POST request");

        } else {

            final SlingPostProcessor[] processors;
            synchronized ( this.delayedPostProcessors ) {
                processors = this.cachedPostProcessors;
            }
            try {
                operation.run(request, htmlResponse, processors);
            } catch (ResourceNotFoundException rnfe) {
                htmlResponse.setStatus(HttpServletResponse.SC_NOT_FOUND,
                    rnfe.getMessage());
            } catch (Throwable throwable) {
                log.debug("Exception while handling POST "
                    + request.getResource().getPath() + " with "
                    + operation.getClass().getName(), throwable);
                htmlResponse.setError(throwable);
            }

        }

        // check for redirect URL if processing succeeded
        if (htmlResponse.isSuccessful()) {
            String redirect = getRedirectUrl(request, htmlResponse);
            if (redirect != null) {
                response.sendRedirect(redirect);
                return;
            }
        }

        // create a html response and send if unsuccessful or no redirect
        htmlResponse.send(response, isSetStatus(request));
    }
View Full Code Here

  @Override
  protected void doPost(SlingHttpServletRequest request,
      SlingHttpServletResponse httpResponse) throws ServletException,
      IOException {
        // prepare the response
        HtmlResponse htmlResponse = new HtmlResponse();
        htmlResponse.setReferer(request.getHeader("referer"));

        // calculate the paths
        String path = getItemPath(request);
        htmlResponse.setPath(path);

        // location
        htmlResponse.setLocation(externalizePath(request, path));

        // parent location
        path = ResourceUtil.getParent(path);
        if (path != null) {
          htmlResponse.setParentLocation(externalizePath(request, path));
        }

        Session session = request.getResourceResolver().adaptTo(Session.class);

        final List<Modification> changes = new ArrayList<Modification>();
       
        try {
            handleOperation(request, htmlResponse, changes);
           
            //TODO: maybe handle SlingAuthorizablePostProcessor handlers here
           
            // set changes on html response
            for(Modification change : changes) {
                switch ( change.getType() ) {
                    case MODIFY : htmlResponse.onModified(change.getSource()); break;
                    case DELETE : htmlResponse.onDeleted(change.getSource()); break;
                    case MOVE :   htmlResponse.onMoved(change.getSource(), change.getDestination()); break;
                    case COPY :   htmlResponse.onCopied(change.getSource(), change.getDestination()); break;
                    case CREATE : htmlResponse.onCreated(change.getSource()); break;
                    case ORDER : htmlResponse.onChange("ordered", change.getSource(), change.getDestination()); break;
                }
            }
           
            if (session.hasPendingChanges()) {
                session.save();
            }
        } catch (ResourceNotFoundException rnfe) {
            htmlResponse.setStatus(HttpServletResponse.SC_NOT_FOUND,
                rnfe.getMessage());
        } catch (Throwable throwable) {
            log.debug("Exception while handling POST "
                + request.getResource().getPath() + " with "
                + getClass().getName(), throwable);
            htmlResponse.setError(throwable);
        } finally {
            try {
                if (session.hasPendingChanges()) {
                    session.refresh(false);
                }
            } catch (RepositoryException e) {
                log.warn("RepositoryException in finally block: {}",
                    e.getMessage(), e);
            }
        }
       
        // check for redirect URL if processing succeeded
        if (htmlResponse.isSuccessful()) {
            String redirect = getRedirectUrl(request, htmlResponse);
            if (redirect != null) {
                httpResponse.sendRedirect(redirect);
                return;
            }
        }

        // create a html response and send if unsuccessful or no redirect
        htmlResponse.send(httpResponse, isSetStatus(request));
  }
View Full Code Here

TOP

Related Classes of org.apache.sling.api.servlets.HtmlResponse

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.