Search in sources :

Example 56 with ExpressionException

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

the class VideoUtilImpl method procent2pixel.

private static int procent2pixel(String str, int source) throws ExpressionException {
    if (!StringUtil.isEmpty(str)) {
        if (StringUtil.endsWith(str, '%')) {
            str = str.substring(0, str.length() - 1).trim();
            double procent = Caster.toDoubleValue(str);
            if (procent < 0)
                throw new ExpressionException("procent has to be positive number (now " + str + ")");
            return (int) (source * (procent / 100D));
        }
        return Caster.toIntValue(str);
    }
    return -1;
}
Also used : ExpressionException(lucee.runtime.exp.ExpressionException)

Example 57 with ExpressionException

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

the class TagLib method duplicate.

/**
 * duplcate a hashmap with TagLibTag's
 * @param tags
 * @param deepCopy
 * @return cloned map
 */
private HashMap<String, TagLibTag> duplicate(HashMap<String, TagLibTag> tags, boolean deepCopy) {
    if (deepCopy)
        throw new PageRuntimeException(new ExpressionException("deep copy not supported"));
    Iterator<Entry<String, TagLibTag>> it = tags.entrySet().iterator();
    HashMap<String, TagLibTag> cm = new HashMap<String, TagLibTag>();
    Entry<String, TagLibTag> entry;
    while (it.hasNext()) {
        entry = it.next();
        cm.put(entry.getKey(), deepCopy ? // TODO add support for deepcopy ((TagLibTag)entry.getValue()).duplicate(deepCopy):
        entry.getValue() : entry.getValue());
    }
    return cm;
}
Also used : Entry(java.util.Map.Entry) HashMap(java.util.HashMap) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 58 with ExpressionException

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

the class StructSort method call.

public static Array call(PageContext pc, Struct base, String sortType, String sortOrder, String pathToSubElement) throws PageException {
    boolean isAsc = true;
    PageException ee = null;
    if (sortOrder.equalsIgnoreCase("asc"))
        isAsc = true;
    else if (sortOrder.equalsIgnoreCase("desc"))
        isAsc = false;
    else
        throw new ExpressionException("invalid sort order type [" + sortOrder + "], sort order types are [asc and desc]");
    Collection.Key[] keys = CollectionUtil.keys(base);
    SortRegister[] arr = new SortRegister[keys.length];
    boolean hasSubDef = pathToSubElement != null;
    for (int i = 0; i < keys.length; i++) {
        Object value = base.get(keys[i], null);
        if (hasSubDef) {
            value = VariableInterpreter.getVariable(pc, Caster.toCollection(value), pathToSubElement);
        }
        arr[i] = new SortRegister(i, value);
    }
    ExceptionComparator comp = null;
    // text
    if (sortType.equalsIgnoreCase("text"))
        comp = new SortRegisterComparator(pc, isAsc, false, true);
    else // text no case
    if (sortType.equalsIgnoreCase("textnocase"))
        comp = new SortRegisterComparator(pc, isAsc, true, true);
    else // numeric
    if (sortType.equalsIgnoreCase("numeric"))
        comp = new NumberSortRegisterComparator(isAsc);
    else {
        throw new ExpressionException("invalid sort type [" + sortType + "], sort types are [text, textNoCase, numeric]");
    }
    Arrays.sort(arr, 0, arr.length, comp);
    ee = comp.getPageException();
    if (ee != null) {
        throw ee;
    }
    Array rtn = new ArrayImpl();
    for (int i = 0; i < arr.length; i++) {
        rtn.append(keys[arr[i].getOldPosition()].getString());
    }
    return rtn;
}
Also used : PageException(lucee.runtime.exp.PageException) ArrayImpl(lucee.runtime.type.ArrayImpl) ExpressionException(lucee.runtime.exp.ExpressionException) SortRegister(lucee.runtime.type.comparator.SortRegister) ExceptionComparator(lucee.runtime.type.comparator.ExceptionComparator) Array(lucee.runtime.type.Array) SortRegisterComparator(lucee.runtime.type.comparator.SortRegisterComparator) NumberSortRegisterComparator(lucee.runtime.type.comparator.NumberSortRegisterComparator) NumberSortRegisterComparator(lucee.runtime.type.comparator.NumberSortRegisterComparator)

Example 59 with ExpressionException

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

the class CFFunction method call.

// private static Map udfs=new ReferenceMap();
public static Object call(PageContext pc, Object[] objArr) throws PageException {
    if (objArr.length < 3)
        throw new ExpressionException("invalid call of a CFML Based built in function");
    // translate arguments
    String filename = Caster.toString((((FunctionValue) objArr[0]).getValue()));
    Collection.Key name = KeyImpl.toKey((((FunctionValue) objArr[1]).getValue()));
    boolean isweb = Caster.toBooleanValue((((FunctionValue) objArr[2]).getValue()));
    UDF udf = loadUDF(pc, filename, name, isweb);
    Struct meta = udf.getMetaData(pc);
    boolean callerScopes = (meta == null) ? false : Caster.toBooleanValue(meta.get("callerScopes", Boolean.FALSE), false);
    boolean caller = meta == null ? false : Caster.toBooleanValue(meta.get(KeyConstants._caller, Boolean.FALSE), false);
    Struct namedArguments = null, cs = null;
    if (callerScopes) {
        cs = new StructImpl();
        if (pc.undefinedScope().getCheckArguments()) {
            cs.set(KeyConstants._local, pc.localScope().duplicate(false));
            cs.set(KeyConstants._arguments, pc.argumentsScope().duplicate(false));
        }
    }
    Object[] arguments = null;
    if (objArr.length <= 3)
        arguments = ArrayUtil.OBJECT_EMPTY;
    else if (objArr[3] instanceof FunctionValue) {
        FunctionValue fv;
        namedArguments = new StructImpl(Struct.TYPE_LINKED);
        if (callerScopes)
            namedArguments.setEL(KeyConstants._caller, cs);
        else if (caller)
            namedArguments.setEL(KeyConstants._caller, Duplicator.duplicate(pc.undefinedScope(), false));
        for (int i = 3; i < objArr.length; i++) {
            fv = toFunctionValue(name, objArr[i]);
            namedArguments.set(fv.getName(), fv.getValue());
        }
    } else {
        int offset = (caller || callerScopes ? 2 : 3);
        arguments = new Object[objArr.length - offset];
        if (callerScopes)
            arguments[0] = cs;
        else if (caller)
            arguments[0] = Duplicator.duplicate(pc.undefinedScope(), false);
        for (int i = 3; i < objArr.length; i++) {
            arguments[i - offset] = toObject(name, objArr[i]);
        }
    }
    // execute UDF
    if (namedArguments == null) {
        return ((UDFImpl) udf).call(pc, name, arguments, false);
    }
    return ((UDFImpl) udf).callWithNamedValues(pc, name, namedArguments, false);
}
Also used : StructImpl(lucee.runtime.type.StructImpl) UDF(lucee.runtime.type.UDF) FunctionValue(lucee.runtime.type.FunctionValue) Collection(lucee.runtime.type.Collection) ExpressionException(lucee.runtime.exp.ExpressionException) Struct(lucee.runtime.type.Struct) UDFImpl(lucee.runtime.type.UDFImpl)

Example 60 with ExpressionException

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

the class CFFunction method loadUDF.

public static UDF loadUDF(PageContext pc, String filename, Collection.Key name, boolean isweb) throws PageException {
    ConfigWebImpl config = (ConfigWebImpl) pc.getConfig();
    String key = isweb ? name.getString() + config.getIdentification().getId() : name.getString();
    UDF udf = config.getFromFunctionCache(key);
    if (udf != null)
        return udf;
    Mapping mapping = isweb ? config.getFunctionMapping() : config.getServerFunctionMapping();
    Page p = mapping.getPageSource(filename).loadPage(pc, false);
    // execute page
    Variables old = pc.variablesScope();
    pc.setVariablesScope(VAR);
    boolean wasSilent = pc.setSilent();
    try {
        p.call(pc);
        Object o = pc.variablesScope().get(name, null);
        if (o instanceof UDF) {
            udf = (UDF) o;
            config.putToFunctionCache(key, udf);
            return udf;
        }
        throw new ExpressionException("there is no Function defined with name [" + name + "] in template [" + mapping.getStrPhysical() + File.separator + filename + "]");
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        throw Caster.toPageException(t);
    } finally {
        pc.setVariablesScope(old);
        if (!wasSilent)
            pc.unsetSilent();
    }
}
Also used : Variables(lucee.runtime.type.scope.Variables) ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) UDF(lucee.runtime.type.UDF) Mapping(lucee.runtime.Mapping) Page(lucee.runtime.Page) ExpressionException(lucee.runtime.exp.ExpressionException)

Aggregations

ExpressionException (lucee.runtime.exp.ExpressionException)136 Element (org.w3c.dom.Element)24 Key (lucee.runtime.type.Collection.Key)15 SecurityException (lucee.runtime.exp.SecurityException)13 ArrayList (java.util.ArrayList)12 Struct (lucee.runtime.type.Struct)12 List (java.util.List)11 Collection (lucee.runtime.type.Collection)11 Entry (java.util.Map.Entry)10 Node (org.w3c.dom.Node)10 Resource (lucee.commons.io.res.Resource)9 Iterator (java.util.Iterator)8 PageException (lucee.runtime.exp.PageException)8 Map (java.util.Map)7 CasterException (lucee.runtime.exp.CasterException)7 NodeList (org.w3c.dom.NodeList)7 PageContextImpl (lucee.runtime.PageContextImpl)6 PageSource (lucee.runtime.PageSource)5 Casting (lucee.runtime.interpreter.ref.cast.Casting)5 ArrayImpl (lucee.runtime.type.ArrayImpl)5