Search in sources :

Example 16 with BodyContent

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);
        }
    }
}
Also used : BodyContent(javax.servlet.jsp.tagext.BodyContent) CaptureResponseWrapper(org.apache.sling.scripting.core.servlet.CaptureResponseWrapper)

Example 17 with BodyContent

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);
    }
}
Also used : UDFCacheItem(lucee.runtime.cache.tag.udf.UDFCacheItem) BodyContent(javax.servlet.jsp.tagext.BodyContent) CacheHandlerPro(lucee.runtime.cache.tag.CacheHandlerPro) PageContextImpl(lucee.runtime.PageContextImpl) CacheItem(lucee.runtime.cache.tag.CacheItem) UDFCacheItem(lucee.runtime.cache.tag.udf.UDFCacheItem) IOException(java.io.IOException) CacheHandler(lucee.runtime.cache.tag.CacheHandler)

Example 18 with BodyContent

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);
    }
}
Also used : BodyContent(javax.servlet.jsp.tagext.BodyContent) DevNullBodyContent(lucee.runtime.writer.DevNullBodyContent) IncludeCacheItem(lucee.runtime.cache.tag.include.IncludeCacheItem) CacheHandlerPro(lucee.runtime.cache.tag.CacheHandlerPro) ErrorPage(lucee.runtime.err.ErrorPage) CacheItem(lucee.runtime.cache.tag.CacheItem) IncludeCacheItem(lucee.runtime.cache.tag.include.IncludeCacheItem) IOException(java.io.IOException) CacheHandler(lucee.runtime.cache.tag.CacheHandler)

Aggregations

BodyContent (javax.servlet.jsp.tagext.BodyContent)18 IOException (java.io.IOException)4 RequestDispatcher (javax.servlet.RequestDispatcher)3 JspException (javax.servlet.jsp.JspException)3 Servlet (javax.servlet.Servlet)2 PageContextImpl (lucee.runtime.PageContextImpl)2 CacheHandler (lucee.runtime.cache.tag.CacheHandler)2 CacheHandlerPro (lucee.runtime.cache.tag.CacheHandlerPro)2 CacheItem (lucee.runtime.cache.tag.CacheItem)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