use of lucee.runtime.PageSource in project Lucee by lucee.
the class Error method setTemplate.
/**
* set the value template
* The relative path to the custom error page.
* @param template value to set
* @throws MissingIncludeException
*/
public void setTemplate(String template) throws MissingIncludeException {
PageSource ps = pageContext.getCurrentPageSource().getRealPage(template);
if (!ps.exists())
throw new MissingIncludeException(ps);
errorPage.setTemplate(ps);
}
use of lucee.runtime.PageSource 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.PageSource in project Lucee by lucee.
the class VideoPlayerJW method toPath.
private String toPath(Resource res) {
if (!(res instanceof FileResource))
return res.getAbsolutePath();
// Config config=pageContext.getConfig();
PageSource ps = pageContext.toPageSource(res, null);
if (ps == null)
return res.getAbsolutePath();
String realPath = ps.getRealpath();
realPath = realPath.replace('\\', '/');
if (realPath.endsWith("/"))
realPath = realPath.substring(0, realPath.length() - 1);
// print.out("real:"+realPath);
String mapping = ps.getMapping().getVirtual();
mapping = mapping.replace('\\', '/');
if (mapping.endsWith("/"))
mapping = mapping.substring(0, mapping.length() - 1);
return mapping + realPath;
}
use of lucee.runtime.PageSource in project Lucee by lucee.
the class Mapping method _init.
private static ArrayList<Source> _init(PageContext pc, Mapping mapping, Resource dir) throws PageException {
Resource[] children = dir.listResources(FILTER);
RestSettings settings = pc.getApplicationContext().getRestSettings();
ArrayList<Source> sources = new ArrayList<Source>();
PageSource ps;
Component cfc;
Struct meta;
String path;
for (int i = 0; i < children.length; i++) {
try {
ps = pc.toPageSource(children[i], null);
cfc = ComponentLoader.loadComponent(pc, ps, children[i].getName(), true, true);
meta = cfc.getMetaData(pc);
if (Caster.toBooleanValue(meta.get(KeyConstants._rest, null), false)) {
path = Caster.toString(meta.get(KeyConstants._restPath, null), null);
sources.add(new Source(mapping, cfc.getPageSource(), path));
}
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
if (!settings.getSkipCFCWithError())
throw Caster.toPageException(t);
}
}
return sources;
}
use of lucee.runtime.PageSource in project Lucee by lucee.
the class UDFImpl method _call.
private Object _call(PageContext pc, Collection.Key calledName, Object[] args, Struct values, boolean doIncludePath) throws PageException {
// print.out(count++);
PageContextImpl pci = (PageContextImpl) pc;
Argument newArgs = pci.getScopeFactory().getArgumentInstance();
newArgs.setFunctionArgumentNames(properties.getArgumentsSet());
LocalImpl newLocal = pci.getScopeFactory().getLocalInstance();
Undefined undefined = pc.undefinedScope();
Argument oldArgs = pc.argumentsScope();
Local oldLocal = pc.localScope();
Collection.Key oldCalledName = pci.getActiveUDFCalledName();
pc.setFunctionScopes(newLocal, newArgs);
pci.setActiveUDFCalledName(calledName);
int oldCheckArgs = undefined.setMode(pc.getCurrentTemplateDialect() == CFMLEngine.DIALECT_CFML ? (properties.getLocalMode() == null ? pc.getApplicationContext().getLocalMode() : properties.getLocalMode().intValue()) : Undefined.MODE_LOCAL_OR_ARGUMENTS_ALWAYS);
PageSource ps = null;
PageSource psInc = null;
try {
ps = properties.getPageSource();
if (doIncludePath)
psInc = ps;
if (doIncludePath && getOwnerComponent() != null) {
psInc = ComponentUtil.getPageSource(getOwnerComponent());
if (psInc == pci.getCurrentTemplatePageSource()) {
psInc = null;
}
}
if (ps != null)
pci.addPageSource(ps, psInc);
pci.addUDF(this);
// ////////////////////////////////////////
BodyContent bc = null;
Boolean wasSilent = null;
boolean bufferOutput = getBufferOutput(pci);
if (!getOutput()) {
if (bufferOutput)
bc = pci.pushBody();
else
wasSilent = pc.setSilent() ? Boolean.TRUE : Boolean.FALSE;
}
UDF parent = null;
if (ownerComponent != null) {
parent = pci.getActiveUDF();
pci.setActiveUDF(this);
}
Object returnValue = null;
try {
if (args != null)
defineArguments(pc, getFunctionArguments(), args, newArgs);
else
defineArguments(pc, getFunctionArguments(), values, newArgs);
returnValue = implementation(pci);
if (ownerComponent != null)
pci.setActiveUDF(parent);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
if (ownerComponent != null)
pci.setActiveUDF(parent);
if (!getOutput()) {
if (bufferOutput)
BodyContentUtil.flushAndPop(pc, bc);
else if (!wasSilent)
pc.unsetSilent();
}
// BodyContentUtil.flushAndPop(pc,bc);
throw Caster.toPageException(t);
}
if (!getOutput()) {
if (bufferOutput)
BodyContentUtil.clearAndPop(pc, bc);
else if (!wasSilent)
pc.unsetSilent();
}
if (returnValue == null && pc.getConfig().getFullNullSupport())
return returnValue;
if (properties.getReturnType() == CFTypes.TYPE_ANY || !((PageContextImpl) pc).getTypeChecking())
return returnValue;
if (Decision.isCastableTo(properties.getReturnTypeAsString(), returnValue, false, false, -1))
return returnValue;
throw new UDFCasterException(this, properties.getReturnTypeAsString(), returnValue);
// REALCAST return Caster.castTo(pageContext,returnType,returnValue,false);
// ////////////////////////////////////////
} finally {
if (ps != null)
pc.removeLastPageSource(psInc != null);
pci.removeUDF();
pci.setFunctionScopes(oldLocal, oldArgs);
pci.setActiveUDFCalledName(oldCalledName);
undefined.setMode(oldCheckArgs);
pci.getScopeFactory().recycle(pci, newArgs);
pci.getScopeFactory().recycle(pci, newLocal);
}
}
Aggregations