Search in sources :

Example 96 with ArrayImpl

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

the class Caster method toArray.

/**
 * cast a Object to a Array Object
 * @param o Object to cast
 * @param defaultValue
 * @return casted Array
 */
public static Array toArray(Object o, Array defaultValue) {
    if (o instanceof Array)
        return (Array) o;
    else if (o instanceof Object[]) {
        return new ArrayImpl((Object[]) o);
    } else if (o instanceof List) {
        return new ArrayImpl(((List) o).toArray());
    } else if (o instanceof Set) {
        return new ArrayImpl(((Set) o).toArray());
    } else if (o instanceof XMLStruct) {
        Array arr = new ArrayImpl();
        arr.appendEL(o);
        return arr;
    } else if (o instanceof ObjectWrap) {
        return toArray(((ObjectWrap) o).getEmbededObject(defaultValue), defaultValue);
    // if(io!=null)return toArray(io,defaultValue);
    } else if (o instanceof Struct) {
        Struct sct = (Struct) o;
        Array arr = new ArrayImpl();
        Iterator<Entry<Key, Object>> it = sct.entryIterator();
        Entry<Key, Object> e = null;
        try {
            while (it.hasNext()) {
                e = it.next();
                arr.setEL(toIntValue(e.getKey().getString()), e.getValue());
            }
        } catch (ExpressionException ee) {
            return defaultValue;
        }
        return arr;
    } else if (o instanceof boolean[])
        return new ArrayImpl(ArrayUtil.toReferenceType((boolean[]) o));
    else if (o instanceof byte[])
        return new ArrayImpl(ArrayUtil.toReferenceType((byte[]) o));
    else if (o instanceof char[])
        return new ArrayImpl(ArrayUtil.toReferenceType((char[]) o));
    else if (o instanceof short[])
        return new ArrayImpl(ArrayUtil.toReferenceType((short[]) o));
    else if (o instanceof int[])
        return new ArrayImpl(ArrayUtil.toReferenceType((int[]) o));
    else if (o instanceof long[])
        return new ArrayImpl(ArrayUtil.toReferenceType((long[]) o));
    else if (o instanceof float[])
        return new ArrayImpl(ArrayUtil.toReferenceType((float[]) o));
    else if (o instanceof double[])
        return new ArrayImpl(ArrayUtil.toReferenceType((double[]) o));
    return defaultValue;
}
Also used : ResultSet(java.sql.ResultSet) Set(java.util.Set) ObjectWrap(lucee.runtime.type.ObjectWrap) ArrayImpl(lucee.runtime.type.ArrayImpl) ExpressionException(lucee.runtime.exp.ExpressionException) XMLMultiElementStruct(lucee.runtime.text.xml.struct.XMLMultiElementStruct) XMLStruct(lucee.runtime.text.xml.struct.XMLStruct) ObjectStruct(lucee.runtime.type.scope.ObjectStruct) MapAsStruct(lucee.runtime.type.wrap.MapAsStruct) Struct(lucee.runtime.type.Struct) CollectionStruct(lucee.runtime.type.CollectionStruct) Array(lucee.runtime.type.Array) XMLMultiElementArray(lucee.runtime.text.xml.struct.XMLMultiElementArray) ListAsArray(lucee.runtime.type.wrap.ListAsArray) Entry(java.util.Map.Entry) XMLStruct(lucee.runtime.text.xml.struct.XMLStruct) JavaObject(lucee.runtime.java.JavaObject) ArrayList(java.util.ArrayList) ArrayAsList(lucee.runtime.type.wrap.ArrayAsList) List(java.util.List) NodeList(org.w3c.dom.NodeList) Key(lucee.runtime.type.Collection.Key)

Example 97 with ArrayImpl

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

the class GetFunctionData method javaBasedFunction.

private static Struct javaBasedFunction(FunctionLibFunction function) throws PageException {
    Struct sct = new StructImpl();
    sct.set(KeyConstants._name, function.getName());
    sct.set(KeyConstants._status, TagLibFactory.toStatus(function.getStatus()));
    if (function.getIntroduced() != null)
        sct.set(INTRODUCED, function.getIntroduced().toString());
    // else if(inside.equals("introduced"))	att.setIntroduced(value);
    sct.set(KeyConstants._description, StringUtil.emptyIfNull(function.getDescription()));
    if (!ArrayUtil.isEmpty(function.getKeywords()))
        sct.set("keywords", Caster.toArray(function.getKeywords()));
    sct.set(RETURN_TYPE, StringUtil.emptyIfNull(function.getReturnTypeAsString()));
    sct.set(ARGUMENT_TYPE, StringUtil.emptyIfNull(function.getArgTypeAsString()));
    sct.set(ARG_MIN, Caster.toDouble(function.getArgMin()));
    sct.set(ARG_MAX, Caster.toDouble(function.getArgMax()));
    sct.set(KeyConstants._type, "java");
    String[] names = function.getMemberNames();
    if (!ArrayUtil.isEmpty(names) && function.getMemberType() != CFTypes.TYPE_UNKNOW) {
        StructImpl mem = new StructImpl();
        sct.set(KeyConstants._member, mem);
        mem.set(KeyConstants._name, names[0]);
        mem.set(KeyConstants._chaining, Caster.toBoolean(function.getMemberChaining()));
        mem.set(KeyConstants._type, function.getMemberTypeAsString());
        mem.set("position", Caster.toDouble(function.getMemberPosition()));
    }
    Array _args = new ArrayImpl();
    sct.set(KeyConstants._arguments, _args);
    if (function.getArgType() != FunctionLibFunction.ARG_DYNAMIC) {
        ArrayList<FunctionLibFunctionArg> args = function.getArg();
        for (int i = 0; i < args.size(); i++) {
            FunctionLibFunctionArg arg = args.get(i);
            Struct _arg = new StructImpl();
            _arg.set(KeyConstants._required, arg.getRequired() ? Boolean.TRUE : Boolean.FALSE);
            _arg.set(KeyConstants._type, StringUtil.emptyIfNull(arg.getTypeAsString()));
            _arg.set(KeyConstants._name, StringUtil.emptyIfNull(arg.getName()));
            _arg.set(KeyConstants._status, TagLibFactory.toStatus(arg.getStatus()));
            if (arg.getIntroduced() != null)
                _arg.set(INTRODUCED, arg.getIntroduced().toString());
            _arg.set("defaultValue", arg.getDefaultValue());
            _arg.set(KeyConstants._description, StringUtil.toStringEmptyIfNull(arg.getDescription()));
            _args.append(_arg);
        }
    }
    return sct;
}
Also used : Array(lucee.runtime.type.Array) StructImpl(lucee.runtime.type.StructImpl) ArrayImpl(lucee.runtime.type.ArrayImpl) FunctionLibFunctionArg(lucee.transformer.library.function.FunctionLibFunctionArg) Struct(lucee.runtime.type.Struct)

Example 98 with ArrayImpl

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

the class QueryNew method _populate.

private static Query _populate(PageContext pc, Query qry, Struct data) throws PageException {
    Iterator<Entry<Key, Object>> it = data.entryIterator();
    Entry<Key, Object> e;
    Object v;
    Array arr;
    int rows = qry.getRecordcount();
    while (it.hasNext()) {
        e = it.next();
        if (qry.getColumn(e.getKey(), null) != null) {
            v = e.getValue();
            arr = Caster.toArray(v, null);
            if (arr == null)
                arr = new ArrayImpl(new Object[] { v });
            populateColumn(qry, e.getKey(), arr, rows);
        }
    }
    return qry;
}
Also used : Array(lucee.runtime.type.Array) Entry(java.util.Map.Entry) ArrayImpl(lucee.runtime.type.ArrayImpl) Key(lucee.runtime.type.Collection.Key)

Example 99 with ArrayImpl

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

the class FontUtil method getAvailableFontsAsStringArray.

public static Array getAvailableFontsAsStringArray() {
    Iterator<Object> it = getAvailableFonts(false).valueIterator();
    Array arr = new ArrayImpl();
    while (it.hasNext()) {
        arr.appendEL(((Font) it.next()).getFontName());
    }
    return arr;
}
Also used : Array(lucee.runtime.type.Array) ArrayImpl(lucee.runtime.type.ArrayImpl) SerializableObject(lucee.commons.lang.SerializableObject)

Example 100 with ArrayImpl

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

the class FontUtil method getAvailableFonts.

private static Array getAvailableFonts(boolean duplicate) {
    synchronized (sync) {
        if (fonts == null) {
            fonts = new ArrayImpl();
            GraphicsEnvironment graphicsEvn = GraphicsEnvironment.getLocalGraphicsEnvironment();
            Font[] availableFonts = graphicsEvn.getAllFonts();
            for (int i = 0; i < availableFonts.length; i++) {
                fonts.appendEL(availableFonts[i]);
            }
        }
        if (!duplicate)
            return fonts;
        return (Array) Duplicator.duplicate(fonts, false);
    }
}
Also used : Array(lucee.runtime.type.Array) ArrayImpl(lucee.runtime.type.ArrayImpl) GraphicsEnvironment(java.awt.GraphicsEnvironment) Font(java.awt.Font)

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