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