Search in sources :

Example 91 with FunctionException

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

the class ImageWrite method call.

public static String call(PageContext pc, Object name, String destination, double quality, boolean overwrite) throws PageException {
    // if(name instanceof String)name=pc.getVariable(Caster.toString(name));
    Image image = Image.toImage(pc, name);
    if (quality < 0 || quality > 1)
        throw new FunctionException(pc, "ImageWrite", 3, "quality", "value have to be between 0 and 1");
    Resource res = StringUtil.isEmpty(destination) ? image.getSource() : ResourceUtil.toResourceNotExisting(pc, destination);
    // MUST beide boolschen argumente checken
    if (res == null)
        return null;
    try {
        image.writeOut(res, overwrite, (float) quality);
    } catch (IOException e) {
        throw Caster.toPageException(e);
    }
    return null;
}
Also used : FunctionException(lucee.runtime.exp.FunctionException) Resource(lucee.commons.io.res.Resource) IOException(java.io.IOException) Image(lucee.runtime.img.Image)

Example 92 with FunctionException

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

the class BitMaskSet method call.

public static double call(PageContext pc, double dnumber, double dmask, double dstart, double dlength) throws FunctionException {
    int number = (int) dnumber, mask = (int) dmask, start = (int) dstart, length = (int) dlength;
    if (start > 31 || start < 0)
        throw new FunctionException(pc, "bitMaskSet", 2, "start", "must be beetween 0 and 31 now " + start);
    if (length > 31 || length < 0)
        throw new FunctionException(pc, "bitMaskSet", 3, "length", "must be beetween 0 and 31 now " + length);
    int tmp = (1 << length) - 1 << start;
    mask &= (1 << length) - 1;
    return number & ~tmp | mask << start;
}
Also used : FunctionException(lucee.runtime.exp.FunctionException)

Example 93 with FunctionException

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

the class ArrayFind method find.

public static int find(PageContext pc, Array array, UDF udf) throws PageException {
    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, "ArrayFind", 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())
                return i;
        }
    }
    return 0;
}
Also used : Closure(lucee.runtime.type.Closure) FunctionException(lucee.runtime.exp.FunctionException)

Example 94 with FunctionException

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

the class UDFComparator method compare.

@Override
public int compare(Object oLeft, Object oRight) {
    try {
        args[0] = oLeft;
        args[1] = oRight;
        Object res = udf.call(pc, args, false);
        Integer i = Caster.toInteger(res, null);
        if (i == null)
            throw new FunctionException(pc, "ArraySort", 2, "function", "return value of the " + (udf instanceof Closure ? "closure" : "function [" + udf.getFunctionName() + "]") + " cannot be casted to a integer.", CasterException.createMessage(res, "integer"));
        return i.intValue();
    } catch (PageException pe) {
        throw new PageRuntimeException(pe);
    }
}
Also used : PageException(lucee.runtime.exp.PageException) Closure(lucee.runtime.type.Closure) FunctionException(lucee.runtime.exp.FunctionException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException)

Example 95 with FunctionException

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

the class CacheGetDefaultCacheName method call.

public static String call(PageContext pc, String strType) throws PageException {
    int type = CacheUtil.toType(strType, Config.CACHE_TYPE_NONE);
    if (type == Config.CACHE_TYPE_NONE)
        throw new FunctionException(pc, "CacheGetDefaultCacheName", 1, "type", "invalid type defintion [" + strType + "], valid types are [object,resource,template,query]");
    ConfigImpl config = (ConfigImpl) pc.getConfig();
    CacheConnection conn = config.getCacheDefaultConnection(type);
    if (conn == null)
        throw new ExpressionException("there is no default cache defined for type [" + strType + "]");
    return conn.getName();
}
Also used : FunctionException(lucee.runtime.exp.FunctionException) CacheConnection(lucee.runtime.cache.CacheConnection) ConfigImpl(lucee.runtime.config.ConfigImpl) ExpressionException(lucee.runtime.exp.ExpressionException)

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