use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class Throw method _doStartTag.
private void _doStartTag(Object obj) throws PageException {
if (!StringUtil.isEmpty(obj)) {
PageException pe = toPageException(obj, null);
if (pe != null)
throw pe;
CustomTypeException exception = new CustomTypeException(Caster.toString(obj), detail, errorcode, type, extendedinfo, level);
throw exception;
}
}
use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class Trace method _doEndTag.
public void _doEndTag() throws IOException, PageException {
PageSource ps = pageContext.getCurrentTemplatePageSource();
// var
String varValue = null;
Object value = null, traceValue = null;
if (!StringUtil.isEmpty(var)) {
try {
if (caller instanceof Scope)
value = VariableInterpreter.getVariable(pageContext, var, (Scope) caller);
else
value = pageContext.getVariable(var);
} catch (PageException e) {
varValue = "(undefined)";
follow = false;
}
if (follow) {
// print.o(1);
if (StringUtil.isEmpty(text, true))
text = var;
// print.o(2);
traceValue = TraceObjectSupport.toTraceObject(pageContext.getDebugger(), value, type, category, text);
if (caller instanceof Scope)
VariableInterpreter.setVariable(pageContext, var, traceValue, (Scope) caller);
else
pageContext.setVariable(var, traceValue);
}
try {
varValue = new ScriptConverter().serialize(value);
} catch (ConverterException e) {
if (value != null)
varValue = "(" + Caster.toTypeName(value) + ")";
}
}
DebugTrace trace = ((DebuggerImpl) pageContext.getDebugger()).addTrace(type, category, text, ps, var, varValue);
DebugTrace[] traces = pageContext.getDebugger().getTraces(pageContext);
String total = "(1st trace)";
if (traces.length > 1) {
long t = 0;
for (int i = 0; i < traces.length; i++) {
t += traces[i].getTime();
}
total = "(" + t + ")";
}
boolean hasCat = !StringUtil.isEmpty(trace.getCategory());
boolean hasText = !StringUtil.isEmpty(trace.getText());
boolean hasVar = !StringUtil.isEmpty(var);
// inline
if (inline) {
lucee.runtime.format.TimeFormat tf = new lucee.runtime.format.TimeFormat(pageContext.getConfig().getLocale());
StringBuffer sb = new StringBuffer();
sb.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"white\">");
sb.append("<tr>");
// sb.append("<td><img src=\"/CFIDE/debug/images/Error_16x16.gif\" alt=\"Error type\">");
sb.append("<td>");
sb.append("<font color=\"orange\">");
sb.append("<b>");
sb.append(DebugTraceImpl.toType(trace.getType(), "INFO") + " - ");
sb.append("[CFTRACE " + tf.format(new DateTimeImpl(pageContext.getConfig()), "hh:mm:ss:l") + "]");
sb.append("[" + trace.getTime() + " ms " + total + "]");
sb.append("[" + trace.getTemplate() + " @ line: " + trace.getLine() + "]");
if (hasCat || hasText)
sb.append(" -");
if (hasCat)
sb.append(" [" + trace.getCategory() + "]");
if (hasText)
sb.append(" <i>" + trace.getText() + " </i>");
sb.append("</b>");
sb.append("</font>");
sb.append("</td>");
sb.append("</tr>");
sb.append("</table>");
pageContext.forceWrite(sb.toString());
if (hasVar)
Dump.call(pageContext, value, var);
}
// log
Log log = ((ConfigImpl) pageContext.getConfig()).getLog("trace");
StringBuffer msg = new StringBuffer();
msg.append("[" + trace.getTime() + " ms " + total + "] ");
msg.append("[" + trace.getTemplate() + " @ line: " + trace.getLine() + "]");
if (hasCat || hasText || hasVar)
msg.append("- ");
if (hasCat)
msg.append("[" + trace.getCategory() + "] ");
if (hasVar)
msg.append("[" + var + "=" + varValue + "] ");
if (hasText)
msg.append(" " + trace.getText() + " ");
log.log(trace.getType(), "cftrace", msg.toString());
// abort
if (abort)
throw new Abort(Abort.SCOPE_REQUEST);
}
use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class Update method doEndTag.
@Override
public int doEndTag() throws PageException {
Object ds = DBInfo.getDatasource(pageContext, datasource);
DataSourceManager manager = pageContext.getDataSourceManager();
DatasourceConnection dc = ds instanceof DataSource ? manager.getConnection(pageContext, (DataSource) ds, username, password) : manager.getConnection(pageContext, Caster.toString(ds), username, password);
try {
Struct meta = null;
try {
meta = Insert.getMeta(dc, tablequalifier, tableowner, tablename);
} catch (SQLException se) {
meta = new StructImpl();
}
String[] pKeys = getPrimaryKeys(dc);
SQL sql = createSQL(dc, pKeys, meta);
if (sql != null) {
lucee.runtime.type.Query query = new QueryImpl(pageContext, dc, sql, -1, -1, null, "query");
if (pageContext.getConfig().debug()) {
String dsn = ds instanceof DataSource ? ((DataSource) ds).getName() : Caster.toString(ds);
boolean logdb = ((ConfigImpl) pageContext.getConfig()).hasDebugOptions(ConfigImpl.DEBUG_DATABASE);
if (logdb) {
boolean debugUsage = DebuggerUtil.debugQueryUsage(pageContext, query);
pageContext.getDebugger().addQuery(debugUsage ? query : null, dsn, "", sql, query.getRecordcount(), pageContext.getCurrentPageSource(), query.getExecutionTime());
}
}
// log
Log log = pageContext.getConfig().getLog("datasource");
if (log.getLogLevel() >= Log.LEVEL_INFO) {
log.info("update tag", "executed [" + sql.toString().trim() + "] in " + DecimalFormat.call(pageContext, query.getExecutionTime() / 1000000D) + " ms");
}
}
return EVAL_PAGE;
} catch (PageException pe) {
pageContext.getConfig().getLog("datasource").error("update tag", pe);
throw pe;
} finally {
manager.releaseConnection(pageContext, dc);
}
}
use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class Video method toMpeg.
private Pair toMpeg(VideoInput vi) throws PageException, IOException {
VideoInfo info = getInfo(vi);
if ("mpeg1video".equals(info.getVideoCodec()))
return new Pair(vi.getResource(), toStruct(info));
VideoOutput tmp = new VideoOutputImpl(pageContext.getConfig().getTempDirectory().getRealResource("tmp-" + new Random().nextInt() + ".mpg"));
try {
doActionConvert(vi, tmp, null, null, NAMECONFLICT_ERROR);
return new Pair(tmp.getResource(), toStruct(info));
} catch (PageException pe) {
tmp.getResource().delete();
throw pe;
} catch (IOException ioe) {
tmp.getResource().delete();
throw ioe;
}
}
use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class XMLCaster method writeTo.
public static void writeTo(Node node, Result res, boolean omitXMLDecl, boolean indent, String publicId, String systemId, String encoding) throws PageException {
try {
Transformer t = XMLUtil.getTransformerFactory().newTransformer();
t.setOutputProperty(OutputKeys.INDENT, indent ? "yes" : "no");
t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, omitXMLDecl ? "yes" : "no");
// optional properties
if (!StringUtil.isEmpty(publicId, true))
t.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, publicId);
if (!StringUtil.isEmpty(systemId, true))
t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, systemId);
if (!StringUtil.isEmpty(encoding, true))
t.setOutputProperty(OutputKeys.ENCODING, encoding);
t.transform(new DOMSource(node), res);
} catch (Exception e) {
throw Caster.toPageException(e);
}
}
Aggregations