Search in sources :

Example 1 with BodyContent

use of javax.servlet.jsp.tagext.BodyContent in project tomcat by apache.

the class JspRuntimeLibrary method include.

/**
     * Perform a RequestDispatcher.include() operation, with optional flushing
     * of the response beforehand.
     *
     * @param request The servlet request we are processing
     * @param response The servlet response we are processing
     * @param relativePath The relative path of the resource to be included
     * @param out The Writer to whom we are currently writing
     * @param flush Should we flush before the include is processed?
     *
     * @exception IOException if thrown by the included servlet
     * @exception ServletException if thrown by the included servlet
     */
public static void include(ServletRequest request, ServletResponse response, String relativePath, JspWriter out, boolean flush) throws IOException, ServletException {
    if (flush && !(out instanceof BodyContent))
        out.flush();
    // FIXME - It is tempting to use request.getRequestDispatcher() to
    // resolve a relative path directly, but Catalina currently does not
    // take into account whether the caller is inside a RequestDispatcher
    // include or not.  Whether Catalina *should* take that into account
    // is a spec issue currently under review.  In the mean time,
    // replicate Jasper's previous behavior
    String resourcePath = getContextRelativePath(request, relativePath);
    RequestDispatcher rd = request.getRequestDispatcher(resourcePath);
    rd.include(request, new ServletResponseWrapperInclude(response, out));
}
Also used : BodyContent(javax.servlet.jsp.tagext.BodyContent) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 2 with BodyContent

use of javax.servlet.jsp.tagext.BodyContent in project grails-core by grails.

the class JspInvokeGrailsTagLibTag method doAfterBody.

@Override
public int doAfterBody() throws JspException {
    BodyContent b = getBodyContent();
    if (invocationCount > 0) {
        if (b != null) {
            jspWriter = b.getEnclosingWriter();
            invocationBodyContent.add(b.getString());
            bodyInvokation = true;
            b.clearBody();
        }
    }
    invocationCount--;
    setCurrentArgument();
    if (invocationCount < 1) {
        tagContent = sw.toString();
        int i = 1;
        StringBuilder buf = new StringBuilder();
        for (String body : invocationBodyContent) {
            String replaceFlag = "<jsp-body-gen" + i + ">";
            int j = tagContent.indexOf(replaceFlag);
            if (j > -1) {
                buf.append(tagContent.substring(0, j)).append(body).append(tagContent.substring(j + replaceFlag.length(), tagContent.length()));
                tagContent = buf.toString();
                if (tagContent != null) {
                    try {
                        jspWriter.write(tagContent);
                        out.close();
                    } catch (IOException e) {
                        throw new JspTagException("I/O error writing tag contents [" + tagContent + "] to response out");
                    }
                }
                buf.delete(0, buf.length());
            }
        }
        return SKIP_BODY;
    }
    return EVAL_BODY_BUFFERED;
}
Also used : BodyContent(javax.servlet.jsp.tagext.BodyContent) IOException(java.io.IOException) JspTagException(javax.servlet.jsp.JspTagException)

Example 3 with BodyContent

use of javax.servlet.jsp.tagext.BodyContent in project grails-core by grails.

the class GroovyPagesPageContext method pushBody.

@Override
public BodyContent pushBody() {
    BodyContent bc = new BodyContentImpl(getOut(), true);
    pushWriter(bc);
    return bc;
}
Also used : BodyContent(javax.servlet.jsp.tagext.BodyContent)

Example 4 with BodyContent

use of javax.servlet.jsp.tagext.BodyContent in project yyl_example by Relucent.

the class JspRuntimeLibrary method include.

/**
	 * <pre>
	 * 	<jsp:include page="page.jsp" />
	 * 	JspRuntimeLibrary.include(request, response, "page.jsp", out, false);
	 * </pre>
	 */
public static void include(ServletRequest request, ServletResponse response, String relativePath, JspWriter out, boolean flush) throws IOException, ServletException {
    if ((flush) && (!(out instanceof BodyContent))) {
        out.flush();
    }
    String resourcePath = getContextRelativePath(request, relativePath);
    RequestDispatcher rd = request.getRequestDispatcher(resourcePath);
    rd.include(request, new ServletResponseWrapperInclude(response, out));
}
Also used : BodyContent(javax.servlet.jsp.tagext.BodyContent) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 5 with BodyContent

use of javax.servlet.jsp.tagext.BodyContent in project sling by apache.

the class EvalTagHandler method doEndTag.

/**
     * Called after the body has been processed.
     *
     * @return whether additional evaluations of the body are desired
     */
public int doEndTag() throws JspException {
    log.debug("EvalTagHandler doEndTag");
    final SlingBindings bindings = (SlingBindings) pageContext.getRequest().getAttribute(SlingBindings.class.getName());
    final SlingScriptHelper scriptHelper = bindings.getSling();
    final ServletResolver servletResolver = scriptHelper.getService(ServletResolver.class);
    final Servlet servlet;
    if (!this.ignoreResourceTypeHierarchy) {
        // detecte resource
        final Resource resource;
        if (this.resource != null) {
            resource = this.resource;
        } else if (this.resourceType != null) {
            resource = new SyntheticResource(bindings.getRequest().getResourceResolver(), bindings.getResource().getPath(), this.resourceType);
        } else {
            resource = bindings.getResource();
        }
        servlet = servletResolver.resolveServlet(resource, this.script);
    } else {
        final ResourceResolver rr = bindings.getRequest().getResourceResolver();
        final String scriptPath;
        if (!script.startsWith("/")) {
            // resolve relative script
            String parentPath = ResourceUtil.getParent(scriptHelper.getScript().getScriptResource().getPath());
            // check if parent resides on search path
            for (String sp : rr.getSearchPath()) {
                if (parentPath.startsWith(sp)) {
                    parentPath = parentPath.substring(sp.length());
                    break;
                }
            }
            scriptPath = parentPath + '/' + script;
        } else {
            scriptPath = this.script;
        }
        servlet = servletResolver.resolveServlet(rr, scriptPath);
    }
    if (servlet == null) {
        throw new JspException("Could not find script '" + script + "' referenced in jsp " + scriptHelper.getScript().getScriptResource().getPath());
    }
    try {
        if (flush && !(pageContext.getOut() instanceof BodyContent)) {
            // might throw an IOException of course
            pageContext.getOut().flush();
        }
        // wrap the response to get the correct output order
        SlingHttpServletResponse response = new JspSlingHttpServletResponseWrapper(pageContext);
        servlet.service(pageContext.getRequest(), response);
        return EVAL_PAGE;
    } catch (Exception e) {
        log.error("Error while executing script " + script, e);
        throw new JspException("Error while executing script " + script, e);
    }
}
Also used : SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) JspSlingHttpServletResponseWrapper(org.apache.sling.scripting.jsp.util.JspSlingHttpServletResponseWrapper) SlingBindings(org.apache.sling.api.scripting.SlingBindings) SlingScriptHelper(org.apache.sling.api.scripting.SlingScriptHelper) Resource(org.apache.sling.api.resource.Resource) SyntheticResource(org.apache.sling.api.resource.SyntheticResource) SyntheticResource(org.apache.sling.api.resource.SyntheticResource) JspException(javax.servlet.jsp.JspException) BodyContent(javax.servlet.jsp.tagext.BodyContent) JspException(javax.servlet.jsp.JspException) ServletResolver(org.apache.sling.api.servlets.ServletResolver) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Servlet(javax.servlet.Servlet)

Aggregations

BodyContent (javax.servlet.jsp.tagext.BodyContent)12 RequestDispatcher (javax.servlet.RequestDispatcher)3 JspException (javax.servlet.jsp.JspException)3 IOException (java.io.IOException)2 Servlet (javax.servlet.Servlet)2 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)2 Resource (org.apache.sling.api.resource.Resource)2 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)2 SlingBindings (org.apache.sling.api.scripting.SlingBindings)2 SlingScriptHelper (org.apache.sling.api.scripting.SlingScriptHelper)2 ServletResolver (org.apache.sling.api.servlets.ServletResolver)2 JspSlingHttpServletResponseWrapper (org.apache.sling.scripting.jsp.util.JspSlingHttpServletResponseWrapper)2 CompleteRequestException (com.iplanet.jato.CompleteRequestException)1 View (com.iplanet.jato.view.View)1 OptionList (com.iplanet.jato.view.html.OptionList)1 SelectableGroup (com.iplanet.jato.view.html.SelectableGroup)1 CCBodyContentImpl (com.sun.web.ui.common.CCBodyContentImpl)1 CCJspWriterImpl (com.sun.web.ui.common.CCJspWriterImpl)1 CCTagBase (com.sun.web.ui.taglib.common.CCTagBase)1 CCCheckBoxTag (com.sun.web.ui.taglib.html.CCCheckBoxTag)1