use of lucee.runtime.exp.PageExceptionImpl 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);
}
}
}
}
use of lucee.runtime.exp.PageExceptionImpl in project Lucee by lucee.
the class Throw method toPageException.
public static PageException toPageException(Object object, PageException defaultValue) throws PageException {
if ((object instanceof ObjectWrap))
return toPageException(((ObjectWrap) object).getEmbededObject(), defaultValue);
if (object instanceof CatchBlock) {
CatchBlock cb = (CatchBlock) object;
return cb.getPageException();
}
if (object instanceof PageException)
return (PageException) object;
if (object instanceof Throwable) {
Throwable t = (Throwable) object;
return new CustomTypeException(t.getMessage(), "", "", t.getClass().getName(), "");
}
if (object instanceof Struct) {
Struct sct = (Struct) object;
String type = Caster.toString(sct.get(KeyConstants._type, ""), "").trim();
String msg = Caster.toString(sct.get(KeyConstants._message, null), null);
if (!StringUtil.isEmpty(msg, true)) {
String detail = Caster.toString(sct.get(KeyConstants._detail, null), null);
String errCode = Caster.toString(sct.get("ErrorCode", null), null);
String extInfo = Caster.toString(sct.get("ExtendedInfo", null), null);
PageException pe = null;
if ("application".equalsIgnoreCase(type))
pe = new ApplicationException(msg, detail);
else if ("expression".equalsIgnoreCase(type))
pe = new ExpressionException(msg, detail);
else
pe = new CustomTypeException(msg, detail, errCode, type, extInfo);
// Extended Info
if (!StringUtil.isEmpty(extInfo, true))
pe.setExtendedInfo(extInfo);
// Error Code
if (!StringUtil.isEmpty(errCode, true))
pe.setErrorCode(errCode);
// Additional
if (pe instanceof PageExceptionImpl) {
PageExceptionImpl pei = (PageExceptionImpl) pe;
sct = Caster.toStruct(sct.get("additional", null), null);
if (sct != null) {
Iterator<Entry<Key, Object>> it = sct.entryIterator();
Entry<Key, Object> e;
while (it.hasNext()) {
e = it.next();
pei.setAdditional(e.getKey(), e.getValue());
}
}
}
return pe;
}
}
return defaultValue;
}
Aggregations