use of javax.servlet.jsp.tagext.BodyContent in project sling by apache.
the class IncludeTagHandler method dispatch.
protected void dispatch(RequestDispatcher dispatcher, ServletRequest request, ServletResponse response) throws IOException, ServletException {
// optionally flush
if (flush && !(pageContext.getOut() instanceof BodyContent)) {
// might throw an IOException of course
pageContext.getOut().flush();
}
if (var == null) {
dispatcher.include(request, response);
} else {
final CaptureResponseWrapper wrapper = new CaptureResponseWrapper((HttpServletResponse) response);
dispatcher.include(request, wrapper);
if (!wrapper.isBinaryResponse()) {
pageContext.setAttribute(var, wrapper.getCapturedCharacterResponse(), scope);
}
}
}
use of javax.servlet.jsp.tagext.BodyContent in project Lucee by lucee.
the class UDFImpl method _callCachedWithin.
private Object _callCachedWithin(PageContext pc, Collection.Key calledName, Object[] args, Struct values, boolean doIncludePath) throws PageException {
PageContextImpl pci = (PageContextImpl) pc;
Object cachedWithin = getCachedWithin(pc);
String cacheId = CacheHandlerCollectionImpl.createId(this, args, values);
CacheHandler cacheHandler = pc.getConfig().getCacheHandlerCollection(Config.CACHE_TYPE_FUNCTION, null).getInstanceMatchingObject(getCachedWithin(pc), null);
if (cacheHandler instanceof CacheHandlerPro) {
CacheItem cacheItem = ((CacheHandlerPro) cacheHandler).get(pc, cacheId, cachedWithin);
if (cacheItem instanceof UDFCacheItem) {
UDFCacheItem entry = (UDFCacheItem) cacheItem;
try {
pc.write(entry.output);
} catch (IOException e) {
throw Caster.toPageException(e);
}
return entry.returnValue;
}
} else if (cacheHandler != null) {
// TODO this else block can be removed when all cache handlers implement CacheHandlerPro
CacheItem cacheItem = cacheHandler.get(pc, cacheId);
if (cacheItem instanceof UDFCacheItem) {
UDFCacheItem entry = (UDFCacheItem) cacheItem;
// if(entry.creationdate+properties.cachedWithin>=System.currentTimeMillis()) {
try {
pc.write(entry.output);
} catch (IOException e) {
throw Caster.toPageException(e);
}
return entry.returnValue;
// }
// cache.remove(id);
}
}
// cached item not found, process and cache result if needed
long start = System.nanoTime();
// execute the function
BodyContent bc = pci.pushBody();
try {
Object rtn = _call(pci, calledName, args, values, doIncludePath);
if (cacheHandler != null) {
String out = bc.getString();
cacheHandler.set(pc, cacheId, cachedWithin, new UDFCacheItem(out, rtn, getFunctionName(), getSource(), System.nanoTime() - start));
}
return rtn;
} finally {
BodyContentUtil.flushAndPop(pc, bc);
}
}
use of javax.servlet.jsp.tagext.BodyContent in project Lucee by lucee.
the class PageContextImpl method _doInclude.
// IMPORTANT!!! we do not getCachedWithin in this method, because Modern|ClassicAppListener is calling this method and in this case it should not be used
public void _doInclude(PageSource[] sources, boolean runOnce, Object cachedWithin) throws PageException {
if (cachedWithin == null) {
_doInclude(sources, runOnce);
return;
}
// ignore call when runonce an it is not first call
if (runOnce) {
Page currentPage = PageSourceImpl.loadPage(this, sources);
if (runOnce && includeOnce.contains(currentPage.getPageSource()))
return;
}
// get cached data
String cacheId = CacheHandlerCollectionImpl.createId(sources);
CacheHandler cacheHandler = config.getCacheHandlerCollection(Config.CACHE_TYPE_INCLUDE, null).getInstanceMatchingObject(cachedWithin, null);
if (cacheHandler instanceof CacheHandlerPro) {
CacheItem cacheItem = ((CacheHandlerPro) cacheHandler).get(this, cacheId, cachedWithin);
if (cacheItem instanceof IncludeCacheItem) {
try {
write(((IncludeCacheItem) cacheItem).getOutput());
return;
} catch (IOException e) {
throw Caster.toPageException(e);
}
}
} else if (cacheHandler != null) {
// TODO this else block can be removed when all cache handlers implement CacheHandlerPro
CacheItem cacheItem = cacheHandler.get(this, cacheId);
if (cacheItem instanceof IncludeCacheItem) {
try {
write(((IncludeCacheItem) cacheItem).getOutput());
return;
} catch (IOException e) {
throw Caster.toPageException(e);
}
}
}
// cached item not found, process and cache result if needed
long start = System.nanoTime();
BodyContent bc = pushBody();
try {
_doInclude(sources, runOnce);
String out = bc.getString();
if (cacheHandler != null) {
CacheItem cacheItem = new IncludeCacheItem(out, ArrayUtil.isEmpty(sources) ? null : sources[0], System.nanoTime() - start);
cacheHandler.set(this, cacheId, cachedWithin, cacheItem);
return;
}
} finally {
BodyContentUtil.flushAndPop(this, bc);
}
}
Aggregations