Search in sources :

Example 1 with FunctionLib

use of lucee.transformer.library.function.FunctionLib in project Lucee by lucee.

the class ConfigImpl method setFunctionDirectory.

protected void setFunctionDirectory(Resource functionDirectory) {
    this.functionMapping = new MappingImpl(this, "/mapping-function/", functionDirectory.getAbsolutePath(), null, ConfigImpl.INSPECT_NEVER, true, true, true, true, false, true, null, -1, -1);
    FunctionLib flc = cfmlFlds[cfmlFlds.length - 1];
    FunctionLib fll = luceeFlds[luceeFlds.length - 1];
    // now overwrite with new data
    if (functionDirectory.isDirectory()) {
        String[] files = functionDirectory.list(new ExtensionResourceFilter(Constants.getTemplateExtensions()));
        for (int i = 0; i < files.length; i++) {
            if (flc != null)
                createFunction(flc, files[i]);
            if (fll != null)
                createFunction(fll, files[i]);
        }
        combinedCFMLFLDs = null;
        combinedLuceeFLDs = null;
    }
}
Also used : FunctionLib(lucee.transformer.library.function.FunctionLib) ExtensionResourceFilter(lucee.commons.io.res.filter.ExtensionResourceFilter) MappingImpl(lucee.runtime.MappingImpl)

Example 2 with FunctionLib

use of lucee.transformer.library.function.FunctionLib in project Lucee by lucee.

the class MemberUtil method getMembers.

public static Map<Collection.Key, FunctionLibFunction> getMembers(PageContext pc, short type) {
    Map<Short, Map<Key, FunctionLibFunction>> matches = pc.getCurrentTemplateDialect() == CFMLEngine.DIALECT_LUCEE ? matchesLucee : matchesCFML;
    Map<Key, FunctionLibFunction> match = matches.get(type);
    if (match != null)
        return match;
    FunctionLib[] flds = ((ConfigWebImpl) pc.getConfig()).getFLDs(pc.getCurrentTemplateDialect());
    Iterator<FunctionLibFunction> it;
    FunctionLibFunction f;
    match = new HashMap<Collection.Key, FunctionLibFunction>();
    String[] names;
    for (int i = 0; i < flds.length; i++) {
        it = flds[i].getFunctions().values().iterator();
        while (it.hasNext()) {
            f = it.next();
            names = f.getMemberNames();
            if (!ArrayUtil.isEmpty(names) && f.getMemberType() == type && f.getArgType() == FunctionLibFunction.ARG_FIX) {
                for (int y = 0; y < names.length; y++) match.put(KeyImpl.getInstance(names[y]), f);
            }
        }
    }
    matches.put(type, match);
    return match;
}
Also used : FunctionLib(lucee.transformer.library.function.FunctionLib) LString(lucee.runtime.interpreter.ref.literal.LString) ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) HashMap(java.util.HashMap) Map(java.util.Map) Key(lucee.runtime.type.Collection.Key)

Example 3 with FunctionLib

use of lucee.transformer.library.function.FunctionLib in project Lucee by lucee.

the class GetFunctionData method _call.

private static Struct _call(PageContext pc, String strFunctionName, int dialect) throws PageException {
    FunctionLib[] flds;
    flds = ((ConfigImpl) pc.getConfig()).getFLDs(dialect);
    FunctionLibFunction function = null;
    for (int i = 0; i < flds.length; i++) {
        function = flds[i].getFunction(strFunctionName.toLowerCase());
        if (function != null)
            break;
    }
    if (function == null)
        throw new ExpressionException("function [" + strFunctionName + "] is not a built in function");
    // CFML Based Function
    Class clazz = null;
    try {
        clazz = function.getFunctionClassDefinition().getClazz();
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
    }
    if (clazz == lucee.runtime.functions.system.CFFunction.class) {
        return cfmlBasedFunction(pc, function);
    }
    return javaBasedFunction(function);
}
Also used : FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) FunctionLib(lucee.transformer.library.function.FunctionLib) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 4 with FunctionLib

use of lucee.transformer.library.function.FunctionLib in project Lucee by lucee.

the class GetFunctionList method _call.

private static lucee.runtime.type.Struct _call(PageContext pc, int dialect) throws PageException {
    Struct sct = new StructImpl();
    // synchronized(sct) {
    // hasSet=true;
    FunctionLib[] flds;
    flds = ((ConfigImpl) pc.getConfig()).getFLDs(dialect);
    FunctionLibFunction func;
    Map<String, FunctionLibFunction> _functions;
    Iterator<Entry<String, FunctionLibFunction>> it;
    Entry<String, FunctionLibFunction> e;
    for (int i = 0; i < flds.length; i++) {
        _functions = flds[i].getFunctions();
        it = _functions.entrySet().iterator();
        while (it.hasNext()) {
            e = it.next();
            func = e.getValue();
            if (func.getStatus() != TagLib.STATUS_HIDDEN && func.getStatus() != TagLib.STATUS_UNIMPLEMENTED)
                sct.set(e.getKey(), "");
        }
    }
    return sct;
}
Also used : Entry(java.util.Map.Entry) StructImpl(lucee.runtime.type.StructImpl) FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) FunctionLib(lucee.transformer.library.function.FunctionLib) Struct(lucee.runtime.type.Struct)

Example 5 with FunctionLib

use of lucee.transformer.library.function.FunctionLib in project Lucee by lucee.

the class Admin method doGetFLDs.

/**
 * @throws PageException
 */
private void doGetFLDs() throws PageException {
    lucee.runtime.type.Query qry = new QueryImpl(new String[] { "displayname", "namespace", "namespaceseparator", "shortname", "description", "uri", "source" }, new String[] { "varchar", "varchar", "varchar", "varchar", "varchar", "varchar", "varchar" }, 0, "tlds");
    int dialect = "lucee".equalsIgnoreCase(getString("dialect", "cfml")) ? CFMLEngine.DIALECT_LUCEE : CFMLEngine.DIALECT_CFML;
    FunctionLib[] libs = config.getFLDs(dialect);
    for (int i = 0; i < libs.length; i++) {
        qry.addRow();
        qry.setAt("displayname", i + 1, libs[i].getDisplayName());
        // TODO support for namespace
        qry.setAt("namespace", i + 1, "");
        qry.setAt("namespaceseparator", i + 1, "");
        qry.setAt("shortname", i + 1, libs[i].getShortName());
        qry.setAt("description", i + 1, libs[i].getDescription());
        qry.setAt("uri", i + 1, Caster.toString(libs[i].getUri()));
        qry.setAt("source", i + 1, StringUtil.emptyIfNull(libs[i].getSource()));
    }
    pageContext.setVariable(getString("admin", action, "returnVariable"), qry);
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) FunctionLib(lucee.transformer.library.function.FunctionLib) Query(lucee.runtime.type.Query)

Aggregations

FunctionLib (lucee.transformer.library.function.FunctionLib)11 FunctionLibFunction (lucee.transformer.library.function.FunctionLibFunction)6 Resource (lucee.commons.io.res.Resource)3 ExtensionResourceFilter (lucee.commons.io.res.filter.ExtensionResourceFilter)2 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)2 TagLib (lucee.transformer.library.tag.TagLib)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 lucee.aprint (lucee.aprint)1 CompressResource (lucee.commons.io.res.type.compress.CompressResource)1 MappingImpl (lucee.runtime.MappingImpl)1 ExpressionException (lucee.runtime.exp.ExpressionException)1 BIF (lucee.runtime.ext.function.BIF)1 BIFProxy (lucee.runtime.functions.BIFProxy)1 LString (lucee.runtime.interpreter.ref.literal.LString)1 Key (lucee.runtime.type.Collection.Key)1 Query (lucee.runtime.type.Query)1