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