Search in sources :

Example 6 with PageSource

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);
}
Also used : MissingIncludeException(lucee.runtime.exp.MissingIncludeException) PageSource(lucee.runtime.PageSource)

Example 7 with PageSource

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() + "&nbsp;</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);
}
Also used : PageException(lucee.runtime.exp.PageException) ConverterException(lucee.runtime.converter.ConverterException) Log(lucee.commons.io.log.Log) DebuggerImpl(lucee.runtime.debug.DebuggerImpl) PageSource(lucee.runtime.PageSource) Abort(lucee.runtime.exp.Abort) Scope(lucee.runtime.type.scope.Scope) DebugTrace(lucee.runtime.debug.DebugTrace) ScriptConverter(lucee.runtime.converter.ScriptConverter) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 8 with PageSource

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;
}
Also used : FileResource(lucee.commons.io.res.type.file.FileResource) PageSource(lucee.runtime.PageSource)

Example 9 with PageSource

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;
}
Also used : Resource(lucee.commons.io.res.Resource) ArrayList(java.util.ArrayList) Component(lucee.runtime.Component) PageSource(lucee.runtime.PageSource) PageSource(lucee.runtime.PageSource) Struct(lucee.runtime.type.Struct)

Example 10 with PageSource

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);
    }
}
Also used : Undefined(lucee.runtime.type.scope.Undefined) Argument(lucee.runtime.type.scope.Argument) Local(lucee.runtime.type.scope.Local) PageContextImpl(lucee.runtime.PageContextImpl) PageSource(lucee.runtime.PageSource) BodyContent(javax.servlet.jsp.tagext.BodyContent) Key(lucee.runtime.type.Collection.Key) LocalImpl(lucee.runtime.type.scope.LocalImpl) UDFCasterException(lucee.runtime.exp.UDFCasterException)

Aggregations

PageSource (lucee.runtime.PageSource)59 PageContextImpl (lucee.runtime.PageContextImpl)19 Resource (lucee.commons.io.res.Resource)16 Struct (lucee.runtime.type.Struct)10 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)8 Mapping (lucee.runtime.Mapping)7 PageException (lucee.runtime.exp.PageException)7 StructImpl (lucee.runtime.type.StructImpl)7 ConfigImpl (lucee.runtime.config.ConfigImpl)6 ConfigWeb (lucee.runtime.config.ConfigWeb)6 ExpressionException (lucee.runtime.exp.ExpressionException)6 ArrayList (java.util.ArrayList)5 Component (lucee.runtime.Component)5 PageSourceCode (lucee.transformer.util.PageSourceCode)5 IOException (java.io.IOException)4 MissingIncludeException (lucee.runtime.exp.MissingIncludeException)4 Array (lucee.runtime.type.Array)4 LitString (lucee.transformer.expression.literal.LitString)4 HTTPResource (lucee.commons.io.res.type.http.HTTPResource)3 Entry (java.util.Map.Entry)2