use of lucee.runtime.exp.FunctionException in project Lucee by lucee.
the class Each method _call.
private static String _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>>>();
}
// Array
if (type == TYPE_ARRAY) {
invoke(pc, (Array) obj, udf, execute, futures);
} else // Query
if (type == TYPE_QUERY) {
invoke(pc, (Query) obj, udf, execute, futures);
} else // Array
if (obj instanceof Array) {
invoke(pc, (Array) obj, udf, execute, futures);
} else // Query
if (obj instanceof Query) {
invoke(pc, (Query) obj, udf, execute, futures);
} else // other Iteratorable
if (obj instanceof Iteratorable) {
invoke(pc, (Iteratorable) obj, udf, execute, futures);
} else // Map
if (obj instanceof Map) {
Iterator it = ((Map) obj).entrySet().iterator();
Entry e;
while (it.hasNext()) {
e = (Entry) it.next();
_call(pc, udf, new Object[] { e.getKey(), e.getValue(), obj }, execute, futures);
// udf.call(pc, new Object[]{e.getKey(),e.getValue()}, true);
}
} else // List
if (obj instanceof List) {
ListIterator it = ((List) obj).listIterator();
int index;
while (it.hasNext()) {
index = it.nextIndex();
_call(pc, udf, new Object[] { it.next(), new Double(index), obj }, execute, futures);
// udf.call(pc, new Object[]{it.next()}, true);
}
} else // Iterator
if (obj instanceof Iterator) {
Iterator it = (Iterator) obj;
while (it.hasNext()) {
_call(pc, udf, new Object[] { it.next() }, execute, futures);
// udf.call(pc, new Object[]{it.next()}, true);
}
} else // Enumeration
if (obj instanceof Enumeration) {
Enumeration e = (Enumeration) obj;
while (e.hasMoreElements()) {
_call(pc, udf, new Object[] { e.nextElement() }, execute, futures);
// udf.call(pc, new Object[]{e.nextElement()}, true);
}
} else // StringListData
if (obj instanceof StringListData) {
invoke(pc, (StringListData) obj, udf, execute, futures);
} else
throw new FunctionException(pc, "Each", 1, "data", "cannot iterate througth this type " + Caster.toTypeName(obj.getClass()));
if (parallel)
afterCall(pc, futures, execute);
return null;
}
use of lucee.runtime.exp.FunctionException in project Lucee by lucee.
the class Filter method _call.
public static Collection _call(PageContext pc, Object obj, UDF udf, boolean parallel, int maxThreads, short type) throws PageException {
ExecutorService execute = null;
List<Future<Data<Pair<Object, Object>>>> futures = null;
if (parallel) {
execute = Executors.newFixedThreadPool(maxThreads);
futures = new ArrayList<Future<Data<Pair<Object, 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);
} 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);
} 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, "Filter", 1, "data", "cannot iterate througth this type " + Caster.toTypeName(obj.getClass()));
if (parallel)
afterCall(pc, coll, futures, execute);
return coll;
}
use of lucee.runtime.exp.FunctionException in project Lucee by lucee.
the class DateConvert method call.
public static DateTime call(PageContext pc, String conversionType, DateTime date) throws FunctionException {
// throw new ApplicationException("This function is no longer supported, because it gives you the wrong impression that the timezone is part of the date object, what is wrong!" +
// "When you wanna convert a Date to String based on the UTC timezone, do for example [DateTimeFormat(date:now(),timezone:'UTC')].");
int offset = pc.getTimeZone().getOffset(date.getTime());
conversionType = conversionType.toLowerCase();
if (conversionType.equals("local2utc")) {
return new DateTimeImpl(pc, date.getTime() - offset, false);
} else if (conversionType.equals("utc2local")) {
return new DateTimeImpl(pc, date.getTime() + offset, false);
}
throw new FunctionException(pc, "DateConvert", 1, "conversionType", "invalid conversion-type [" + conversionType + "] for function dateConvert");
}
use of lucee.runtime.exp.FunctionException in project Lucee by lucee.
the class IsIPInRange method call.
public static boolean call(PageContext pc, Object ips, String ip) throws PageException {
try {
if (ips instanceof String)
return IPRange.getInstance((String) ips).inRange(ip);
Array arr = Caster.toArray(ips, null);
if (arr == null)
throw new FunctionException(pc, "IsIpRange", 1, "ips", "ips must be a string list or a string array");
String[] _ips = new String[arr.size()];
for (int i = 0; i < _ips.length; i++) {
_ips[i] = Caster.toString(arr.getE(i + 1), null);
if (_ips[i] == null)
throw new FunctionException(pc, "IsIpRange", 1, "ips", "element number " + (i + 1) + " in ips array is not a string");
}
return IPRange.getInstance(_ips).inRange(ip);
} catch (IOException e) {
throw Caster.toPageException(e);
}
}
use of lucee.runtime.exp.FunctionException in project Lucee by lucee.
the class FileCopy method call.
public static String call(PageContext pc, Object oSrc, Object oDst) throws PageException {
Resource src = Caster.toResource(pc, oSrc, false);
if (!src.exists())
throw new FunctionException(pc, "FileCopy", 1, "source", "source file [" + src + "] does not exist");
FileTag.actionCopy(pc, pc.getConfig().getSecurityManager(), src, Caster.toString(oDst), FileUtil.NAMECONFLICT_UNDEFINED, null, null, -1, null);
return null;
}
Aggregations