Package org.apache.sling.api

Examples of org.apache.sling.api.SlingHttpServletRequest


     * @return whether additional evaluations of the body are desired
     */
    public int doEndTag() throws JspException {
        log.debug("AbstractDispatcherTagHandler.doEndTag");

        final SlingHttpServletRequest request = TagUtil.getRequest(pageContext);

        // set request dispatcher options according to tag attributes. This
        // depends on the implementation, that using a "null" argument
        // has no effect
        final RequestDispatcherOptions opts = new RequestDispatcherOptions();
        opts.setForceResourceType(resourceType);
        opts.setReplaceSelectors(replaceSelectors);
        opts.setAddSelectors(addSelectors);
        opts.setReplaceSuffix(replaceSuffix);

        // ensure the path (if set) is absolute and normalized
        if (path != null) {
            if (!path.startsWith("/")) {
                path = request.getResource().getPath() + "/" + path;
            }
            path = ResourceUtil.normalize(path);
        }

        // check the resource
        if (resource == null) {
            if (path == null) {
                // neither resource nor path is defined, use current resource
                resource = request.getResource();
            } else {
                // check whether the path (would) resolve, else SyntheticRes.
                Resource tmp = request.getResourceResolver().resolve(path);
                if (tmp == null && resourceType != null) {
                    resource = new DispatcherSyntheticResource(
                        request.getResourceResolver(), path, resourceType);

                    // remove resource type overwrite as synthetic resource
                    // is correctly typed as requested
                    opts.remove(RequestDispatcherOptions.OPT_FORCE_RESOURCE_TYPE);
                }
            }
        }

        try {
            // create a dispatcher for the resource or path
            RequestDispatcher dispatcher;
            if (resource != null) {
                dispatcher = request.getRequestDispatcher(resource, opts);
            } else {
                dispatcher = request.getRequestDispatcher(path, opts);
            }

            if (dispatcher != null) {
                SlingHttpServletResponse response = new JspSlingHttpServletResponseWrapper(
                    pageContext);
View Full Code Here


    return getFromCurrentPath(pageContext, type, null);
  }

  public static <T> T getFromCurrentPath(final PageContext pageContext, final Class<T> type,
      final String appName) {
    final SlingHttpServletRequest request = SliceTagUtils.slingRequestFrom(pageContext);
    final InjectorsRepository injectorsRepository = SliceTagUtils.injectorsRepositoryFrom(pageContext);
    final ContextProvider contextProvider = SliceTagUtils.contextProviderFrom(pageContext);

    return getFromCurrentPath(request, injectorsRepository, contextProvider, type, appName);
  }
View Full Code Here

                || !(servletResponse instanceof SlingHttpServletResponse)) {
            filterChain.doFilter(servletRequest, servletResponse);
            return;
        }

        final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) servletRequest;
        final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) servletResponse;

        if (!this.accepts(slingRequest)) {
            filterChain.doFilter(slingRequest, slingResponse);
            return;
        }

        final BufferingResponse capturedResponse = new BufferingResponse(slingResponse);

        filterChain.doFilter(slingRequest, capturedResponse);

        // Get contents
        final String contents = capturedResponse.getContents();

        if (contents != null) {
            if (StringUtils.contains(slingResponse.getContentType(), "html")) {

                final int bodyIndex = contents.indexOf("</body>");
                if (bodyIndex != -1) {

                    final PrintWriter printWriter = slingResponse.getWriter();

                    printWriter.write(contents.substring(0, bodyIndex));
                    printWriter.write(String.format(
                            "<script type=\"text/javascript\" src=\"http://%s:%s/livereload.js\"></script>",
                            slingRequest.getServerName(), port));
                    printWriter.write(contents.substring(bodyIndex));
                    return;
                }
            }
        }
View Full Code Here

      throws IOException, ServletException {
    if (!(config.isEnabled() && request instanceof SlingHttpServletRequest && response instanceof SlingHttpServletResponse)) {
      chain.doFilter(request, response);
      return;
    }
    SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;
    SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) response;
    for (RequestProcessor p : processors) {
      if (p.accepts(slingRequest)) {
        p.process(slingRequest, slingResponse, chain);
        return;
View Full Code Here

    final String blankMessage = prepareBlankMessage();
    out.write(blankMessage);
  }

  protected String prepareBlankMessage() throws IOException, RepositoryException {
    final SlingHttpServletRequest request = SliceTagUtils.slingRequestFrom(pageContext);
    final Resource resource = request.getResource();

    if (null == resource || StringUtils.isBlank(resource.getResourceType())) {
      return DEFAULT_BLANK_MESSAGE;
    }
View Full Code Here

    return getFromCurrentPath(pageContext, type, null);
  }

  public static <T> T getFromCurrentPath(final PageContext pageContext, final Class<T> type,
      final String appName) {
    final SlingHttpServletRequest request = SliceTagUtils.slingRequestFrom(pageContext);
    final InjectorsRepository injectorsRepository = SliceTagUtils.injectorsRepositoryFrom(pageContext);
    final RequestContextProvider requestContextProvider = SliceTagUtils
        .requestContextProviderFrom(pageContext);

    return getFromCurrentPath(request, injectorsRepository, requestContextProvider, type, appName);
View Full Code Here

  /** {@inheritDoc} */
  @Override
  public int doEndTag() throws JspException {
    // we consider removing decoration only if we're including a component
    SlingHttpServletRequest request = getRequest();
    WCMMode wcmMode = WCMMode.fromRequest(request);

    ComponentConfiguration componentConfiguration = readComponentConfiguration(request);

    boolean decorationEnabled;
View Full Code Here

  /** {@inheritDoc} */
  @Override
  public int doEndTag() throws JspException {
    // we consider removing decoration only if we're including a component
    SlingHttpServletRequest request = getRequest();
    WCMMode wcmMode = WCMMode.fromRequest(request);

    ComponentConfiguration componentConfiguration = readComponentConfiguration(request);

    boolean decorationEnabled;
View Full Code Here

      throws IOException, ServletException {
    if (!(request instanceof SlingHttpServletRequest && response instanceof SlingHttpServletResponse)) {
      chain.doFilter(request, response);
      return;
    }
    final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;
    final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) response;
    final String requestPath = slingRequest.getRequestPathInfo().getResourcePath();
    for (Configuration c : configs) {
      if (c.isEnabled() && requestPath.startsWith(c.getBasePath())) {
        if (process(c, slingRequest, slingResponse, chain)) {
          return;
        }
View Full Code Here

    private String brand;

    @Override
    public int doEndTag() throws JspTagException {

        final SlingHttpServletRequest request = (SlingHttpServletRequest) pageContext.getAttribute(
                ATTR_SLING_REQUEST);

        try {
            if (buildJs()) {
View Full Code Here

TOP

Related Classes of org.apache.sling.api.SlingHttpServletRequest

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.