use of lucee.runtime.Page 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.Page in project Lucee by lucee.
the class DebugEntryTemplatePartComparator method writeOut.
@Override
public void writeOut(PageContext pc) throws IOException {
// stop();
if (!output)
return;
String addr = pc.getHttpServletRequest().getRemoteAddr();
lucee.runtime.config.DebugEntry debugEntry = ((ConfigImpl) pc.getConfig()).getDebugEntry(addr, null);
if (debugEntry == null) {
// pc.forceWrite(pc.getConfig().getDefaultDumpWriter().toString(pc,toDumpData(pc, 9999,DumpUtil.toDumpProperties()),true));
return;
}
Struct args = new StructImpl();
args.setEL(KeyConstants._custom, debugEntry.getCustom());
try {
args.setEL(KeyConstants._debugging, pc.getDebugger().getDebuggingData(pc));
} catch (PageException e1) {
}
try {
String path = debugEntry.getPath();
PageSource[] arr = ((PageContextImpl) pc).getPageSources(path);
Page p = PageSourceImpl.loadPage(pc, arr, null);
// patch for old path
String fullname = debugEntry.getFullname();
if (p == null) {
if (path != null) {
boolean changed = false;
if (path.endsWith("/Modern.cfc") || path.endsWith("\\Modern.cfc")) {
path = "/lucee-server-context/admin/debug/Modern.cfc";
fullname = "lucee-server-context.admin.debug.Modern";
changed = true;
} else if (path.endsWith("/Classic.cfc") || path.endsWith("\\Classic.cfc")) {
path = "/lucee-server-context/admin/debug/Classic.cfc";
fullname = "lucee-server-context.admin.debug.Classic";
changed = true;
} else if (path.endsWith("/Comment.cfc") || path.endsWith("\\Comment.cfc")) {
path = "/lucee-server-context/admin/debug/Comment.cfc";
fullname = "lucee-server-context.admin.debug.Comment";
changed = true;
}
if (changed)
pc.write("<span style='color:red'>Please update your debug template defintions in the Lucee admin by going into the detail view and hit the \"update\" button.</span>");
}
arr = ((PageContextImpl) pc).getPageSources(path);
p = PageSourceImpl.loadPage(pc, arr);
}
pc.addPageSource(p.getPageSource(), true);
try {
Component c = pc.loadComponent(fullname);
c.callWithNamedValues(pc, "output", args);
} finally {
pc.removeLastPageSource(true);
}
} catch (PageException e) {
pc.handlePageException(e);
}
}
use of lucee.runtime.Page in project Lucee by lucee.
the class Renderer method loadPage.
private static Page loadPage(ConfigWeb cw, PageSource ps, String cfml, int dialect, boolean ignoreScopes) throws Exception {
String className = HashUtil.create64BitHashAsString(cfml);
// do we already have the page?
Page p = pages.get(className);
if (p != null)
return p;
// load class
Constructor<? extends Page> constr = loadClass(cw, className, cfml, dialect, ignoreScopes).getDeclaredConstructor(PageSource.class);
p = constr.newInstance(ps);
pages.put(className, p);
return p;
}
use of lucee.runtime.Page in project Lucee by lucee.
the class ComponentLoader method _search.
private static Object _search(PageContext pc, PageSource loadingLocation, String rawPath, Boolean searchLocal, Boolean searchRoot, boolean executeConstr, short returnType, final boolean isExtendedComponent) throws PageException {
PageSource currPS = pc.getCurrentPageSource(null);
ImportDefintion[] importDefintions = null;
if (currPS != null) {
Page currP;
Component cfc = pc.getActiveComponent();
if (cfc instanceof ComponentImpl && currPS.equals(cfc.getPageSource())) {
importDefintions = ((ComponentImpl) cfc)._getImportDefintions();
} else if ((currP = currPS.loadPage(pc, false, null)) != null) {
importDefintions = currP.getImportDefintions();
}
}
int dialect = currPS == null ? pc.getCurrentTemplateDialect() : currPS.getDialect();
// first try for the current dialect
Object obj = _search(pc, loadingLocation, rawPath, searchLocal, searchRoot, executeConstr, returnType, currPS, importDefintions, dialect, isExtendedComponent);
// then we try the opposite dialect
if (obj == null && ((ConfigImpl) pc.getConfig()).allowLuceeDialect()) {
// only when the lucee dialect is enabled we have to check the opposite
obj = _search(pc, loadingLocation, rawPath, searchLocal, searchRoot, executeConstr, returnType, currPS, importDefintions, dialect == CFMLEngine.DIALECT_CFML ? CFMLEngine.DIALECT_LUCEE : CFMLEngine.DIALECT_CFML, isExtendedComponent);
}
if (obj == null)
throw new ExpressionException("invalid " + toStringType(returnType, dialect) + " definition, can't find " + toStringType(returnType, dialect) + " [" + rawPath + "]");
return obj;
}
use of lucee.runtime.Page in project Lucee by lucee.
the class ComponentUtil method getPage.
public static Page getPage(PageContext pc, PageSource ps) throws PageException {
PageSourceImpl psi = (PageSourceImpl) ps;
Page p = psi.getPage();
if (p != null) {
// print.o("getPage(existing):"+ps.getDisplayPath()+":"+psi.hashCode()+":"+p.hashCode());
return p;
}
pc = ThreadLocalPageContext.get(pc);
return psi.loadPage(pc, false);
}
Aggregations