Search in sources :

Example 11 with UDF

use of lucee.runtime.type.UDF in project Lucee by lucee.

the class PropertyFactory method addGet.

public static void addGet(ComponentImpl comp, Property prop) throws ApplicationException {
    Member m = comp.getMember(Component.ACCESS_PRIVATE, KeyImpl.getInstance("get" + prop.getName()), true, false);
    if (!(m instanceof UDF)) {
        UDF udf = new UDFGetterProperty(comp, prop);
        comp.registerUDF(KeyImpl.init(udf.getFunctionName()), udf);
    }
}
Also used : UDFGetterProperty(lucee.runtime.type.UDFGetterProperty) UDF(lucee.runtime.type.UDF) Member(lucee.runtime.component.Member)

Example 12 with UDF

use of lucee.runtime.type.UDF in project Lucee by lucee.

the class PropertyFactory method addAdd.

public static void addAdd(ComponentImpl comp, Property prop) throws ApplicationException {
    Member m = comp.getMember(Component.ACCESS_PRIVATE, KeyImpl.getInstance("add" + getSingularName(prop)), true, false);
    if (!(m instanceof UDF)) {
        UDF udf = new UDFAddProperty(comp, prop);
        comp.registerUDF(KeyImpl.init(udf.getFunctionName()), udf);
    }
}
Also used : UDFAddProperty(lucee.runtime.type.UDFAddProperty) UDF(lucee.runtime.type.UDF) Member(lucee.runtime.component.Member)

Example 13 with UDF

use of lucee.runtime.type.UDF in project Lucee by lucee.

the class PropertyFactory method addRemove.

public static void addRemove(ComponentImpl comp, Property prop) throws ApplicationException {
    Member m = comp.getMember(Component.ACCESS_PRIVATE, KeyImpl.getInstance("remove" + getSingularName(prop)), true, false);
    if (!(m instanceof UDF)) {
        UDF udf = new UDFRemoveProperty(comp, prop);
        comp.registerUDF(KeyImpl.init(udf.getFunctionName()), udf);
    }
}
Also used : UDF(lucee.runtime.type.UDF) Member(lucee.runtime.component.Member) UDFRemoveProperty(lucee.runtime.type.UDFRemoveProperty)

Example 14 with UDF

use of lucee.runtime.type.UDF in project Lucee by lucee.

the class CFFunction method call.

// private static Map udfs=new ReferenceMap();
public static Object call(PageContext pc, Object[] objArr) throws PageException {
    if (objArr.length < 3)
        throw new ExpressionException("invalid call of a CFML Based built in function");
    // translate arguments
    String filename = Caster.toString((((FunctionValue) objArr[0]).getValue()));
    Collection.Key name = KeyImpl.toKey((((FunctionValue) objArr[1]).getValue()));
    boolean isweb = Caster.toBooleanValue((((FunctionValue) objArr[2]).getValue()));
    UDF udf = loadUDF(pc, filename, name, isweb);
    Struct meta = udf.getMetaData(pc);
    boolean callerScopes = (meta == null) ? false : Caster.toBooleanValue(meta.get("callerScopes", Boolean.FALSE), false);
    boolean caller = meta == null ? false : Caster.toBooleanValue(meta.get(KeyConstants._caller, Boolean.FALSE), false);
    Struct namedArguments = null, cs = null;
    if (callerScopes) {
        cs = new StructImpl();
        if (pc.undefinedScope().getCheckArguments()) {
            cs.set(KeyConstants._local, pc.localScope().duplicate(false));
            cs.set(KeyConstants._arguments, pc.argumentsScope().duplicate(false));
        }
    }
    Object[] arguments = null;
    if (objArr.length <= 3)
        arguments = ArrayUtil.OBJECT_EMPTY;
    else if (objArr[3] instanceof FunctionValue) {
        FunctionValue fv;
        namedArguments = new StructImpl(Struct.TYPE_LINKED);
        if (callerScopes)
            namedArguments.setEL(KeyConstants._caller, cs);
        else if (caller)
            namedArguments.setEL(KeyConstants._caller, Duplicator.duplicate(pc.undefinedScope(), false));
        for (int i = 3; i < objArr.length; i++) {
            fv = toFunctionValue(name, objArr[i]);
            namedArguments.set(fv.getName(), fv.getValue());
        }
    } else {
        int offset = (caller || callerScopes ? 2 : 3);
        arguments = new Object[objArr.length - offset];
        if (callerScopes)
            arguments[0] = cs;
        else if (caller)
            arguments[0] = Duplicator.duplicate(pc.undefinedScope(), false);
        for (int i = 3; i < objArr.length; i++) {
            arguments[i - offset] = toObject(name, objArr[i]);
        }
    }
    // execute UDF
    if (namedArguments == null) {
        return ((UDFImpl) udf).call(pc, name, arguments, false);
    }
    return ((UDFImpl) udf).callWithNamedValues(pc, name, namedArguments, false);
}
Also used : StructImpl(lucee.runtime.type.StructImpl) UDF(lucee.runtime.type.UDF) FunctionValue(lucee.runtime.type.FunctionValue) Collection(lucee.runtime.type.Collection) ExpressionException(lucee.runtime.exp.ExpressionException) Struct(lucee.runtime.type.Struct) UDFImpl(lucee.runtime.type.UDFImpl)

Example 15 with UDF

use of lucee.runtime.type.UDF in project Lucee by lucee.

the class CFFunction method loadUDF.

public static UDF loadUDF(PageContext pc, String filename, Collection.Key name, boolean isweb) throws PageException {
    ConfigWebImpl config = (ConfigWebImpl) pc.getConfig();
    String key = isweb ? name.getString() + config.getIdentification().getId() : name.getString();
    UDF udf = config.getFromFunctionCache(key);
    if (udf != null)
        return udf;
    Mapping mapping = isweb ? config.getFunctionMapping() : config.getServerFunctionMapping();
    Page p = mapping.getPageSource(filename).loadPage(pc, false);
    // execute page
    Variables old = pc.variablesScope();
    pc.setVariablesScope(VAR);
    boolean wasSilent = pc.setSilent();
    try {
        p.call(pc);
        Object o = pc.variablesScope().get(name, null);
        if (o instanceof UDF) {
            udf = (UDF) o;
            config.putToFunctionCache(key, udf);
            return udf;
        }
        throw new ExpressionException("there is no Function defined with name [" + name + "] in template [" + mapping.getStrPhysical() + File.separator + filename + "]");
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        throw Caster.toPageException(t);
    } finally {
        pc.setVariablesScope(old);
        if (!wasSilent)
            pc.unsetSilent();
    }
}
Also used : Variables(lucee.runtime.type.scope.Variables) ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) UDF(lucee.runtime.type.UDF) Mapping(lucee.runtime.Mapping) Page(lucee.runtime.Page) ExpressionException(lucee.runtime.exp.ExpressionException)

Aggregations

UDF (lucee.runtime.type.UDF)42 Key (lucee.runtime.type.Collection.Key)14 Struct (lucee.runtime.type.Struct)14 Component (lucee.runtime.Component)9 Entry (java.util.Map.Entry)7 PageException (lucee.runtime.exp.PageException)7 Member (lucee.runtime.component.Member)6 FunctionArgument (lucee.runtime.type.FunctionArgument)6 StructImpl (lucee.runtime.type.StructImpl)6 ArgumentIntKey (lucee.runtime.type.scope.ArgumentIntKey)6 Iterator (java.util.Iterator)5 ComponentScope (lucee.runtime.ComponentScope)5 ComponentSpecificAccess (lucee.runtime.ComponentSpecificAccess)5 PageContextImpl (lucee.runtime.PageContextImpl)5 Property (lucee.runtime.component.Property)5 Array (lucee.runtime.type.Array)5 Collection (lucee.runtime.type.Collection)5 IOException (java.io.IOException)4 Map (java.util.Map)4 HashMap (java.util.HashMap)3