use of lucee.runtime.ext.function.BIF in project Lucee by lucee.
the class FunctionHandlerPool method use.
/**
* return a tag to use from a class
* @param tagClass
* @return Tag
* @throws PageException
*/
public static BIF use(PageContext pc, String className, String bundleName, String bundleVersion) throws PageException {
String id = toId(className, bundleName, bundleVersion);
BIF bif = map.get(id);
if (bif != null)
return bif;
try {
Class<?> clazz;
// OSGi bundle
if (!StringUtil.isEmpty(bundleName))
clazz = ClassUtil.loadClassByBundle(className, bundleName, bundleVersion, pc.getConfig().getIdentification());
else
// JAR
clazz = ClassUtil.loadClass(className);
if (Reflector.isInstaneOf(clazz, BIF.class))
bif = (BIF) clazz.newInstance();
else
bif = new BIFProxy(clazz);
} catch (Exception e) {
throw Caster.toPageException(e);
}
map.put(id, bif);
return bif;
}
use of lucee.runtime.ext.function.BIF in project Lucee by lucee.
the class Directory method setS3Attrs.
public static void setS3Attrs(PageContext pc, Resource res, Object acl, String storage) throws PageException {
String scheme = res.getResourceProvider().getScheme();
if ("s3".equalsIgnoreCase(scheme)) {
// ACL
if (acl != null) {
try {
// old way
if (Decision.isString(acl)) {
Reflector.callMethod(res, "setACL", new Object[] { improveACL(Caster.toString(acl)) });
} else // new way
{
BIF bif = CFMLEngineFactory.getInstance().getClassUtil().loadBIF(pc, "StoreSetACL");
bif.invoke(pc, new Object[] { res.getAbsolutePath(), acl });
}
} catch (Exception e) {
throw Caster.toPageException(e);
}
}
// STORAGE
if (storage != null) {
Reflector.callMethod(res, "setStorage", new Object[] { storage });
}
}
}
use of lucee.runtime.ext.function.BIF in project Lucee by lucee.
the class TagUtil method invokeBIF.
/**
* used by the bytecode builded
* @param pc pageContext
* @param className
* @param bundleName
* @param bundleVersion
* @return
* @throws BundleException
* @throws ClassException
*/
public static Object invokeBIF(PageContext pc, Object[] args, String className, String bundleName, String bundleVersion) throws PageException {
try {
Class<?> clazz = ClassUtil.loadClassByBundle(className, bundleName, bundleVersion, pc.getConfig().getIdentification());
BIF bif;
if (Reflector.isInstaneOf(clazz, BIF.class))
bif = (BIF) clazz.newInstance();
else
bif = new BIFProxy(clazz);
return bif.invoke(pc, args);
} catch (Exception e) {
throw Caster.toPageException(e);
}
}
use of lucee.runtime.ext.function.BIF in project Lucee by lucee.
the class ClassUtilImpl method loadBIF.
@Override
public BIF loadBIF(PageContext pc, String name) throws InstantiationException, IllegalAccessException {
// first of all we chek if itis a class
Class<?> res = lucee.commons.lang.ClassUtil.loadClass(name, null);
if (res != null) {
if (Reflector.isInstaneOf(res, BIF.class)) {
return (BIF) res.newInstance();
}
return new BIFProxy(res);
}
FunctionLib[] flds = ((ConfigWebImpl) pc.getConfig()).getFLDs(pc.getCurrentTemplateDialect());
FunctionLibFunction flf;
for (int i = 0; i < flds.length; i++) {
flf = flds[i].getFunction(name);
if (flf != null)
return flf.getBIF();
}
return null;
}
use of lucee.runtime.ext.function.BIF in project Lucee by lucee.
the class VT method getValue.
@Override
public Object getValue(PageContext pc) throws PageException {
Object[] arguments = null;
if (isDynamic()) {
arguments = RefUtil.getValue(pc, refArgs);
if (flf.hasDefaultValues()) {
List<Object> tmp = new ArrayList<Object>();
ArrayList<FunctionLibFunctionArg> args = flf.getArg();
Iterator<FunctionLibFunctionArg> it = args.iterator();
FunctionLibFunctionArg arg;
while (it.hasNext()) {
arg = it.next();
if (arg.getDefaultValue() != null)
tmp.add(new FunctionValueImpl(arg.getName(), arg.getDefaultValue()));
}
for (int i = 0; i < arguments.length; i++) {
tmp.add(arguments[i]);
}
arguments = tmp.toArray();
}
arguments = new Object[] { arguments };
} else {
if (isNamed(pc, refArgs)) {
FunctionValue[] fvalues = getFunctionValues(pc, refArgs);
String[] names = getNames(fvalues);
ArrayList<FunctionLibFunctionArg> list = flf.getArg();
Iterator<FunctionLibFunctionArg> it = list.iterator();
arguments = new Object[list.size()];
FunctionLibFunctionArg flfa;
int index = 0;
VT vt;
while (it.hasNext()) {
flfa = it.next();
vt = getMatchingValueAndType(flfa, fvalues, names);
if (vt.index != -1)
names[vt.index] = null;
arguments[index++] = new Casting(vt.type, CFTypes.toShort(vt.type, false, CFTypes.TYPE_UNKNOW), vt.value).getValue(pc);
}
for (int y = 0; y < names.length; y++) {
if (names[y] != null) {
ExpressionException ee = new InterpreterException("argument [" + names[y] + "] is not allowed for function [" + flf.getName() + "]");
UDFUtil.addFunctionDoc(ee, flf);
throw ee;
}
}
} else {
arguments = RefUtil.getValue(pc, refArgs);
}
}
BIF bif = flf.getBIF();
if (flf.getMemberChaining() && obj != null) {
bif.invoke(pc, arguments);
return obj;
}
if (!isDynamic() && flf.getArgMin() > arguments.length) {
throw new FunctionException(pc, flf.getName(), flf.getArgMin(), flf.getArgMax(), arguments.length);
}
return Caster.castTo(pc, flf.getReturnTypeAsString(), bif.invoke(pc, arguments), false);
}
Aggregations