use of lucee.runtime.PageSource in project Lucee by lucee.
the class ModernAppListener method onRequest.
@Override
public void onRequest(PageContext pc, PageSource requestedPage, RequestListener rl) throws PageException {
// on requestStart
PageSource appPS = AppListenerUtil.getApplicationPageSource(pc, requestedPage, pc.getRequestDialect() == CFMLEngine.DIALECT_CFML ? Constants.CFML_APPLICATION_EVENT_HANDLER : Constants.LUCEE_APPLICATION_EVENT_HANDLER, mode);
_onRequest(pc, requestedPage, appPS, rl);
}
use of lucee.runtime.PageSource in project Lucee by lucee.
the class ModernAppListener method _onRequest.
protected void _onRequest(PageContext pc, PageSource requestedPage, PageSource appPS, RequestListener rl) throws PageException {
PageContextImpl pci = (PageContextImpl) pc;
pci.setAppListenerType(ApplicationListener.TYPE_MODERN);
if (appPS != null) {
String callPath = appPS.getComponentName();
Component app = ComponentLoader.loadComponent(pci, appPS, callPath, false, false);
// init
ModernApplicationContext appContext = initApplicationContext(pci, app);
apps.put(appContext.getName(), app);
if (!pci.initApplicationContext(this))
return;
if (rl != null) {
requestedPage = rl.execute(pc, requestedPage);
if (requestedPage == null)
return;
}
String targetPage = requestedPage.getRealpathWithVirtual();
RefBoolean goon = new RefBooleanImpl(true);
// onRequestStart
if (app.contains(pc, ON_REQUEST_START)) {
try {
Object rtn = call(app, pci, ON_REQUEST_START, new Object[] { targetPage }, false);
if (!Caster.toBooleanValue(rtn, true))
return;
} catch (PageException pe) {
pe = handlePageException(pci, app, pe, requestedPage, targetPage, goon);
if (pe != null)
throw pe;
}
}
// onRequest
if (goon.toBooleanValue()) {
boolean isComp = isComponent(pc, requestedPage);
Object method;
if (isComp && app.contains(pc, ON_CFCREQUEST) && (method = pc.urlFormScope().get(KeyConstants._method, null)) != null) {
Struct url = (Struct) Duplicator.duplicate(pc.urlFormScope(), true);
url.removeEL(KeyConstants._fieldnames);
url.removeEL(KeyConstants._method);
Object args = url.get(KeyConstants._argumentCollection, null);
// url returnFormat
Object oReturnFormat = url.removeEL(KeyConstants._returnFormat);
int urlReturnFormat = -1;
if (oReturnFormat != null)
urlReturnFormat = UDFUtil.toReturnFormat(Caster.toString(oReturnFormat, null), -1);
// request header accept
List<MimeType> accept = ReqRspUtil.getAccept(pc);
int headerReturnFormat = MimeType.toFormat(accept, -1, -1);
Object queryFormat = url.removeEL(KeyConstants._queryFormat);
if (args == null) {
args = pc.getHttpServletRequest().getAttribute("argumentCollection");
}
if (args instanceof String) {
args = new JSONExpressionInterpreter().interpret(pc, (String) args);
}
if (args != null) {
if (Decision.isCastableToStruct(args)) {
Struct sct = Caster.toStruct(args, false);
// Key[] keys = url.keys();
Iterator<Entry<Key, Object>> it = url.entryIterator();
Entry<Key, Object> e;
while (it.hasNext()) {
e = it.next();
sct.setEL(e.getKey(), e.getValue());
}
args = sct;
} else if (Decision.isCastableToArray(args)) {
args = Caster.toArray(args);
} else {
Array arr = new ArrayImpl();
arr.appendEL(args);
args = arr;
}
} else
args = url;
Object rtn = call(app, pci, ON_CFCREQUEST, new Object[] { requestedPage.getComponentName(), method, args }, true);
if (rtn != null) {
if (pc.getHttpServletRequest().getHeader("AMF-Forward") != null) {
pc.variablesScope().setEL("AMF-Forward", rtn);
// ThreadLocalWDDXResult.set(rtn);
} else {
try {
ComponentPageImpl.writeToResponseStream(pc, app, method.toString(), urlReturnFormat, headerReturnFormat, queryFormat, rtn);
} catch (Exception e) {
throw Caster.toPageException(e);
}
}
}
} else {
// TODO impl die nicht so generisch ist
try {
if (!isComp && app.contains(pc, ON_REQUEST))
call(app, pci, ON_REQUEST, new Object[] { targetPage }, false);
else
pci._doInclude(new PageSource[] { requestedPage }, false, null);
} catch (PageException pe) {
pe = handlePageException(pci, app, pe, requestedPage, targetPage, goon);
if (pe != null)
throw pe;
}
}
}
// onRequestEnd
if (goon.toBooleanValue() && app.contains(pc, ON_REQUEST_END)) {
try {
call(app, pci, ON_REQUEST_END, new Object[] { targetPage }, false);
} catch (PageException pe) {
pe = handlePageException(pci, app, pe, requestedPage, targetPage, goon);
if (pe != null)
throw pe;
}
}
} else {
apps.put(pc.getApplicationContext().getName(), null);
if (rl != null) {
requestedPage = rl.execute(pc, requestedPage);
if (requestedPage == null)
return;
}
pci._doInclude(new PageSource[] { requestedPage }, false, null);
}
}
use of lucee.runtime.PageSource in project Lucee by lucee.
the class CallStackGet method abs.
private static String abs(PageContextImpl pc, String template) {
ConfigWeb config = pc.getConfig();
Resource res = config.getResource(template);
if (res.exists())
return template;
PageSource ps = pc == null ? null : pc.getPageSource(template);
res = ps == null ? null : ps.getPhyscalFile();
if (res == null || !res.exists()) {
res = config.getResource(ps.getDisplayPath());
if (res != null && res.exists())
return res.getAbsolutePath();
} else
return res.getAbsolutePath();
return template;
}
use of lucee.runtime.PageSource in project Lucee by lucee.
the class ContractPath method call.
public static String call(PageContext pc, String absPath, boolean placeHolder) {
Resource res = ResourceUtil.toResourceNotExisting(pc, absPath);
if (!res.exists())
return absPath;
if (placeHolder) {
String cp = SystemUtil.addPlaceHolder(res, null);
if (!StringUtil.isEmpty(cp))
return cp;
}
// Config config=pc.getConfig();
PageSource ps = pc.toPageSource(res, null);
if (ps == null)
return absPath;
String realPath = ps.getRealpath();
realPath = realPath.replace('\\', '/');
if (StringUtil.endsWith(realPath, '/'))
realPath = realPath.substring(0, realPath.length() - 1);
String mapping = ps.getMapping().getVirtual();
mapping = mapping.replace('\\', '/');
if (StringUtil.endsWith(mapping, '/'))
mapping = mapping.substring(0, mapping.length() - 1);
return mapping + realPath;
}
Aggregations