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;
}
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;
}
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);
}
}
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;
}
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;
}
Aggregations