use of lucee.runtime.PageContextImpl in project Lucee by lucee.
the class HtmlBody method actionFlush.
@Override
public void actionFlush() throws IOException {
PageContextImpl pci = (PageContextImpl) pageContext;
pci.write(pci.getRootOut().getHTMLBody());
pci.getRootOut().resetHTMLBody();
}
use of lucee.runtime.PageContextImpl in project Lucee by lucee.
the class HtmlHead method actionFlush.
@Override
public void actionFlush() throws IOException {
PageContextImpl pci = (PageContextImpl) pageContext;
pci.write(pci.getRootOut().getHTMLHead());
pci.getRootOut().resetHTMLHead();
}
use of lucee.runtime.PageContextImpl in project Lucee by lucee.
the class Lock method doStartTag.
@Override
public int doStartTag() throws PageException {
if (timeoutInMillis <= 0) {
TimeSpan remaining = PageContextUtil.remainingTime(pageContext, true);
this.timeoutInMillis = toInt(remaining.getMillis());
}
manager = pageContext.getConfig().getLockManager();
// check attributes
if (name != null && scope != SCOPE_NONE) {
throw new LockException(LockException.OPERATION_CREATE, this.name, "invalid attribute combination", "attribute [name] and [scope] can't be used together");
}
if (name == null && scope == SCOPE_NONE) {
name = "id-" + id;
}
String lockType = null;
if (name == null) {
String cid = pageContext.getConfig().getIdentification().getId();
// Session
if (scope == SCOPE_REQUEST) {
lockType = "request";
name = "__request_" + cid + "__" + ((RequestImpl) pageContext.requestScope())._getId();
} else // Session
if (scope == SCOPE_SESSION) {
lockType = "session";
name = "__session_" + cid + "__" + pageContext.sessionScope()._getId();
} else // Application
if (scope == SCOPE_APPLICATION) {
lockType = "application";
name = "__application_" + cid + "__" + ((ApplicationImpl) pageContext.applicationScope())._getId();
} else // Server
if (scope == SCOPE_SERVER) {
lockType = "server";
name = "__server_" + ((ServerImpl) pageContext.serverScope())._getId();
}
}
Struct cflock = new StructImpl();
cflock.set("succeeded", Boolean.TRUE);
cflock.set("errortext", "");
pageContext.setVariable(result, cflock);
start = System.nanoTime();
try {
// this has to be first, otherwise LockTimeoutException has nothing to release
((PageContextImpl) pageContext).setActiveLock(new ActiveLock(type, name, timeoutInMillis));
data = manager.lock(type, name, timeoutInMillis, pageContext.getId());
} catch (LockTimeoutException e) {
LockManagerImpl mi = (LockManagerImpl) manager;
Boolean hasReadLock = mi.isReadLocked(name);
Boolean hasWriteLock = mi.isWriteLocked(name);
String msg = LockTimeoutExceptionImpl.createMessage(type, name, lockType, timeoutInMillis, hasReadLock, hasWriteLock);
_release(pageContext, System.nanoTime() - start);
name = null;
cflock.set("succeeded", Boolean.FALSE);
cflock.set("errortext", msg);
if (throwontimeout)
throw new LockException(LockException.OPERATION_TIMEOUT, this.name, msg);
return SKIP_BODY;
} catch (InterruptedException e) {
_release(pageContext, System.nanoTime() - start);
cflock.set("succeeded", Boolean.FALSE);
cflock.set("errortext", e.getMessage());
if (throwontimeout)
throw Caster.toPageException(e);
return SKIP_BODY;
}
return EVAL_BODY_INCLUDE;
}
use of lucee.runtime.PageContextImpl in project Lucee by lucee.
the class Log method doStartTag.
@Override
public int doStartTag() throws PageException {
if (text == null && exception == null)
throw new ApplicationException("Wrong Context, you must define one of the following attributes [text, exception]");
PageContextImpl pci = (PageContextImpl) pageContext;
ConfigImpl config = (ConfigImpl) pageContext.getConfig();
lucee.commons.io.log.Log logger;
if (file == null) {
logger = pci.getLog(log.toLowerCase(), false);
if (logger == null) {
// for backward compatiblity
if ("console".equalsIgnoreCase(log))
logger = new LogAdapter(Log4jUtil.getConsoleLog(config, false, "cflog", Level.INFO));
else {
java.util.Collection<String> set = pci.getLogNames();
Iterator<String> it = set.iterator();
lucee.runtime.type.Collection.Key[] keys = new lucee.runtime.type.Collection.Key[set.size()];
int index = 0;
while (it.hasNext()) {
keys[index++] = KeyImpl.init(it.next());
}
throw new ApplicationException(ExceptionUtil.similarKeyMessage(keys, log, "attribute log", "log names", null, true));
}
}
} else {
logger = getFileLog(pageContext, file, charset, async);
}
String contextName = pageContext.getApplicationContext().getName();
if (contextName == null || !application)
contextName = "";
if (exception != null) {
if (StringUtil.isEmpty(text))
LogUtil.log(logger, type, contextName, exception);
else
LogUtil.log(logger, type, contextName, text, exception);
} else if (!StringUtil.isEmpty(text))
logger.log(type, contextName, text);
else
throw new ApplicationException("you must define attribute text or attribute exception with the tag cflog");
// logger.write(toStringType(type),contextName,text);
return SKIP_BODY;
}
use of lucee.runtime.PageContextImpl in project Lucee by lucee.
the class Module method initFile.
@Override
public void initFile() throws MissingIncludeException, ExpressionException {
ConfigWeb config = pageContext.getConfig();
// MUSTMUST cache like ct
// String[] filenames=getFileNames(config,getAppendix());// = appendix+'.'+config.getCFMLExtension();
Object objTemplate = attributesScope.get(KeyConstants._template, null);
Object objName = attributesScope.get(KeyConstants._name, null);
source = null;
if (objTemplate != null) {
attributesScope.removeEL(KeyConstants._template);
String template = objTemplate.toString();
if (StringUtil.startsWith(template, '/')) {
PageSource[] sources = ((PageContextImpl) pageContext).getPageSources(template);
PageSource ps = MappingImpl.isOK(sources);
if (ps == null)
throw new MissingIncludeException(sources[0], "could not find template [" + template + "], file [" + sources[0].getDisplayPath() + "] doesn't exist");
source = new InitFile(pageContext, ps, template);
} else {
source = new InitFile(pageContext, pageContext.getCurrentPageSource().getRealPage(template), template);
if (!MappingImpl.isOK(source.getPageSource())) {
throw new MissingIncludeException(source.getPageSource(), "could not find template [" + template + "], file [" + source.getPageSource().getDisplayPath() + "] doesn't exist");
}
}
// attributesScope.removeEL(TEMPLATE);
setAppendix(source.getPageSource());
} else if (objName != null) {
attributesScope.removeEL(KeyConstants._name);
String[] filenames = toRealPath(config, objName.toString());
boolean exist = false;
// appcontext mappings
Mapping[] ctms = pageContext.getApplicationContext().getCustomTagMappings();
if (ctms != null) {
outer: for (int f = 0; f < filenames.length; f++) {
for (int i = 0; i < ctms.length; i++) {
source = new InitFile(pageContext, ctms[i].getPageSource(filenames[f]), filenames[f]);
if (MappingImpl.isOK(source.getPageSource())) {
exist = true;
break outer;
}
}
}
}
// config mappings
if (!exist) {
ctms = config.getCustomTagMappings();
outer: for (int f = 0; f < filenames.length; f++) {
for (int i = 0; i < ctms.length; i++) {
// TODO optimieren siehe CFTag
source = new InitFile(pageContext, ctms[i].getPageSource(filenames[f]), filenames[f]);
if (MappingImpl.isOK(source.getPageSource())) {
exist = true;
break outer;
}
}
}
}
if (!exist)
throw new ExpressionException("custom tag (" + CustomTagUtil.getDisplayName(config, objName.toString()) + ") is not defined in custom tag directory [" + (ctms.length == 0 ? "no custom tag directory defined" : CustomTagUtil.toString(ctms)) + "]");
setAppendix(source.getPageSource());
} else {
throw new ExpressionException("you must define attribute template or name for tag module");
}
}
Aggregations