Search in sources :

Example 1 with TextListPropertyType

use of ietf.params.xml.ns.icalendar_2.TextListPropertyType in project bw-calendar-engine by Bedework.

the class LangTextListPropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    BwEvent ev = ui.getEvent();
    Collection<String> adds = new ArrayList<String>();
    Collection<String> removes = new ArrayList<String>();
    /* Figure out what we need to add/remove */
    TextListPropertyType prop = (TextListPropertyType) ui.getProp();
    String lang = UpdaterUtil.getLang(ui.getProp());
    if (ui.isAdd()) {
        adds.addAll(prop.getText());
    } else if (ui.isRemove()) {
        removes.addAll(prop.getText());
    } else {
        // Diff the prop value and the updProp value
        TextListPropertyType updProp = (TextListPropertyType) ui.getUpdprop();
        List<String> oldVals = prop.getText();
        List<String> updVals = updProp.getText();
        for (String s : updVals) {
            if (!oldVals.contains(s)) {
                adds.add(s);
            }
        }
        for (String s : oldVals) {
            if (!updVals.contains(s)) {
                removes.add(s);
            }
        }
    }
    for (String s : adds) {
        addValue(ev, new BwString(lang, s), ui);
    }
    for (String s : removes) {
        if (!removeValue(ev, new BwString(lang, s), ui)) {
            break;
        }
    }
    return UpdateResult.getOkResult();
}
Also used : TextListPropertyType(ietf.params.xml.ns.icalendar_2.TextListPropertyType) ArrayList(java.util.ArrayList) BwEvent(org.bedework.calfacade.BwEvent) List(java.util.List) ArrayList(java.util.ArrayList) BwString(org.bedework.calfacade.BwString) BwString(org.bedework.calfacade.BwString)

Aggregations

TextListPropertyType (ietf.params.xml.ns.icalendar_2.TextListPropertyType)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BwEvent (org.bedework.calfacade.BwEvent)1 BwString (org.bedework.calfacade.BwString)1