Search in sources :

Example 41 with ArrayImpl

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

the class StructFindValue method call.

public static Array call(PageContext pc, Struct struct, String value, String scope) throws PageException {
    // Scope
    boolean all = false;
    if (scope.equalsIgnoreCase("one"))
        all = false;
    else if (scope.equalsIgnoreCase("all"))
        all = true;
    else
        throw new FunctionException(pc, "structFindValue", 3, "scope", "invalid scope definition [" + scope + "], valid scopes are [one, all]");
    Array array = new ArrayImpl();
    getValues(pc, array, struct, value, all, "");
    return array;
}
Also used : Array(lucee.runtime.type.Array) ArrayImpl(lucee.runtime.type.ArrayImpl) FunctionException(lucee.runtime.exp.FunctionException)

Example 42 with ArrayImpl

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

the class StructSort method call.

public static Array call(PageContext pc, Struct base, String sortType, String sortOrder, String pathToSubElement) throws PageException {
    boolean isAsc = true;
    PageException ee = null;
    if (sortOrder.equalsIgnoreCase("asc"))
        isAsc = true;
    else if (sortOrder.equalsIgnoreCase("desc"))
        isAsc = false;
    else
        throw new ExpressionException("invalid sort order type [" + sortOrder + "], sort order types are [asc and desc]");
    Collection.Key[] keys = CollectionUtil.keys(base);
    SortRegister[] arr = new SortRegister[keys.length];
    boolean hasSubDef = pathToSubElement != null;
    for (int i = 0; i < keys.length; i++) {
        Object value = base.get(keys[i], null);
        if (hasSubDef) {
            value = VariableInterpreter.getVariable(pc, Caster.toCollection(value), pathToSubElement);
        }
        arr[i] = new SortRegister(i, value);
    }
    ExceptionComparator comp = null;
    // text
    if (sortType.equalsIgnoreCase("text"))
        comp = new SortRegisterComparator(pc, isAsc, false, true);
    else // text no case
    if (sortType.equalsIgnoreCase("textnocase"))
        comp = new SortRegisterComparator(pc, isAsc, true, true);
    else // numeric
    if (sortType.equalsIgnoreCase("numeric"))
        comp = new NumberSortRegisterComparator(isAsc);
    else {
        throw new ExpressionException("invalid sort type [" + sortType + "], sort types are [text, textNoCase, numeric]");
    }
    Arrays.sort(arr, 0, arr.length, comp);
    ee = comp.getPageException();
    if (ee != null) {
        throw ee;
    }
    Array rtn = new ArrayImpl();
    for (int i = 0; i < arr.length; i++) {
        rtn.append(keys[arr[i].getOldPosition()].getString());
    }
    return rtn;
}
Also used : PageException(lucee.runtime.exp.PageException) ArrayImpl(lucee.runtime.type.ArrayImpl) ExpressionException(lucee.runtime.exp.ExpressionException) SortRegister(lucee.runtime.type.comparator.SortRegister) ExceptionComparator(lucee.runtime.type.comparator.ExceptionComparator) Array(lucee.runtime.type.Array) SortRegisterComparator(lucee.runtime.type.comparator.SortRegisterComparator) NumberSortRegisterComparator(lucee.runtime.type.comparator.NumberSortRegisterComparator) NumberSortRegisterComparator(lucee.runtime.type.comparator.NumberSortRegisterComparator)

Example 43 with ArrayImpl

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

the class BundleInfo method toArray2.

private static Array toArray2(List<PackageQuery> list) {
    Struct sct, _sct;
    Array arr = new ArrayImpl(), _arr;
    Iterator<PackageQuery> it = list.iterator();
    PackageQuery pd;
    Iterator<VersionDefinition> _it;
    VersionDefinition vd;
    while (it.hasNext()) {
        pd = it.next();
        sct = new StructImpl();
        sct.setEL(KeyConstants._package, pd.getName());
        sct.setEL("versions", _arr = new ArrayImpl());
        _it = pd.getVersionDefinitons().iterator();
        while (_it.hasNext()) {
            vd = _it.next();
            _sct = new StructImpl();
            _sct.setEL(KeyConstants._bundleVersion, vd.getVersion().toString());
            _sct.setEL("operator", vd.getOpAsString());
            _arr.appendEL(_sct);
        }
        arr.appendEL(sct);
    }
    return arr;
}
Also used : Array(lucee.runtime.type.Array) VersionDefinition(lucee.runtime.osgi.OSGiUtil.VersionDefinition) StructImpl(lucee.runtime.type.StructImpl) PackageQuery(lucee.runtime.osgi.OSGiUtil.PackageQuery) ArrayImpl(lucee.runtime.type.ArrayImpl) Struct(lucee.runtime.type.Struct)

Example 44 with ArrayImpl

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

the class BundleInfo method toArray1.

private static Array toArray1(List<BundleDefinition> list) {
    Struct sct;
    Array arr = new ArrayImpl();
    Iterator<BundleDefinition> it = list.iterator();
    BundleDefinition bd;
    VersionDefinition vd;
    while (it.hasNext()) {
        bd = it.next();
        sct = new StructImpl();
        sct.setEL(KeyConstants._bundleName, bd.getName());
        vd = bd.getVersionDefiniton();
        if (vd != null) {
            sct.setEL(KeyConstants._bundleVersion, vd.getVersionAsString());
            sct.setEL("operator", vd.getOpAsString());
        }
        arr.appendEL(sct);
    }
    return arr;
}
Also used : Array(lucee.runtime.type.Array) BundleDefinition(lucee.runtime.osgi.OSGiUtil.BundleDefinition) VersionDefinition(lucee.runtime.osgi.OSGiUtil.VersionDefinition) StructImpl(lucee.runtime.type.StructImpl) ArrayImpl(lucee.runtime.type.ArrayImpl) Struct(lucee.runtime.type.Struct)

Example 45 with ArrayImpl

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

the class CallStackGet method call.

public static Object call(PageContext pc) {
    Array arr = new ArrayImpl();
    _getTagContext(pc, arr, new Exception("Stack trace"), LINE_NUMBER);
    return arr;
}
Also used : Array(lucee.runtime.type.Array) ArrayImpl(lucee.runtime.type.ArrayImpl) FunctionException(lucee.runtime.exp.FunctionException) PageException(lucee.runtime.exp.PageException)

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