Search in sources :

Example 16 with PageRuntimeException

use of lucee.runtime.exp.PageRuntimeException in project Lucee by lucee.

the class AbstrCFMLExprTransformer method getFunctionMember.

/**
 * Liest die Argumente eines Funktonsaufruf ein und prueft ob die Funktion
 * innerhalb der FLD (Function Library Descriptor) definiert ist.
 * Falls sie existiert wird die Funktion gegen diese geprueft und ein build-in-function CFXD Element generiert,
 * ansonsten ein normales funcion-call Element.
 * <br />
 * EBNF:<br />
 * <code>[impOp{"," impOp}];</code>
 * @param name Identifier der Funktion als Zeichenkette
 * @param checkLibrary Soll geprueft werden ob die Funktion innerhalb der Library existiert.
 * @return CFXD Element
 * @throws TemplateException
 */
private FunctionMember getFunctionMember(ExprData data, final ExprString name, boolean checkLibrary) throws TemplateException {
    // get Function Library
    checkLibrary = checkLibrary && data.flibs != null;
    FunctionLibFunction flf = null;
    if (checkLibrary) {
        if (!(name instanceof Literal))
            // should never happen!
            throw new TemplateException(data.srcCode, "syntax error");
        for (int i = 0; i < data.flibs.length; i++) {
            flf = data.flibs[i].getFunction(((Literal) name).getString());
            if (flf != null)
                break;
        }
        if (flf == null) {
            checkLibrary = false;
        }
    }
    FunctionMember fm = null;
    while (true) {
        int pos = data.srcCode.getPos();
        // Element Function
        if (checkLibrary) {
            BIF bif = new BIF(data.factory, data.settings, flf);
            // TODO data.ep.add(flf, bif, data.srcCode);
            bif.setArgType(flf.getArgType());
            try {
                bif.setClassDefinition(flf.getFunctionClassDefinition());
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
                throw new PageRuntimeException(t);
            }
            bif.setReturnType(flf.getReturnTypeAsString());
            fm = bif;
            if (flf.getArgType() == FunctionLibFunction.ARG_DYNAMIC && flf.hasDefaultValues()) {
                ArrayList<FunctionLibFunctionArg> args = flf.getArg();
                Iterator<FunctionLibFunctionArg> it = args.iterator();
                FunctionLibFunctionArg arg;
                while (it.hasNext()) {
                    arg = it.next();
                    if (arg.getDefaultValue() != null)
                        bif.addArgument(new NamedArgument(data.factory.createLitString(arg.getName()), data.factory.createLitString(arg.getDefaultValue()), arg.getTypeAsString(), false));
                }
            }
        } else {
            fm = new UDF(name);
        }
        int count = getFunctionMemberAttrs(data, name, checkLibrary, fm, flf);
        if (checkLibrary) {
            // pre
            if (flf.hasTteClass()) {
                FunctionLibFunction tmp = flf.getEvaluator().pre((BIF) fm, flf);
                if (tmp != null && tmp != flf) {
                    flf = tmp;
                    data.srcCode.setPos(pos);
                    continue;
                }
            }
            // check max attributes
            {
                boolean isDynamic = flf.getArgType() == FunctionLibFunction.ARG_DYNAMIC;
                int max = flf.getArgMax();
                // Dynamic
                if (isDynamic) {
                    if (max != -1 && max < fm.getArguments().length)
                        throw new TemplateException(data.srcCode, "too many Attributes (" + max + ":" + fm.getArguments().length + ") in function [ " + ASMUtil.display(name) + " ]");
                } else // Fix
                {
                    if (flf.getArg().size() < fm.getArguments().length) {
                        TemplateException te = new TemplateException(data.srcCode, "too many Attributes (" + flf.getArg().size() + ":" + fm.getArguments().length + ") in function call [" + ASMUtil.display(name) + "]");
                        UDFUtil.addFunctionDoc(te, flf);
                        throw te;
                    }
                }
            }
            // check min attributes
            if (flf.getArgMin() > count) {
                TemplateException te = new TemplateException(data.srcCode, "too few attributes in function [" + ASMUtil.display(name) + "]");
                if (flf.getArgType() == FunctionLibFunction.ARG_FIX)
                    UDFUtil.addFunctionDoc(te, flf);
                throw te;
            }
            // evaluator
            if (flf.hasTteClass()) {
                flf.getEvaluator().execute((BIF) fm, flf);
            }
        }
        comments(data);
        if (checkLibrary)
            data.ep.add(flf, (BIF) fm, data.srcCode);
        break;
    }
    return fm;
}
Also used : TemplateException(lucee.runtime.exp.TemplateException) FunctionMember(lucee.transformer.bytecode.expression.var.FunctionMember) UDF(lucee.transformer.bytecode.expression.var.UDF) FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) Literal(lucee.transformer.expression.literal.Literal) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) NamedArgument(lucee.transformer.bytecode.expression.var.NamedArgument) BIF(lucee.transformer.bytecode.expression.var.BIF) FunctionLibFunctionArg(lucee.transformer.library.function.FunctionLibFunctionArg)

Example 17 with PageRuntimeException

use of lucee.runtime.exp.PageRuntimeException in project Lucee by lucee.

the class AbstrCFMLExprTransformer method json.

protected Expression json(ExprData data, FunctionLibFunction flf, char start, char end) throws TemplateException {
    if (!data.srcCode.forwardIfCurrent(start))
        return null;
    Position line = data.srcCode.getPosition();
    data.srcCode.removeSpace();
    // [:|=]
    if (data.srcCode.forwardIfCurrent(':', ']') || data.srcCode.forwardIfCurrent('=', ']')) {
        flf = flf.getFunctionLib().getFunction("_literalOrderedStruct");
        BIF bif = new BIF(data.factory, data.settings, flf);
        bif.setArgType(flf.getArgType());
        try {
            bif.setClassDefinition(flf.getFunctionClassDefinition());
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
            throw new PageRuntimeException(t);
        }
        bif.setReturnType(flf.getReturnTypeAsString());
        data.ep.add(flf, bif, data.srcCode);
        Variable var = data.factory.createVariable(line, data.srcCode.getPosition());
        var.addMember(bif);
        return var;
    }
    BIF bif = new BIF(data.factory, data.settings, flf);
    bif.setArgType(flf.getArgType());
    try {
        bif.setClassDefinition(flf.getFunctionClassDefinition());
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        throw new PageRuntimeException(t);
    }
    bif.setReturnType(flf.getReturnTypeAsString());
    do {
        comments(data);
        if (data.srcCode.isCurrent(end))
            break;
        bif.addArgument(functionArgument(data, data.settings.dotNotationUpper));
        comments(data);
    } while (data.srcCode.forwardIfCurrent(','));
    comments(data);
    if (!data.srcCode.forwardIfCurrent(end))
        throw new TemplateException(data.srcCode, "Invalid Syntax Closing [" + end + "] not found");
    comments(data);
    if (flf.hasTteClass()) {
        FunctionLibFunction tmp = flf.getEvaluator().pre(bif, flf);
        if (tmp != null && tmp != flf) {
            bif.setFlf(flf = tmp);
            bif.setArgType(flf.getArgType());
            try {
                bif.setClassDefinition(flf.getFunctionClassDefinition());
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
                throw new PageRuntimeException(t);
            }
            bif.setReturnType(flf.getReturnTypeAsString());
        }
    }
    data.ep.add(flf, bif, data.srcCode);
    Variable var = data.factory.createVariable(line, data.srcCode.getPosition());
    var.addMember(bif);
    return var;
}
Also used : OpVariable(lucee.transformer.bytecode.op.OpVariable) Variable(lucee.transformer.expression.var.Variable) Position(lucee.transformer.Position) TemplateException(lucee.runtime.exp.TemplateException) FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) BIF(lucee.transformer.bytecode.expression.var.BIF)

Example 18 with PageRuntimeException

use of lucee.runtime.exp.PageRuntimeException in project Lucee by lucee.

the class XMLEventParser method error.

/**
 * call back error function if a error occour
 * @param pe
 */
private void error(PageException pe) {
    if (error == null)
        throw new PageRuntimeException(pe);
    try {
        pc = ThreadLocalPageContext.get(pc);
        error.call(pc, new Object[] { pe.getCatchBlock(pc.getConfig()) }, false);
    } catch (PageException e) {
    }
}
Also used : PageException(lucee.runtime.exp.PageException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException)

Example 19 with PageRuntimeException

use of lucee.runtime.exp.PageRuntimeException in project Lucee by lucee.

the class CFMLResourceProvider method callResourceArrayRTE.

Resource[] callResourceArrayRTE(PageContext pc, Component component, String methodName, Object[] args) {
    pc = ThreadLocalPageContext.get(pc);
    try {
        Array arr = Caster.toArray(call(pc, getCFC(pc, component), methodName, args));
        Iterator<Object> it = arr.valueIterator();
        CFMLResource[] resources = new CFMLResource[arr.size()];
        int index = 0;
        while (it.hasNext()) {
            resources[index++] = new CFMLResource(this, Caster.toComponent(it.next()));
        }
        return resources;
    } catch (PageException pe) {
        throw new PageRuntimeException(pe);
    }
}
Also used : Array(lucee.runtime.type.Array) PageException(lucee.runtime.exp.PageException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException)

Example 20 with PageRuntimeException

use of lucee.runtime.exp.PageRuntimeException in project Lucee by lucee.

the class DatasourceResource method listResources.

@Override
public Resource[] listResources() {
    if (!attr().isDirectory())
        return null;
    String path;
    if (parent == null)
        path = "/";
    else
        path = parent.concat(name).concat("/");
    Attr[] children = null;
    try {
        children = provider.getAttrs(data, path.hashCode(), path);
    } catch (PageException e) {
        throw new PageRuntimeException(e);
    }
    if (children == null)
        return new Resource[0];
    Resource[] attrs = new Resource[children.length];
    for (int i = 0; i < children.length; i++) {
        // TODO optimieren, alle attr mitgeben
        attrs[i] = new DatasourceResource(provider, data, path + children[i].getName());
    }
    return attrs;
}
Also used : PageException(lucee.runtime.exp.PageException) Resource(lucee.commons.io.res.Resource) PageRuntimeException(lucee.runtime.exp.PageRuntimeException)

Aggregations

PageRuntimeException (lucee.runtime.exp.PageRuntimeException)37 PageException (lucee.runtime.exp.PageException)17 Method (java.lang.reflect.Method)7 SQLException (java.sql.SQLException)7 DOMException (org.w3c.dom.DOMException)7 IOException (java.io.IOException)4 Entry (java.util.Map.Entry)4 Pair (lucee.commons.lang.Pair)4 DatasourceConnection (lucee.runtime.db.DatasourceConnection)4 DatabaseException (lucee.runtime.exp.DatabaseException)4 DeprecatedException (lucee.runtime.exp.DeprecatedException)4 ORMDatasourceConnection (lucee.runtime.orm.ORMDatasourceConnection)4 HashMap (java.util.HashMap)3 ApplicationException (lucee.runtime.exp.ApplicationException)3 TemplateException (lucee.runtime.exp.TemplateException)3 Array (lucee.runtime.type.Array)3 Struct (lucee.runtime.type.Struct)3 BIF (lucee.transformer.bytecode.expression.var.BIF)3 Iterator (java.util.Iterator)2 Resource (lucee.commons.io.res.Resource)2