Search in sources :

Example 1 with CastableArray

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

the class FeedQuery method toStruct.

private static Struct toStruct(Object value) {
    if (value instanceof Struct)
        return (Struct) value;
    if (value instanceof Array) {
        Struct sct = new StructImpl(), row;
        Array arr = (Array) value;
        int len = arr.size();
        // Key[] keys;
        Iterator<Entry<Key, Object>> it;
        Entry<Key, Object> e;
        String nw;
        Object ext;
        for (int i = 1; i <= len; i++) {
            row = Caster.toStruct(arr.get(i, null), null, false);
            if (row == null)
                continue;
            it = row.entryIterator();
            // keys = row.keys();
            while (it.hasNext()) {
                e = it.next();
                ext = sct.get(e.getKey(), null);
                nw = Caster.toString(e.getValue(), null);
                if (nw != null) {
                    if (ext == null)
                        sct.setEL(e.getKey(), nw);
                    else if (ext instanceof CastableArray) {
                        ((CastableArray) ext).appendEL(nw);
                    } else {
                        CastableArray ca = new CastableArray();
                        ca.appendEL(Caster.toString(ext, null));
                        ca.appendEL(nw);
                        sct.setEL(e.getKey(), ca);
                    }
                }
            }
        }
        return sct;
    }
    return null;
}
Also used : CastableArray(lucee.runtime.type.CastableArray) Array(lucee.runtime.type.Array) Entry(java.util.Map.Entry) StructImpl(lucee.runtime.type.StructImpl) CastableArray(lucee.runtime.type.CastableArray) Key(lucee.runtime.type.Collection.Key) Struct(lucee.runtime.type.Struct)

Example 2 with CastableArray

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

the class FeedHandler method startElement.

@Override
public void startElement(String uri, String name, String qName, Attributes atts) {
    deep++;
    if ("entry".equals(name))
        inEntry = true;
    else if ("author".equals(name))
        inAuthor = true;
    if (qName.startsWith("dc:")) {
        name = "dc_" + name;
        hasDC = true;
    }
    inside = KeyImpl.getInstance(name);
    if (StringUtil.isEmpty(path))
        path = name;
    else {
        path += "." + name;
    }
    if (decl == null) {
        String decName = name;
        String version = atts.getValue("version");
        if ("feed".equals(decName)) {
            if (!StringUtil.isEmpty(version))
                decName = "atom_" + version;
            else
                decName = "atom_1.0";
        } else {
            if (!StringUtil.isEmpty(version))
                decName += "_" + version;
        }
        decl = FeedDeclaration.getInstance(decName);
        root.put("version", decName);
        isAtom = decl.getType().equals("atom");
    }
    FeedStruct sct = new FeedStruct(path, inside, uri);
    // attributes
    Map<String, String> attrs = getAttributes(atts, path);
    if (attrs != null) {
        Entry<String, String> entry;
        Iterator<Entry<String, String>> it = attrs.entrySet().iterator();
        sct.setHasAttribute(true);
        while (it.hasNext()) {
            entry = it.next();
            sct.setEL(entry.getKey(), entry.getValue());
        }
    }
    // assign
    if (!isAtom || deep < 4) {
        Object obj = data.get(inside, null);
        if (obj instanceof Array) {
            ((Array) obj).appendEL(sct);
        } else if (obj instanceof FeedStruct) {
            Array arr = new ArrayImpl();
            arr.appendEL(obj);
            arr.appendEL(sct);
            data.setEL(inside, arr);
        } else if (obj instanceof String) {
        // wenn wert schon existiert wird castableArray in setContent erstellt
        } else {
            El el = decl.getDeclaration().get(path);
            if (el != null && (el.getQuantity() == El.QUANTITY_0_N || el.getQuantity() == El.QUANTITY_1_N)) {
                Array arr = new ArrayImpl();
                arr.appendEL(sct);
                data.setEL(inside, arr);
            } else
                data.setEL(inside, sct);
        }
    }
    parents.add(data);
    data = sct;
// <enclosure url="http://www.scripting.com/mp3s/weatherReportDicksPicsVol7.mp3" length="6182912" type="audio/mpeg"/>
}
Also used : Array(lucee.runtime.type.Array) CastableArray(lucee.runtime.type.CastableArray) Entry(java.util.Map.Entry) ArrayImpl(lucee.runtime.type.ArrayImpl)

Aggregations

Entry (java.util.Map.Entry)2 Array (lucee.runtime.type.Array)2 CastableArray (lucee.runtime.type.CastableArray)2 ArrayImpl (lucee.runtime.type.ArrayImpl)1 Key (lucee.runtime.type.Collection.Key)1 Struct (lucee.runtime.type.Struct)1 StructImpl (lucee.runtime.type.StructImpl)1