Search in sources :

Example 76 with Array

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

the class ModernApplicationContext method initJava.

private void initJava() {
    if (!initJavaSettings) {
        Object o = get(component, JAVA_SETTING, null);
        if (o != null && Decision.isStruct(o)) {
            Struct sct = Caster.toStruct(o, null);
            // loadPaths
            Object obj = sct.get(KeyImpl.init("loadPaths"), null);
            List<Resource> paths;
            if (obj != null) {
                paths = loadPaths(ThreadLocalPageContext.get(), obj);
            } else
                paths = new ArrayList<Resource>();
            // loadCFMLClassPath
            Boolean loadCFMLClassPath = Caster.toBoolean(sct.get(KeyImpl.init("loadCFMLClassPath"), null), null);
            if (loadCFMLClassPath == null)
                loadCFMLClassPath = Caster.toBoolean(sct.get(KeyImpl.init("loadColdFusionClassPath"), null), null);
            if (loadCFMLClassPath == null)
                loadCFMLClassPath = javaSettings.loadCFMLClassPath();
            // reloadOnChange
            boolean reloadOnChange = Caster.toBooleanValue(sct.get(KeyImpl.init("reloadOnChange"), null), javaSettings.reloadOnChange());
            // watchInterval
            int watchInterval = Caster.toIntValue(sct.get(KeyImpl.init("watchInterval"), null), javaSettings.watchInterval());
            // watchExtensions
            obj = sct.get(KeyImpl.init("watchExtensions"), null);
            List<String> extensions = new ArrayList<String>();
            if (obj != null) {
                Array arr;
                if (Decision.isArray(obj)) {
                    try {
                        arr = Caster.toArray(obj);
                    } catch (PageException e) {
                        arr = new ArrayImpl();
                    }
                } else {
                    arr = lucee.runtime.type.util.ListUtil.listToArrayRemoveEmpty(Caster.toString(obj, ""), ',');
                }
                Iterator<Object> it = arr.valueIterator();
                String ext;
                while (it.hasNext()) {
                    ext = Caster.toString(it.next(), null);
                    if (StringUtil.isEmpty(ext))
                        continue;
                    ext = ext.trim();
                    if (ext.startsWith("."))
                        ext = ext.substring(1);
                    if (ext.startsWith("*."))
                        ext = ext.substring(2);
                    extensions.add(ext);
                }
            }
            javaSettings = new JavaSettingsImpl(paths.toArray(new Resource[paths.size()]), loadCFMLClassPath, reloadOnChange, watchInterval, extensions.toArray(new String[extensions.size()]));
        }
        initJavaSettings = true;
    }
}
Also used : PageException(lucee.runtime.exp.PageException) ArrayImpl(lucee.runtime.type.ArrayImpl) Resource(lucee.commons.io.res.Resource) ArrayList(java.util.ArrayList) Struct(lucee.runtime.type.Struct) Array(lucee.runtime.type.Array) RefBoolean(lucee.commons.lang.types.RefBoolean)

Example 77 with Array

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

the class ModernApplicationContext method loadPaths.

public static java.util.List<Resource> loadPaths(PageContext pc, Object obj) {
    Resource res;
    if (!Decision.isArray(obj)) {
        String list = Caster.toString(obj, null);
        if (!StringUtil.isEmpty(list)) {
            obj = ListUtil.listToArray(list, ',');
        }
    }
    if (Decision.isArray(obj)) {
        Array arr = Caster.toArray(obj, null);
        java.util.List<Resource> list = new ArrayList<Resource>();
        Iterator<Object> it = arr.valueIterator();
        while (it.hasNext()) {
            try {
                String path = Caster.toString(it.next(), null);
                if (path == null)
                    continue;
                // print.e("--------------------------------------------------");
                // print.e(path);
                res = ORMConfigurationImpl.toResourceExisting(pc.getConfig(), pc.getApplicationContext(), path, false);
                // print.e(res+"->"+(res!=null && res.exists()));
                if (res == null || !res.exists())
                    res = ResourceUtil.toResourceExisting(pc, path, true, null);
                // print.e(res+"->"+(res!=null && res.exists()));
                if (res != null)
                    list.add(res);
            } catch (Exception e) {
                SystemOut.printDate(e);
            }
        }
        return list;
    }
    return null;
}
Also used : Array(lucee.runtime.type.Array) Resource(lucee.commons.io.res.Resource) ArrayList(java.util.ArrayList) DeprecatedException(lucee.runtime.exp.DeprecatedException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) PageException(lucee.runtime.exp.PageException) BundleException(org.osgi.framework.BundleException) ClassException(lucee.commons.lang.ClassException) CacheException(lucee.commons.io.cache.exp.CacheException) ApplicationException(lucee.runtime.exp.ApplicationException)

Example 78 with Array

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

the class GetFunctionData method cfmlBasedFunction.

private static Struct cfmlBasedFunction(PageContext pc, FunctionLibFunction function) throws PageException {
    Struct sct = new StructImpl();
    ArrayList<FunctionLibFunctionArg> args = function.getArg();
    String filename = Caster.toString(args.get(0).getDefaultValue());
    Key name = KeyImpl.toKey(args.get(1).getDefaultValue());
    boolean isWeb = Caster.toBooleanValue(args.get(2).getDefaultValue());
    UDF udf = CFFunction.loadUDF(pc, filename, name, isWeb);
    sct.set(KeyConstants._name, function.getName());
    sct.set(ARGUMENT_TYPE, "fixed");
    sct.set(KeyConstants._description, StringUtil.emptyIfNull(udf.getHint()));
    sct.set(RETURN_TYPE, StringUtil.emptyIfNull(udf.getReturnTypeAsString()));
    sct.set(KeyConstants._type, "cfml");
    sct.set(SOURCE, udf.getSource());
    sct.set(KeyConstants._status, "implemeted");
    FunctionArgument[] fas = udf.getFunctionArguments();
    Array _args = new ArrayImpl();
    sct.set(KeyConstants._arguments, _args);
    int min = 0, max = 0;
    for (int i = 0; i < fas.length; i++) {
        FunctionArgument fa = fas[i];
        Struct meta = fa.getMetaData();
        Struct _arg = new StructImpl();
        if (fa.isRequired())
            min++;
        max++;
        _arg.set(KeyConstants._required, fa.isRequired() ? Boolean.TRUE : Boolean.FALSE);
        _arg.set(KeyConstants._type, StringUtil.emptyIfNull(fa.getTypeAsString()));
        _arg.set(KeyConstants._name, StringUtil.emptyIfNull(fa.getName()));
        _arg.set(KeyConstants._description, StringUtil.emptyIfNull(fa.getHint()));
        String status;
        if (meta == null)
            status = "implemeted";
        else
            status = TagLibFactory.toStatus(TagLibFactory.toStatus(Caster.toString(meta.get(KeyConstants._status, "implemeted"))));
        _arg.set(KeyConstants._status, status);
        _args.append(_arg);
    }
    sct.set(ARG_MIN, Caster.toDouble(min));
    sct.set(ARG_MAX, Caster.toDouble(max));
    return sct;
}
Also used : ArrayImpl(lucee.runtime.type.ArrayImpl) Struct(lucee.runtime.type.Struct) Array(lucee.runtime.type.Array) StructImpl(lucee.runtime.type.StructImpl) UDF(lucee.runtime.type.UDF) FunctionArgument(lucee.runtime.type.FunctionArgument) FunctionLibFunctionArg(lucee.transformer.library.function.FunctionLibFunctionArg) Key(lucee.runtime.type.Collection.Key)

Example 79 with Array

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

the class QueryColumnData method call.

public static Array call(PageContext pc, Query query, String columnName, UDF udf) throws PageException {
    Array arr = new ArrayImpl();
    QueryColumn column = query.getColumn(KeyImpl.init(columnName));
    Iterator<Object> it = column.valueIterator();
    Object value;
    short type = SQLCaster.toCFType(column.getType(), lucee.commons.lang.CFTypes.TYPE_UNDEFINED);
    while (it.hasNext()) {
        value = it.next();
        if (!NullSupportHelper.full(pc) && value == null)
            value = "";
        // callback call
        if (udf != null)
            value = udf.call(pc, new Object[] { value }, true);
        // convert (if necessary)
        value = Caster.castTo(pc, type, column.getTypeAsString(), value, value);
        arr.append(value);
    }
    return arr;
}
Also used : Array(lucee.runtime.type.Array) QueryColumn(lucee.runtime.type.QueryColumn) ArrayImpl(lucee.runtime.type.ArrayImpl)

Example 80 with Array

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

the class QueryDeleteColumn method toArray.

public static Array toArray(QueryColumn column) throws PageException {
    Array clone = new ArrayImpl();
    int len = column.size();
    clone.resize(len);
    for (int i = 1; i <= len; i++) {
        clone.setE(i, QueryUtil.getValue(column, i));
    }
    return clone;
}
Also used : Array(lucee.runtime.type.Array) ArrayImpl(lucee.runtime.type.ArrayImpl)

Aggregations

Array (lucee.runtime.type.Array)169 ArrayImpl (lucee.runtime.type.ArrayImpl)79 Struct (lucee.runtime.type.Struct)49 StructImpl (lucee.runtime.type.StructImpl)25 Iterator (java.util.Iterator)24 PageException (lucee.runtime.exp.PageException)23 Entry (java.util.Map.Entry)22 ArrayList (java.util.ArrayList)20 Key (lucee.runtime.type.Collection.Key)20 ListIterator (java.util.ListIterator)16 Query (lucee.runtime.type.Query)16 List (java.util.List)14 ApplicationException (lucee.runtime.exp.ApplicationException)14 FunctionException (lucee.runtime.exp.FunctionException)14 ForEachQueryIterator (lucee.runtime.type.it.ForEachQueryIterator)14 Resource (lucee.commons.io.res.Resource)13 IOException (java.io.IOException)12 Collection (lucee.runtime.type.Collection)10 QueryImpl (lucee.runtime.type.QueryImpl)10 JavaObject (lucee.runtime.java.JavaObject)8