use of lucee.runtime.PageSource 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.PageSource in project Lucee by lucee.
the class TagUtil method addTagMetaData.
private static void addTagMetaData(PageContext pc, TagLib tl, TagLibTag tlt, String filename, boolean isWeb) {
if (pc == null)
return;
try {
ConfigWebImpl config = (ConfigWebImpl) pc.getConfig();
PageSource ps = isWeb ? config.getTagMapping().getPageSource(filename) : config.getServerTagMapping().getPageSource(filename);
// Page p = ps.loadPage(pc);
ComponentImpl c = ComponentLoader.loadComponent(pc, ps, filename, true, true);
ComponentSpecificAccess cw = ComponentSpecificAccess.toComponentSpecificAccess(Component.ACCESS_PRIVATE, c);
Struct meta = Caster.toStruct(cw.get(KeyConstants._metadata, null), null);
// TODO handle all metadata here and make checking at runtime useless
if (meta != null) {
// parse body
boolean rtexprvalue = Caster.toBooleanValue(meta.get(KeyConstants._parsebody, Boolean.FALSE), false);
tlt.setParseBody(rtexprvalue);
// hint
String hint = Caster.toString(meta.get(KeyConstants._hint, null), null);
if (!StringUtil.isEmpty(hint))
tlt.setDescription(hint);
}
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
}
use of lucee.runtime.PageSource in project Lucee by lucee.
the class Admin method doGetError.
private void doGetError() throws PageException {
Struct sct = new StructImpl();
pageContext.setVariable(getString("admin", action, "returnVariable"), sct);
// sct.set("errorTemplate",config.getErrorTemplate());
Struct templates = new StructImpl();
Struct str = new StructImpl();
sct.set(TEMPLATES, templates);
sct.set(STR, str);
sct.set(DO_STATUS_CODE, Caster.toBoolean(config.getErrorStatusCode()));
// 500
String template = config.getErrorTemplate(500);
try {
PageSource ps = ((PageContextImpl) pageContext).getPageSourceExisting(template);
if (ps != null)
templates.set("500", ps.getDisplayPath());
else
templates.set("500", "");
} catch (PageException e) {
templates.set("500", "");
}
str.set("500", template);
// 404
template = config.getErrorTemplate(404);
try {
PageSource ps = ((PageContextImpl) pageContext).getPageSourceExisting(template);
if (ps != null)
templates.set("404", ps.getDisplayPath());
else
templates.set("404", "");
} catch (PageException e) {
templates.set("404", "");
}
str.set("404", template);
}
use of lucee.runtime.PageSource in project Lucee by lucee.
the class Admin method doAddDump.
private void doAddDump() throws ApplicationException {
Debugger debugger = pageContext.getDebugger();
PageSource ps = pageContext.getCurrentTemplatePageSource();
if (ps != null)
debugger.addDump(ps, getString("admin", action, "dump", true));
}
use of lucee.runtime.PageSource in project Lucee by lucee.
the class Admin method doCompileFile.
private void doCompileFile(Mapping mapping, Resource file, String path, Map<String, String> errors, Boolean explicitIgnoreScope) throws PageException {
if (ResourceUtil.exists(file)) {
if (file.isDirectory()) {
Resource[] files = file.listResources(FILTER_CFML_TEMPLATES);
if (files != null)
for (int i = 0; i < files.length; i++) {
String p = path + '/' + files[i].getName();
// print.ln(files[i]+" - "+p);
doCompileFile(mapping, files[i], p, errors, explicitIgnoreScope);
}
} else if (file.isFile()) {
PageSource ps = mapping.getPageSource(path);
PageContextImpl pci = (PageContextImpl) pageContext;
boolean envIgnoreScopes = pci.ignoreScopes();
try {
if (explicitIgnoreScope != null)
pci.setIgnoreScopes(explicitIgnoreScope);
((PageSourceImpl) ps).clear();
((PageSourceImpl) ps).loadPage(pageContext, explicitIgnoreScope != null);
// pageContext.compile(ps);
} catch (PageException pe) {
SystemOut.printDate(pe);
String template = ps.getDisplayPath();
StringBuilder msg = new StringBuilder(pe.getMessage());
msg.append(", Error Occurred in File [");
msg.append(template);
if (pe instanceof PageExceptionImpl) {
try {
PageExceptionImpl pei = (PageExceptionImpl) pe;
Array context = pei.getTagContext(config);
if (context.size() > 0) {
msg.append(":");
msg.append(Caster.toString(((Struct) context.getE(1)).get("line")));
}
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
}
msg.append("]");
if (errors != null)
errors.put(template, msg.toString());
else
throw new ApplicationException(msg.toString());
} finally {
pci.setIgnoreScopes(envIgnoreScopes);
}
}
}
}
Aggregations