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));
}
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;
}
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;
}
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));
}
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);
}
}
Aggregations