use of javax.servlet.jsp.tagext.BodyContent in project sling 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 Lucee by lucee.
the class UDFImpl method _call.
private Object _call(PageContext pc, Collection.Key calledName, Object[] args, Struct values, boolean doIncludePath) throws PageException {
// print.out(count++);
PageContextImpl pci = (PageContextImpl) pc;
Argument newArgs = pci.getScopeFactory().getArgumentInstance();
newArgs.setFunctionArgumentNames(properties.getArgumentsSet());
LocalImpl newLocal = pci.getScopeFactory().getLocalInstance();
Undefined undefined = pc.undefinedScope();
Argument oldArgs = pc.argumentsScope();
Local oldLocal = pc.localScope();
Collection.Key oldCalledName = pci.getActiveUDFCalledName();
pc.setFunctionScopes(newLocal, newArgs);
pci.setActiveUDFCalledName(calledName);
int oldCheckArgs = undefined.setMode(pc.getCurrentTemplateDialect() == CFMLEngine.DIALECT_CFML ? (properties.getLocalMode() == null ? pc.getApplicationContext().getLocalMode() : properties.getLocalMode().intValue()) : Undefined.MODE_LOCAL_OR_ARGUMENTS_ALWAYS);
PageSource ps = null;
PageSource psInc = null;
try {
ps = properties.getPageSource();
if (doIncludePath)
psInc = ps;
if (doIncludePath && getOwnerComponent() != null) {
psInc = ComponentUtil.getPageSource(getOwnerComponent());
if (psInc == pci.getCurrentTemplatePageSource()) {
psInc = null;
}
}
if (ps != null)
pci.addPageSource(ps, psInc);
pci.addUDF(this);
// ////////////////////////////////////////
BodyContent bc = null;
Boolean wasSilent = null;
boolean bufferOutput = getBufferOutput(pci);
if (!getOutput()) {
if (bufferOutput)
bc = pci.pushBody();
else
wasSilent = pc.setSilent() ? Boolean.TRUE : Boolean.FALSE;
}
UDF parent = null;
if (ownerComponent != null) {
parent = pci.getActiveUDF();
pci.setActiveUDF(this);
}
Object returnValue = null;
try {
if (args != null)
defineArguments(pc, getFunctionArguments(), args, newArgs);
else
defineArguments(pc, getFunctionArguments(), values, newArgs);
returnValue = implementation(pci);
if (ownerComponent != null)
pci.setActiveUDF(parent);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
if (ownerComponent != null)
pci.setActiveUDF(parent);
if (!getOutput()) {
if (bufferOutput)
BodyContentUtil.flushAndPop(pc, bc);
else if (!wasSilent)
pc.unsetSilent();
}
// BodyContentUtil.flushAndPop(pc,bc);
throw Caster.toPageException(t);
}
if (!getOutput()) {
if (bufferOutput)
BodyContentUtil.clearAndPop(pc, bc);
else if (!wasSilent)
pc.unsetSilent();
}
if (returnValue == null && pc.getConfig().getFullNullSupport())
return returnValue;
if (properties.getReturnType() == CFTypes.TYPE_ANY || !((PageContextImpl) pc).getTypeChecking())
return returnValue;
if (Decision.isCastableTo(properties.getReturnTypeAsString(), returnValue, false, false, -1))
return returnValue;
throw new UDFCasterException(this, properties.getReturnTypeAsString(), returnValue);
// REALCAST return Caster.castTo(pageContext,returnType,returnValue,false);
// ////////////////////////////////////////
} finally {
if (ps != null)
pc.removeLastPageSource(psInc != null);
pci.removeUDF();
pci.setFunctionScopes(oldLocal, oldArgs);
pci.setActiveUDFCalledName(oldCalledName);
undefined.setMode(oldCheckArgs);
pci.getScopeFactory().recycle(pci, newArgs);
pci.getScopeFactory().recycle(pci, newLocal);
}
}
use of javax.servlet.jsp.tagext.BodyContent in project Lucee by lucee.
the class Renderer method tag.
public static Result tag(PageContext pc, String cfml, int dialect, boolean catchOutput, boolean ignoreScopes) throws PageException {
// execute
Result res = new Result();
BodyContent bc = null;
// Variables before = pc.variablesScope();
try {
if (catchOutput)
bc = pc.pushBody();
// if(variables!=null)pc.setVariablesScope(variables);
res.value = loadPage(pc.getConfig(), null, cfml, dialect, ignoreScopes).call(pc);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
throw Caster.toPageException(t);
} finally {
// if(variables!=null)pc.setVariablesScope(before);
if (catchOutput) {
if (bc != null)
res.output = bc.getString();
pc.popBody();
}
// pc.flush();
}
return res;
}
use of javax.servlet.jsp.tagext.BodyContent in project Lucee by lucee.
the class PageContextUtil method getHandlePageException.
public static String getHandlePageException(PageContextImpl pc, PageException pe) throws PageException {
BodyContent bc = null;
String str = null;
try {
bc = pc.pushBody();
pc.handlePageException(pe, false);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
throw Caster.toPageException(t);
} finally {
if (bc != null)
str = bc.getString();
pc.popBody();
}
return str;
}
use of javax.servlet.jsp.tagext.BodyContent in project Lucee by lucee.
the class FormatTag method doAfterBody.
/**
* Method called at end of format tag body.
*
* @return SKIP_BODY
*/
@Override
public final int doAfterBody() throws JspException {
// Use the body of the tag as input for the date
BodyContent body = getBodyContent();
String s = body.getString().trim();
// Clear the body since we will output only the formatted date
body.clearBody();
if (output_date == null) {
long time;
try {
time = Long.valueOf(s).longValue();
output_date = new Date(time);
} catch (NumberFormatException nfe) {
}
}
return SKIP_BODY;
}
Aggregations