Search in sources :

Example 46 with PageContextImpl

use of lucee.runtime.PageContextImpl in project Lucee by lucee.

the class CFTag method doStartTag.

@Override
public int doStartTag() throws PageException {
    PageContextImpl pci = (PageContextImpl) pageContext;
    boolean old = pci.useSpecialMappings(true);
    try {
        initFile();
        callerScope.initialize(pageContext);
        if (source.isCFC())
            return cfcStartTag();
        return cfmlStartTag();
    } finally {
        pci.useSpecialMappings(old);
    }
}
Also used : PageContextImpl(lucee.runtime.PageContextImpl)

Example 47 with PageContextImpl

use of lucee.runtime.PageContextImpl in project Lucee by lucee.

the class CFTag method doEndTag.

@Override
public int doEndTag() {
    PageContextImpl pci = (PageContextImpl) pageContext;
    boolean old = pci.useSpecialMappings(true);
    try {
        if (source.isCFC())
            _doCFCFinally();
        return EVAL_PAGE;
    } finally {
        pci.useSpecialMappings(old);
    }
}
Also used : PageContextImpl(lucee.runtime.PageContextImpl)

Example 48 with PageContextImpl

use of lucee.runtime.PageContextImpl in project Lucee by lucee.

the class Cache method doServerCache.

private void doServerCache() throws IOException, PageException {
    if (hasBody)
        hasBody = !StringUtil.isEmpty(body);
    // call via cfcache disable debugger output
    if (pageContext.getConfig().debug())
        pageContext.getDebugger().setOutput(false);
    HttpServletResponse rsp = pageContext.getHttpServletResponse();
    // generate cache resource matching request object
    CacheItem ci = generateCacheResource(null, false);
    // use cached resource
    if (ci.isValid(timespan)) {
        // if(isOK(cacheResource)){
        if (pageContext.getHttpServletResponse().isCommitted())
            return;
        OutputStream os = null;
        try {
            ci.writeTo(os = getOutputStream(), ReqRspUtil.getCharacterEncoding(pageContext, rsp).name());
        // IOUtil.copy(is=cacheResource.getInputStream(),os=getOutputStream(),false,false);
        } finally {
            IOUtil.flushEL(os);
            IOUtil.closeEL(os);
            ((PageContextImpl) pageContext).getRootOut().setClosed(true);
        }
        throw new Abort(Abort.SCOPE_REQUEST);
    }
    // call page again and
    // MetaData.getInstance(getDirectory()).add(ci.getName(), ci.getRaw());
    PageContextImpl pci = (PageContextImpl) pageContext;
    pci.getRootOut().doCache(ci);
}
Also used : Abort(lucee.runtime.exp.Abort) OutputStream(java.io.OutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) CacheItem(lucee.runtime.cache.legacy.CacheItem) PageContextImpl(lucee.runtime.PageContextImpl)

Example 49 with PageContextImpl

use of lucee.runtime.PageContextImpl in project Lucee by lucee.

the class FileTag method actionRead.

/**
 * read source file
 * @throws PageException
 */
private void actionRead(boolean isBinary) throws PageException {
    if (variable == null)
        throw new ApplicationException("attribute variable is not defined for tag file");
    // check if we can use cache
    if (StringUtil.isEmpty(cachedWithin)) {
        Object tmp = ((PageContextImpl) pageContext).getCachedWithin(ConfigWeb.CACHEDWITHIN_FILE);
        if (tmp != null)
            setCachedwithin(tmp);
    }
    String cacheId = createCacheId(isBinary);
    CacheHandler cacheHandler = null;
    if (cachedWithin != null) {
        cacheHandler = pageContext.getConfig().getCacheHandlerCollection(Config.CACHE_TYPE_FILE, null).getInstanceMatchingObject(cachedWithin, null);
        if (cacheHandler instanceof CacheHandlerPro) {
            CacheItem cacheItem = ((CacheHandlerPro) cacheHandler).get(pageContext, cacheId, cachedWithin);
            if (cacheItem instanceof FileCacheItem) {
                pageContext.setVariable(variable, ((FileCacheItem) cacheItem).getData());
                return;
            }
        } else if (cacheHandler != null) {
            // TODO this else block can be removed when all cache handlers implement CacheHandlerPro
            CacheItem cacheItem = cacheHandler.get(pageContext, cacheId);
            if (cacheItem instanceof FileCacheItem) {
                pageContext.setVariable(variable, ((FileCacheItem) cacheItem).getData());
                return;
            }
        }
    }
    // cache not found, process and cache result if needed
    checkFile(pageContext, securityManager, file, serverPassword, false, false, true, false);
    try {
        long start = System.nanoTime();
        Object data = isBinary ? IOUtil.toBytes(file) : IOUtil.toString(file, CharsetUtil.toCharset(charset));
        pageContext.setVariable(variable, data);
        if (cacheHandler != null)
            cacheHandler.set(pageContext, cacheId, cachedWithin, FileCacheItem.getInstance(file.getAbsolutePath(), data, System.nanoTime() - start));
    } catch (IOException e) {
        throw new ApplicationException("can't read file [" + file.toString() + "]", e.getMessage());
    }
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) CacheHandlerPro(lucee.runtime.cache.tag.CacheHandlerPro) FileCacheItem(lucee.runtime.cache.tag.file.FileCacheItem) PageContextImpl(lucee.runtime.PageContextImpl) FileCacheItem(lucee.runtime.cache.tag.file.FileCacheItem) CacheItem(lucee.runtime.cache.tag.CacheItem) IOException(java.io.IOException) CacheHandler(lucee.runtime.cache.tag.CacheHandler)

Example 50 with PageContextImpl

use of lucee.runtime.PageContextImpl in project Lucee by lucee.

the class Header method doStartTag.

@Override
public int doStartTag() throws PageException {
    HttpServletResponse rsp = pageContext.getHttpServletResponse();
    if (rsp.isCommitted())
        throw new TemplateException("can't assign value to header, header is already committed");
    // set name value
    if (name != null) {
        if (charset == null && name.equalsIgnoreCase("content-disposition")) {
            charset = CharsetUtil.toCharSet(((PageContextImpl) pageContext).getWebCharset());
        }
        if (charset != null) {
            name = new String(name.getBytes(CharsetUtil.toCharset(charset)), CharsetUtil.ISO88591);
            value = new String(value.getBytes(CharsetUtil.toCharset(charset)), CharsetUtil.ISO88591);
        } else {
            name = new String(name.getBytes(), CharsetUtil.ISO88591);
            value = new String(value.getBytes(), CharsetUtil.ISO88591);
        }
        if (name.toLowerCase().equals("content-type") && value.length() > 0) {
            ReqRspUtil.setContentType(rsp, value);
        } else {
            rsp.addHeader(name, value);
        }
    }
    // set status
    if (hasStatucCode) {
        if (statustext != null) {
            // try {
            // /rsp.sendError(statuscode, statustext);
            rsp.setStatus(statuscode, statustext);
        /*} 
                catch (IOException e) {
    				throw new TemplateException("can't assign value to header, header is already committed",e.getMessage());
    			} */
        } else {
            rsp.setStatus(statuscode);
        }
    }
    return SKIP_BODY;
}
Also used : TemplateException(lucee.runtime.exp.TemplateException) HttpServletResponse(javax.servlet.http.HttpServletResponse) PageContextImpl(lucee.runtime.PageContextImpl)

Aggregations

PageContextImpl (lucee.runtime.PageContextImpl)84 PageSource (lucee.runtime.PageSource)19 Resource (lucee.commons.io.res.Resource)17 Key (lucee.runtime.type.Collection.Key)15 Struct (lucee.runtime.type.Struct)15 StructImpl (lucee.runtime.type.StructImpl)14 IOException (java.io.IOException)12 ApplicationException (lucee.runtime.exp.ApplicationException)10 PageException (lucee.runtime.exp.PageException)10 Component (lucee.runtime.Component)9 ConfigWeb (lucee.runtime.config.ConfigWeb)9 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)9 CFMLFactoryImpl (lucee.runtime.CFMLFactoryImpl)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ArrayList (java.util.ArrayList)6 Mapping (lucee.runtime.Mapping)6 PageContext (lucee.runtime.PageContext)6 ConfigImpl (lucee.runtime.config.ConfigImpl)6 ExpressionException (lucee.runtime.exp.ExpressionException)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)5