use of lucee.runtime.PageSource in project Lucee by lucee.
the class Controler method removeOldest.
private void removeOldest(PageSourcePool[] pools) {
PageSourcePool pool = null;
String key = null;
PageSource ps = null;
long date = -1;
for (int i = 0; i < pools.length; i++) {
try {
String[] keys = pools[i].keys();
for (int y = 0; y < keys.length; y++) {
ps = pools[i].getPageSource(keys[y], false);
if (date == -1 || date > ps.getLastAccessTime()) {
pool = pools[i];
key = keys[y];
date = ps.getLastAccessTime();
}
}
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
pools[i].clear();
}
}
if (pool != null)
pool.remove(key);
}
use of lucee.runtime.PageSource in project Lucee by lucee.
the class PageExceptionImpl method _getTagContext.
private static void _getTagContext(Config config, Array tagContext, StackTraceElement[] traces, LinkedList<PageSource> sources) {
// StackTraceElement[] traces = getStackTraceElements(t);
int line = 0;
String template = "", tlast;
Struct item;
StackTraceElement trace = null;
int index = -1;
PageSource ps;
PageContextImpl pc = null;
if (config instanceof ConfigWeb)
pc = (PageContextImpl) ThreadLocalPageContext.get();
for (int i = 0; i < traces.length; i++) {
trace = traces[i];
tlast = template;
template = trace.getFileName();
if (trace.getLineNumber() <= 0 || template == null || ResourceUtil.getExtension(template, "").equals("java"))
continue;
// content
if (!StringUtil.emptyIfNull(tlast).equals(template))
index++;
String[] content = null;
String dspPath = template;
try {
Resource res = config.getResource(template);
if (!res.exists()) {
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())
dspPath = res.getAbsolutePath();
} else
dspPath = res.getAbsolutePath();
} else
dspPath = res.getAbsolutePath();
// class was not build on the local filesystem
if (!res.exists()) {
SourceInfo si = pc != null ? MappingUtil.getMatch(pc, trace) : MappingUtil.getMatch(config, trace);
if (si != null && si.relativePath != null) {
dspPath = si.relativePath;
res = ResourceUtil.toResourceNotExisting(ThreadLocalPageContext.get(), si.relativePath, true, true);
if (!res.exists()) {
PageSource _ps = PageSourceImpl.best(config.getPageSources(ThreadLocalPageContext.get(), null, si.relativePath, false, false, true));
if (_ps != null && _ps.exists()) {
res = _ps.getResource();
if (res != null && res.exists())
dspPath = res.getAbsolutePath();
} else
dspPath = res.getAbsolutePath();
} else
dspPath = res.getAbsolutePath();
}
}
if (res.exists()) {
InputStream is = res.getInputStream();
if (ClassUtil.isBytecode(is)) {
// empty code array to show ??
content = new String[] {};
} else
content = IOUtil.toStringArray(IOUtil.getReader(res, config.getTemplateCharset()));
IOUtil.closeEL(is);
} else {
if (sources.size() > index)
ps = sources.get(index);
else
ps = null;
if (ps != null && trace.getClassName().equals(ps.getClassName())) {
if (ps.physcalExists())
content = IOUtil.toStringArray(IOUtil.getReader(ps.getPhyscalFile(), config.getTemplateCharset()));
template = ps.getDisplayPath();
}
}
} catch (Throwable th) {
}
// check last
if (tagContext.size() > 0) {
try {
Struct last = (Struct) tagContext.getE(tagContext.size());
if (last.get(KeyConstants._Raw_Trace).equals(trace.toString()))
continue;
} catch (Exception e) {
}
}
item = new StructImpl();
line = trace.getLineNumber();
item.setEL(KeyConstants._template, dspPath);
item.setEL(KeyConstants._line, new Double(line));
item.setEL(KeyConstants._id, "??");
item.setEL(KeyConstants._Raw_Trace, trace.toString());
item.setEL(KeyConstants._type, "cfml");
item.setEL(KeyConstants._column, new Double(0));
if (content != null) {
if (content.length > 0) {
item.setEL(KeyConstants._codePrintHTML, getCodePrint(content, line, true));
item.setEL(KeyConstants._codePrintPlain, getCodePrint(content, line, false));
} else {
item.setEL(KeyConstants._codePrintHTML, "??");
item.setEL(KeyConstants._codePrintPlain, "??");
}
} else {
item.setEL(KeyConstants._codePrintHTML, "");
item.setEL(KeyConstants._codePrintPlain, "");
}
// FUTURE id
tagContext.appendEL(item);
}
}
use of lucee.runtime.PageSource in project Lucee by lucee.
the class CustomTagUtil method loadInitFile.
public static InitFile loadInitFile(PageContext pc, String name, InitFile defaultValue) throws PageException {
ConfigImpl config = (ConfigImpl) pc.getConfig();
String[] filenames = getFileNames(config, name);
boolean doCache = config.useCTPathCache();
boolean doCustomTagDeepSearch = config.doCustomTagDeepSearch();
PageSource ps = null;
InitFile initFile;
// CACHE
// check local
String localCacheName = null;
Mapping[] actms = pc.getApplicationContext().getCustomTagMappings();
Mapping[] cctms = config.getCustomTagMappings();
if (doCache) {
if (pc.getConfig().doLocalCustomTag()) {
localCacheName = pc.getCurrentPageSource().getDisplayPath().replace('\\', '/');
localCacheName = "local:" + localCacheName.substring(0, localCacheName.lastIndexOf('/') + 1).concat(name);
initFile = config.getCTInitFile(pc, localCacheName);
if (initFile != null)
return initFile;
}
// cache application mapping
if (actms != null)
for (int i = 0; i < actms.length; i++) {
initFile = config.getCTInitFile(pc, "application:" + actms[i].hashCode() + "/" + name);
if (initFile != null)
return initFile;
}
// cache config mapping
if (cctms != null)
for (int i = 0; i < cctms.length; i++) {
initFile = config.getCTInitFile(pc, "config:" + cctms[i].hashCode() + "/" + name);
if (initFile != null)
return initFile;
}
}
// search local
if (pc.getConfig().doLocalCustomTag()) {
for (int i = 0; i < filenames.length; i++) {
PageSource[] arr = ((PageContextImpl) pc).getRelativePageSources(filenames[i]);
// ps=pc.getRelativePageSource(filenames[i]);
ps = MappingImpl.isOK(arr);
if (ps != null) {
initFile = new InitFile(pc, ps, filenames[i]);
if (doCache)
config.putCTInitFile(localCacheName, initFile);
return initFile;
}
}
}
// search application custom tag mapping
if (actms != null) {
for (int i = 0; i < filenames.length; i++) {
ps = getMapping(actms, filenames[i], doCustomTagDeepSearch);
if (ps != null) {
initFile = new InitFile(pc, ps, filenames[i]);
if (doCache)
config.putCTInitFile("application:" + ps.getMapping().hashCode() + "/" + name, initFile);
return initFile;
}
}
}
// search custom tag mappings
for (int i = 0; i < filenames.length; i++) {
ps = getMapping(cctms, filenames[i], doCustomTagDeepSearch);
if (ps != null) {
initFile = new InitFile(pc, ps, filenames[i]);
if (doCache)
config.putCTInitFile("config:" + ps.getMapping().hashCode() + "/" + name, initFile);
return initFile;
}
}
return defaultValue;
}
use of lucee.runtime.PageSource 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.PageSource 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;
}
Aggregations