Search in sources :

Example 1 with FunctionException

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

the class ArrayFindAll method find.

public static Array find(PageContext pc, Array array, UDF udf) throws PageException {
    Array rtn = new ArrayImpl();
    int len = array.size();
    Object[] arr = new Object[1];
    Object res;
    Boolean b;
    for (int i = 1; i <= len; i++) {
        arr[0] = array.get(i, null);
        if (arr[0] != null) {
            res = udf.call(pc, arr, false);
            b = Caster.toBoolean(res, null);
            if (b == null)
                throw new FunctionException(pc, "ArrayFindAll", 2, "function", "return value of the " + (udf instanceof Closure ? "closure" : "function [" + udf.getFunctionName() + "]") + " cannot be casted to a boolean value.", CasterException.createMessage(res, "boolean"));
            if (b.booleanValue()) {
                rtn.appendEL(Caster.toDouble(i));
            }
        }
    }
    return rtn;
}
Also used : Array(lucee.runtime.type.Array) Closure(lucee.runtime.type.Closure) ArrayImpl(lucee.runtime.type.ArrayImpl) FunctionException(lucee.runtime.exp.FunctionException)

Example 2 with FunctionException

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

the class ArrayMid method call.

public static Array call(PageContext pc, Array arr, double start, double count) throws ExpressionException {
    int s = (int) start;
    int c = (int) count;
    if (s < 1)
        throw new FunctionException(pc, "ArrayMid", 2, "start", "Parameter which is now [" + s + "] must be a positive integer");
    if (c == -1)
        c = arr.size();
    else if (c < -1)
        throw new FunctionException(pc, "ArrayMid", 3, "count", "Parameter which is now [" + c + "] must be a non-negative integer or -1 (for string length)");
    c += s - 1;
    if (s > arr.size())
        return new ArrayImpl();
    ArrayImpl rtn = new ArrayImpl();
    int len = arr.size();
    Object value;
    for (int i = s; i <= c && i <= len; i++) {
        value = arr.get(i, null);
        rtn.appendEL(value);
    }
    return rtn;
}
Also used : ArrayImpl(lucee.runtime.type.ArrayImpl) FunctionException(lucee.runtime.exp.FunctionException)

Example 3 with FunctionException

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

the class CacheClear method _call.

private static double _call(PageContext pc, Object filterOrTags, String cacheName) throws PageException {
    try {
        Object filter = FILTER;
        // tags
        boolean isArray = false;
        String dsn = null;
        if ((isArray = Decision.isArray(filterOrTags)) || Decision.isStruct(filterOrTags)) {
            // read tags from collection and datasource (optional)
            String[] tags;
            if (!isArray) {
                Struct sct = Caster.toStruct(filterOrTags);
                Array arr = Caster.toArray(sct.get("tags", null), null);
                if (arr == null)
                    throw new FunctionException(pc, "CacheClear", 1, "tags", "if you pass the tags within a struct, that struct need to have a key [tags] containing the tags in an array.");
                tags = ListUtil.toStringArray(arr);
                dsn = Caster.toString(sct.get(KeyConstants._datasource, null), null);
            } else {
                tags = ListUtil.toStringArray(Caster.toArray(filterOrTags));
            }
            // get default datasource
            if (StringUtil.isEmpty(dsn)) {
                Object tmp = pc.getApplicationContext().getDefDataSource();
                dsn = tmp instanceof CharSequence ? Caster.toString(tmp, null) : null;
            }
            filter = new QueryTagFilter(tags, StringUtil.isEmpty(dsn) ? null : dsn);
        } else // filter
        {
            String strFilter = Caster.toString(filterOrTags);
            if (CacheGetAllIds.isFilter(strFilter))
                filter = new WildCardFilter(strFilter, true);
        }
        Cache cache = CacheUtil.getCache(pc, cacheName, Config.CACHE_TYPE_OBJECT);
        if (filter instanceof CacheKeyFilter)
            return cache.remove((CacheKeyFilter) filter);
        return cache.remove((CacheEntryFilter) filter);
    } catch (Exception e) {
        throw Caster.toPageException(e);
    }
}
Also used : QueryTagFilter(lucee.runtime.cache.util.QueryTagFilter) FunctionException(lucee.runtime.exp.FunctionException) FunctionException(lucee.runtime.exp.FunctionException) PageException(lucee.runtime.exp.PageException) Struct(lucee.runtime.type.Struct) Array(lucee.runtime.type.Array) WildCardFilter(lucee.runtime.cache.util.WildCardFilter) CacheKeyFilter(lucee.commons.io.cache.CacheKeyFilter) Cache(lucee.commons.io.cache.Cache)

Example 4 with FunctionException

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

the class Every method _call.

public static boolean _call(PageContext pc, Object obj, UDF udf, boolean parallel, int maxThreads, short type) throws PageException {
    ExecutorService execute = null;
    List<Future<Data<Object>>> futures = null;
    if (parallel) {
        execute = Executors.newFixedThreadPool(maxThreads);
        futures = new ArrayList<Future<Data<Object>>>();
    }
    boolean res;
    // Array
    if (type == TYPE_ARRAY) {
        res = invoke(pc, (Array) obj, udf, execute, futures);
    } else // Query
    if (type == TYPE_QUERY) {
        res = invoke(pc, (Query) obj, udf, execute, futures);
    } else // Struct
    if (type == TYPE_STRUCT) {
        res = invoke(pc, (Struct) obj, udf, execute, futures);
    } else // Array
    if (obj instanceof Array) {
        res = invoke(pc, (Array) obj, udf, execute, futures);
    } else // Query
    if (obj instanceof Query) {
        res = invoke(pc, (Query) obj, udf, execute, futures);
    } else // Struct
    if (obj instanceof Struct) {
        res = invoke(pc, (Struct) obj, udf, execute, futures);
    } else // other Iteratorable
    if (obj instanceof Iteratorable) {
        res = invoke(pc, (Iteratorable) obj, udf, execute, futures);
    } else // Map
    if (obj instanceof java.util.Map) {
        res = invoke(pc, (java.util.Map) obj, udf, execute, futures);
    } else // List
    if (obj instanceof List) {
        res = invoke(pc, (List) obj, udf, execute, futures);
    } else // Iterator
    if (obj instanceof Iterator) {
        res = invoke(pc, (Iterator) obj, udf, execute, futures);
    } else // Enumeration
    if (obj instanceof Enumeration) {
        res = invoke(pc, (Enumeration) obj, udf, execute, futures);
    } else // String List
    if (obj instanceof StringListData) {
        res = invoke(pc, (StringListData) obj, udf, execute, futures);
    } else
        throw new FunctionException(pc, "Every", 1, "data", "cannot iterate througth this type " + Caster.toTypeName(obj.getClass()));
    if (parallel)
        res = afterCall(pc, futures, execute);
    return res;
}
Also used : Enumeration(java.util.Enumeration) Query(lucee.runtime.type.Query) FunctionException(lucee.runtime.exp.FunctionException) Struct(lucee.runtime.type.Struct) Array(lucee.runtime.type.Array) StringListData(lucee.runtime.type.util.StringListData) Iteratorable(lucee.runtime.type.Iteratorable) ExecutorService(java.util.concurrent.ExecutorService) ListIterator(java.util.ListIterator) ForEachQueryIterator(lucee.runtime.type.it.ForEachQueryIterator) Iterator(java.util.Iterator) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with FunctionException

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

the class Map method _call.

public static Collection _call(PageContext pc, Object obj, UDF udf, boolean parallel, int maxThreads, Query resQry, short type) throws PageException {
    ExecutorService execute = null;
    List<Future<Data<Object>>> futures = null;
    if (parallel) {
        execute = Executors.newFixedThreadPool(maxThreads);
        futures = new ArrayList<Future<Data<Object>>>();
    }
    Collection coll;
    // Array
    if (type == TYPE_ARRAY) {
        coll = invoke(pc, (Array) obj, udf, execute, futures);
    } else // Query
    if (type == TYPE_QUERY) {
        coll = invoke(pc, (Query) obj, udf, execute, futures, resQry);
    } else // Struct
    if (type == TYPE_STRUCT) {
        coll = invoke(pc, (Struct) obj, udf, execute, futures);
    } else // Array
    if (obj instanceof Array) {
        coll = invoke(pc, (Array) obj, udf, execute, futures);
    } else // Query
    if (obj instanceof Query) {
        coll = invoke(pc, (Query) obj, udf, execute, futures, resQry);
    } else // Struct
    if (obj instanceof Struct) {
        coll = invoke(pc, (Struct) obj, udf, execute, futures);
    } else // other Iteratorable
    if (obj instanceof Iteratorable) {
        coll = invoke(pc, (Iteratorable) obj, udf, execute, futures);
    } else // Map
    if (obj instanceof java.util.Map) {
        coll = invoke(pc, (java.util.Map) obj, udf, execute, futures);
    } else // List
    if (obj instanceof List) {
        coll = invoke(pc, (List) obj, udf, execute, futures);
    } else // Iterator
    if (obj instanceof Iterator) {
        coll = invoke(pc, (Iterator) obj, udf, execute, futures);
    } else // Enumeration
    if (obj instanceof Enumeration) {
        coll = invoke(pc, (Enumeration) obj, udf, execute, futures);
    } else // String List
    if (obj instanceof StringListData) {
        coll = invoke(pc, (StringListData) obj, udf, execute, futures);
    } else
        throw new FunctionException(pc, "Map", 1, "data", "cannot iterate througth this type " + Caster.toTypeName(obj.getClass()));
    if (parallel)
        afterCall(pc, coll, futures, execute);
    return coll;
}
Also used : Enumeration(java.util.Enumeration) Query(lucee.runtime.type.Query) FunctionException(lucee.runtime.exp.FunctionException) Struct(lucee.runtime.type.Struct) Array(lucee.runtime.type.Array) StringListData(lucee.runtime.type.util.StringListData) Iteratorable(lucee.runtime.type.Iteratorable) ExecutorService(java.util.concurrent.ExecutorService) ListIterator(java.util.ListIterator) ForEachQueryIterator(lucee.runtime.type.it.ForEachQueryIterator) Iterator(java.util.Iterator) Future(java.util.concurrent.Future) Collection(lucee.runtime.type.Collection) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

FunctionException (lucee.runtime.exp.FunctionException)189 BufferedImage (java.awt.image.BufferedImage)123 Image (lucee.runtime.img.Image)17 Struct (lucee.runtime.type.Struct)13 Array (lucee.runtime.type.Array)12 Resource (lucee.commons.io.res.Resource)10 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)6 Iterator (java.util.Iterator)6 Query (lucee.runtime.type.Query)6 ForEachQueryIterator (lucee.runtime.type.it.ForEachQueryIterator)6 Enumeration (java.util.Enumeration)5 List (java.util.List)5 ListIterator (java.util.ListIterator)5 ExecutorService (java.util.concurrent.ExecutorService)5 Future (java.util.concurrent.Future)5 Iteratorable (lucee.runtime.type.Iteratorable)5 StringListData (lucee.runtime.type.util.StringListData)5 ArrayImpl (lucee.runtime.type.ArrayImpl)4 StructImpl (lucee.runtime.type.StructImpl)4