Search in sources :

Example 96 with FunctionException

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;
}
Also used : Enumeration(java.util.Enumeration) Query(lucee.runtime.type.Query) FunctionException(lucee.runtime.exp.FunctionException) ListIterator(java.util.ListIterator) Array(lucee.runtime.type.Array) Entry(java.util.Map.Entry) 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) Map(java.util.Map)

Example 97 with FunctionException

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;
}
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) Pair(lucee.commons.lang.Pair)

Example 98 with FunctionException

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");
}
Also used : FunctionException(lucee.runtime.exp.FunctionException) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl)

Example 99 with FunctionException

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);
    }
}
Also used : Array(lucee.runtime.type.Array) FunctionException(lucee.runtime.exp.FunctionException) IOException(java.io.IOException)

Example 100 with FunctionException

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;
}
Also used : Resource(lucee.commons.io.res.Resource) FunctionException(lucee.runtime.exp.FunctionException)

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