Search in sources :

Example 1 with BIF

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;
}
Also used : BIF(lucee.runtime.ext.function.BIF) PageException(lucee.runtime.exp.PageException)

Example 2 with 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 });
        }
    }
}
Also used : BIF(lucee.runtime.ext.function.BIF) PageException(lucee.runtime.exp.PageException) IOException(java.io.IOException) ApplicationException(lucee.runtime.exp.ApplicationException)

Example 3 with BIF

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);
    }
}
Also used : BIFProxy(lucee.runtime.functions.BIFProxy) BIF(lucee.runtime.ext.function.BIF) ClassException(lucee.commons.lang.ClassException) PageException(lucee.runtime.exp.PageException) BundleException(org.osgi.framework.BundleException) ApplicationException(lucee.runtime.exp.ApplicationException)

Example 4 with BIF

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;
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) FunctionLib(lucee.transformer.library.function.FunctionLib) BIFProxy(lucee.runtime.functions.BIFProxy) BIF(lucee.runtime.ext.function.BIF)

Example 5 with BIF

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);
}
Also used : InterpreterException(lucee.runtime.interpreter.InterpreterException) ArrayList(java.util.ArrayList) FunctionException(lucee.runtime.exp.FunctionException) ExpressionException(lucee.runtime.exp.ExpressionException) Casting(lucee.runtime.interpreter.ref.cast.Casting) LFunctionValue(lucee.runtime.interpreter.ref.literal.LFunctionValue) FunctionValue(lucee.runtime.type.FunctionValue) FunctionLibFunctionArg(lucee.transformer.library.function.FunctionLibFunctionArg) FunctionValueImpl(lucee.runtime.type.FunctionValueImpl) BIF(lucee.runtime.ext.function.BIF)

Aggregations

BIF (lucee.runtime.ext.function.BIF)5 PageException (lucee.runtime.exp.PageException)3 ApplicationException (lucee.runtime.exp.ApplicationException)2 BIFProxy (lucee.runtime.functions.BIFProxy)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ClassException (lucee.commons.lang.ClassException)1 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)1 ExpressionException (lucee.runtime.exp.ExpressionException)1 FunctionException (lucee.runtime.exp.FunctionException)1 InterpreterException (lucee.runtime.interpreter.InterpreterException)1 Casting (lucee.runtime.interpreter.ref.cast.Casting)1 LFunctionValue (lucee.runtime.interpreter.ref.literal.LFunctionValue)1 FunctionValue (lucee.runtime.type.FunctionValue)1 FunctionValueImpl (lucee.runtime.type.FunctionValueImpl)1 FunctionLib (lucee.transformer.library.function.FunctionLib)1 FunctionLibFunction (lucee.transformer.library.function.FunctionLibFunction)1 FunctionLibFunctionArg (lucee.transformer.library.function.FunctionLibFunctionArg)1 BundleException (org.osgi.framework.BundleException)1