use of lucee.runtime.exp.FunctionException in project Lucee by lucee.
the class CreateDynamicProxy method _call.
public static Object _call(PageContext pc, Object oCFC, Object oInterfaces) throws PageException, IOException {
if (SystemUtil.getLoaderVersion() < 5.9D)
throw new ApplicationException("You need to update your lucee.jar to execute the function [createDynamicProxy], you can download the latest jar from http://download.lucee.org.");
// Component
Component cfc;
if (oCFC instanceof Component)
cfc = (Component) oCFC;
else
cfc = pc.loadComponent(Caster.toString(oCFC));
// string list to array
if (Decision.isString(oInterfaces)) {
String list = Caster.toString(oInterfaces);
oInterfaces = ListUtil.listToStringArray(list, ',');
}
Class[] interfaces = null;
if (Decision.isArray(oInterfaces)) {
Object[] arr = Caster.toNativeArray(oInterfaces);
ClassLoader cl = ((PageContextImpl) pc).getClassLoader();
interfaces = new Class[arr.length];
for (int i = 0; i < arr.length; i++) {
if (arr[i] instanceof JavaObject)
interfaces[i] = ((JavaObject) arr[i]).getClazz();
else
interfaces[i] = ClassUtil.loadClass(cl, Caster.toString(arr[i]));
}
// strInterfaces=ListUtil.toStringArray(Caster.toArray(oInterfaces));
} else if (oInterfaces instanceof JavaObject) {
interfaces = new Class[] { ((JavaObject) oInterfaces).getClazz() };
} else
throw new FunctionException(pc, "CreateDynamicProxy", 2, "interfaces", "invalid type [" + Caster.toClassName(oInterfaces) + "] for class defintion");
// check if all classes are interfaces
for (int i = 0; i < interfaces.length; i++) {
if (!interfaces[i].isInterface())
throw new FunctionException(pc, "CreateDynamicProxy", 2, "interfaces", "definition [" + interfaces[i].getClass() + "] is a class and not a interface");
}
return JavaProxyFactory.createProxy(pc, cfc, null, interfaces);
}
use of lucee.runtime.exp.FunctionException in project Lucee by lucee.
the class GeneratePBKDFKey method call.
public static String call(PageContext pc, String algorithm, String passPhrase, String salt, double iterations, double keySize) throws PageException {
// algo
if (StringUtil.isEmpty(algorithm))
throw new FunctionException(pc, "GeneratePBKDFKey", 1, "algorithm", "algorithm argument is empty.");
algorithm = algorithm.trim();
if (!StringUtil.startsWithIgnoreCase(algorithm, "PBK"))
throw new FunctionException(pc, "GeneratePBKDFKey", 1, "algorithm", "algorithm [" + algorithm + "] is not supported.");
// TODO add provider to support addional keys by addin a provider that is supporting it
SecretKeyFactory key = null;
try {
key = SecretKeyFactory.getInstance(algorithm);
} catch (NoSuchAlgorithmException e) {
if (!algorithm.equalsIgnoreCase("PBKDF2WithHmacSHA1"))
throw new FunctionException(pc, "GeneratePBKDFKey", 1, "algorithm", "only the algorithm [PBKDF2WithHmacSHA1] is supported by the build in .");
else
throw Caster.toPageException(e);
}
try {
PBEKeySpec spec = new PBEKeySpec(passPhrase.toCharArray(), salt.getBytes(), (int) iterations, (int) keySize);
return Base64Coder.encode(key.generateSecret(spec).getEncoded());
} catch (InvalidKeySpecException ikse) {
throw Caster.toPageException(ikse);
}
}
use of lucee.runtime.exp.FunctionException in project Lucee by lucee.
the class QueryRowData method call.
public static Struct call(PageContext pc, Query query, double rowNumber) throws PageException {
int row = Caster.toInteger(rowNumber);
if (row < 1 || row > query.getRecordcount())
throw new FunctionException(pc, QueryRowData.class.getSimpleName(), 2, "rowNumber", "The argument rowNumber [" + row + "] must be between 1 and the query's record count [" + query.getRecordcount() + "]");
Collection.Key[] colNames = query.getColumnNames();
Struct result = new StructImpl();
for (int col = 0; col < colNames.length; col++) result.setEL(colNames[col], query.getAt(colNames[col], row, NullSupportHelper.empty(pc)));
return result;
}
use of lucee.runtime.exp.FunctionException in project Lucee by lucee.
the class PinchFilter method filter.
@Override
public BufferedImage filter(BufferedImage src, Struct parameters) throws PageException {
// ImageUtil.createBufferedImage(src);
BufferedImage dst = null;
Object o;
if ((o = parameters.removeEL(KeyImpl.init("Radius"))) != null)
setRadius(ImageFilterUtil.toFloatValue(o, "Radius"));
if ((o = parameters.removeEL(KeyImpl.init("Amount"))) != null)
setAmount(ImageFilterUtil.toFloatValue(o, "Amount"));
if ((o = parameters.removeEL(KeyImpl.init("Angle"))) != null)
setAngle(ImageFilterUtil.toFloatValue(o, "Angle"));
if ((o = parameters.removeEL(KeyImpl.init("CentreX"))) != null)
setCentreX(ImageFilterUtil.toFloatValue(o, "CentreX"));
if ((o = parameters.removeEL(KeyImpl.init("CentreY"))) != null)
setCentreY(ImageFilterUtil.toFloatValue(o, "CentreY"));
// if((o=parameters.removeEL(KeyImpl.init("Centre")))!=null)setCentre(ImageFilterUtil.toPoint2D(o,"Centre"));
if ((o = parameters.removeEL(KeyImpl.init("EdgeAction"))) != null)
setEdgeAction(ImageFilterUtil.toString(o, "EdgeAction"));
if ((o = parameters.removeEL(KeyImpl.init("Interpolation"))) != null)
setInterpolation(ImageFilterUtil.toString(o, "Interpolation"));
// check for arguments not supported
if (parameters.size() > 0) {
throw new FunctionException(ThreadLocalPageContext.get(), "ImageFilter", 3, "parameters", "the parameter" + (parameters.size() > 1 ? "s" : "") + " [" + CollectionUtil.getKeyList(parameters, ", ") + "] " + (parameters.size() > 1 ? "are" : "is") + " not allowed, only the following parameters are supported [Radius, Amount, Angle, CentreX, CentreY, Centre, EdgeAction, Interpolation]");
}
return filter(src, dst);
}
use of lucee.runtime.exp.FunctionException in project Lucee by lucee.
the class PlasmaFilter method filter.
@Override
public BufferedImage filter(BufferedImage src, Struct parameters) throws PageException {
BufferedImage dst = ImageUtil.createBufferedImage(src);
Object o;
if ((o = parameters.removeEL(KeyImpl.init("Colormap"))) != null)
setColormap(ImageFilterUtil.toColormap(o, "Colormap"));
if ((o = parameters.removeEL(KeyImpl.init("Turbulence"))) != null)
setTurbulence(ImageFilterUtil.toFloatValue(o, "Turbulence"));
if ((o = parameters.removeEL(KeyImpl.init("Scaling"))) != null)
setScaling(ImageFilterUtil.toFloatValue(o, "Scaling"));
if ((o = parameters.removeEL(KeyImpl.init("UseColormap"))) != null)
setUseColormap(ImageFilterUtil.toBooleanValue(o, "UseColormap"));
if ((o = parameters.removeEL(KeyImpl.init("UseImageColors"))) != null)
setUseImageColors(ImageFilterUtil.toBooleanValue(o, "UseImageColors"));
if ((o = parameters.removeEL(KeyImpl.init("Seed"))) != null)
setSeed(ImageFilterUtil.toIntValue(o, "Seed"));
// check for arguments not supported
if (parameters.size() > 0) {
throw new FunctionException(ThreadLocalPageContext.get(), "ImageFilter", 3, "parameters", "the parameter" + (parameters.size() > 1 ? "s" : "") + " [" + CollectionUtil.getKeyList(parameters, ", ") + "] " + (parameters.size() > 1 ? "are" : "is") + " not allowed, only the following parameters are supported [Colormap, Turbulence, Scaling, UseColormap, UseImageColors, Seed]");
}
return filter(src, dst);
}
Aggregations