Search in sources :

Example 51 with ArrayImpl

use of lucee.runtime.type.ArrayImpl 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 52 with ArrayImpl

use of lucee.runtime.type.ArrayImpl 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 53 with ArrayImpl

use of lucee.runtime.type.ArrayImpl 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)

Example 54 with ArrayImpl

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

the class QuerySetColumn method call.

public static String call(PageContext pc, Query query, String columnName, String newColumnName) throws PageException {
    columnName = columnName.trim();
    newColumnName = newColumnName.trim();
    Collection.Key src = KeyImpl.getInstance(columnName);
    Collection.Key trg = KeyImpl.getInstance(newColumnName);
    Query qp = Caster.toQuery(query, null);
    if (qp != null)
        qp.rename(src, trg);
    else {
        QueryColumn qc = query.removeColumn(src);
        Array content = new ArrayImpl();
        int len = qc.size();
        for (int i = 1; i <= len; i++) {
            content.setE(i, qc.get(i, null));
        }
        query.addColumn(trg, content, qc.getType());
    }
    return null;
}
Also used : Array(lucee.runtime.type.Array) Query(lucee.runtime.type.Query) QueryColumn(lucee.runtime.type.QueryColumn) ArrayImpl(lucee.runtime.type.ArrayImpl) Collection(lucee.runtime.type.Collection)

Example 55 with ArrayImpl

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

the class ValueArray method call.

public static Array call(PageContext pc, QueryColumn column) throws PageException {
    Array arr = new ArrayImpl();
    int size = column.size();
    Object obj;
    short type = SQLCaster.toCFType(column.getType(), lucee.commons.lang.CFTypes.TYPE_UNDEFINED);
    for (int i = 1; i <= size; i++) {
        obj = column.get(i, null);
        try {
            obj = Caster.castTo(pc, type, column.getTypeAsString(), obj);
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
        }
        arr.append(obj);
    }
    return arr;
}
Also used : Array(lucee.runtime.type.Array) ArrayImpl(lucee.runtime.type.ArrayImpl)

Aggregations

ArrayImpl (lucee.runtime.type.ArrayImpl)100 Array (lucee.runtime.type.Array)79 Struct (lucee.runtime.type.Struct)33 StructImpl (lucee.runtime.type.StructImpl)24 PageException (lucee.runtime.exp.PageException)14 Entry (java.util.Map.Entry)13 Key (lucee.runtime.type.Collection.Key)12 ArgumentIntKey (lucee.runtime.type.scope.ArgumentIntKey)8 IOException (java.io.IOException)7 Iterator (java.util.Iterator)7 ArrayList (java.util.ArrayList)6 ListIterator (java.util.ListIterator)6 FunctionException (lucee.runtime.exp.FunctionException)6 ForEachQueryIterator (lucee.runtime.type.it.ForEachQueryIterator)6 ApplicationException (lucee.runtime.exp.ApplicationException)5 ExpressionException (lucee.runtime.exp.ExpressionException)5 Query (lucee.runtime.type.Query)5 QueryImpl (lucee.runtime.type.QueryImpl)5 ListAsArray (lucee.runtime.type.wrap.ListAsArray)5 NodeList (org.w3c.dom.NodeList)5