use of lucee.runtime.config.ConfigWeb 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");
}
}
use of lucee.runtime.config.ConfigWeb in project Lucee by lucee.
the class Admin method doTerminateRunningThread.
private void doTerminateRunningThread() throws PageException {
int id = getInt("admin", "RemoveRunningThread", "id");
if (type == TYPE_WEB) {
terminateRunningThread(pageContext.getConfig(), id);
} else {
ConfigServer cs = pageContext.getConfig().getConfigServer(password);
ConfigWeb[] webs = cs.getConfigWebs();
for (int i = 0; i < webs.length; i++) {
if (terminateRunningThread(webs[i], id))
break;
}
}
}
use of lucee.runtime.config.ConfigWeb in project Lucee by lucee.
the class ChildThreadImpl method execute.
public PageException execute(Config config) {
PageContext oldPc = ThreadLocalPageContext.get();
Page p = page;
PageContextImpl pc = null;
try {
// deamon
if (this.pc != null) {
pc = this.pc;
ThreadLocalPageContext.register(pc);
} else // task
{
ConfigWebImpl cwi;
try {
cwi = (ConfigWebImpl) config;
DevNullOutputStream os = DevNullOutputStream.DEV_NULL_OUTPUT_STREAM;
pc = ThreadUtil.createPageContext(cwi, os, serverName, requestURI, queryString, SerializableCookie.toCookies(cookies), headers, null, parameters, attributes, true, -1);
pc.setRequestTimeout(requestTimeout);
p = PageSourceImpl.loadPage(pc, cwi.getPageSources(oldPc == null ? pc : oldPc, null, template, false, false, true));
// p=cwi.getPageSources(oldPc,null, template, false,false,true).loadPage(cwi);
} catch (PageException e) {
return e;
}
pc.addPageSource(p.getPageSource(), true);
}
threadScope = pc.getThreadScope(KeyConstants._cfthread, null);
pc.setCurrentThreadScope(new ThreadsImpl(this));
pc.setThread(Thread.currentThread());
// String encodings = pc.getHttpServletRequest().getHeader("Accept-Encoding");
Undefined undefined = pc.us();
Argument newArgs = new ArgumentThreadImpl((Struct) Duplicator.duplicate(attrs, false));
LocalImpl newLocal = pc.getScopeFactory().getLocalInstance();
// Key[] keys = attrs.keys();
Iterator<Entry<Key, Object>> it = attrs.entryIterator();
Entry<Key, Object> e;
while (it.hasNext()) {
e = it.next();
newArgs.setEL(e.getKey(), e.getValue());
}
newLocal.setEL(KEY_ATTRIBUTES, newArgs);
Argument oldArgs = pc.argumentsScope();
Local oldLocal = pc.localScope();
int oldMode = undefined.setMode(Undefined.MODE_LOCAL_OR_ARGUMENTS_ALWAYS);
pc.setFunctionScopes(newLocal, newArgs);
try {
p.threadCall(pc, threadIndex);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
if (!Abort.isSilentAbort(t)) {
ConfigWeb c = pc.getConfig();
if (c instanceof ConfigImpl) {
ConfigImpl ci = (ConfigImpl) c;
Log log = ci.getLog("thread");
if (log != null)
LogUtil.log(log, Log.LEVEL_ERROR, this.getName(), t);
}
PageException pe = Caster.toPageException(t);
if (!serializable)
catchBlock = pe.getCatchBlock(pc.getConfig());
return pe;
}
} finally {
completed = true;
pc.setFunctionScopes(oldLocal, oldArgs);
undefined.setMode(oldMode);
// pc.getScopeFactory().recycle(newArgs);
pc.getScopeFactory().recycle(pc, newLocal);
if (pc.getHttpServletResponse() instanceof HttpServletResponseDummy) {
HttpServletResponseDummy rsp = (HttpServletResponseDummy) pc.getHttpServletResponse();
pc.flush();
contentType = rsp.getContentType();
Pair<String, Object>[] _headers = rsp.getHeaders();
if (_headers != null)
for (int i = 0; i < _headers.length; i++) {
if (_headers[i].getName().equalsIgnoreCase("Content-Encoding"))
contentEncoding = Caster.toString(_headers[i].getValue(), null);
}
}
}
} finally {
pc.getConfig().getFactory().releaseLuceePageContext(pc, true);
pc = null;
if (oldPc != null)
ThreadLocalPageContext.register(oldPc);
}
return null;
}
use of lucee.runtime.config.ConfigWeb in project Lucee by lucee.
the class SMTPClient method send.
public void send(PageContext pc, long sendTime) throws MailException {
if (plainText == null && htmlText == null)
throw new MailException("you must define plaintext or htmltext");
Server[] servers = ((PageContextImpl) pc).getMailServers();
ConfigWeb config = pc.getConfig();
if (ArrayUtil.isEmpty(servers) && ArrayUtil.isEmpty(host))
throw new MailException("no SMTP Server defined");
if (spool == SPOOL_YES || (spool == SPOOL_UNDEFINED && config.isMailSpoolEnable())) {
MailSpoolerTask mst = new MailSpoolerTask(this, servers, sendTime);
if (listener instanceof Component)
mst.setListener(new ComponentSpoolerTaskListener(SystemUtil.getCurrentContext(), mst, (Component) listener));
else if (listener instanceof UDF)
mst.setListener(new UDFSpoolerTaskListener(SystemUtil.getCurrentContext(), mst, (UDF) listener));
config.getSpoolerEngine().add(mst);
} else
_send(config, servers);
}
use of lucee.runtime.config.ConfigWeb in project Lucee by lucee.
the class Admin method doStopThread.
private void doStopThread() throws PageException {
String contextId = getString("admin", "stopThread", "contextId");
String threadId = getString("admin", "stopThread", "threadId");
String stopType = getString("stopType", "exception");
if (!(config instanceof ConfigServer))
throw new ApplicationException("invalid context for this action");
ConfigServer cs = (ConfigServer) config;
ConfigWeb[] webs = cs.getConfigWebs();
boolean has = false;
for (int i = 0; i < webs.length; i++) {
ConfigWebImpl cw = (ConfigWebImpl) webs[i];
if (!cw.getIdentification().getId().equals(contextId))
continue;
((CFMLFactoryImpl) cw.getFactory()).stopThread(threadId, stopType);
has = true;
break;
}
if (!has) {
for (int i = 0; i < webs.length; i++) {
ConfigWebImpl cw = (ConfigWebImpl) webs[i];
if (!contextId.equals(cw.getLabel()))
continue;
((CFMLFactoryImpl) cw.getFactory()).stopThread(threadId, stopType);
has = true;
break;
}
}
}
Aggregations