Search in sources :

Example 6 with BwXproperty

use of org.bedework.calfacade.BwXproperty in project bw-calendar-engine by Bedework.

the class IcalUtil method xpropertiesToIcal.

/**
 * @param pl
 * @param xprops
 * @throws Throwable
 */
@SuppressWarnings("deprecation")
public static void xpropertiesToIcal(final PropertyList pl, final List<BwXproperty> xprops) throws Throwable {
    for (BwXproperty x : xprops) {
        String xname = x.getName();
        if (xname.equals(BwXproperty.bedeworkIcalProp)) {
            // Some get squirreled away in here -mostly for alarms
            List<Xpar> params = x.getParameters();
            String pname = params.get(0).getValue();
            if (params.size() == 1) {
                params = null;
            } else {
                params = new ArrayList<Xpar>(params);
                params.remove(0);
            }
            // XXX Need to be able to do this in ical4j - create property by name
            if (pname.equals("UID")) {
                pl.add(new Uid(makeXparlist(params), x.getValue()));
            }
        }
        if (x.getSkip()) {
            continue;
        }
        // Skip any timezone we saved in the event.
        if (xname.startsWith(BwXproperty.bedeworkTimezonePrefix)) {
            continue;
        }
        addXproperty(pl, xname, x.getParameters(), x.getValue());
    }
}
Also used : Xpar(org.bedework.calfacade.BwXproperty.Xpar) Uid(net.fortuna.ical4j.model.property.Uid) BwXproperty(org.bedework.calfacade.BwXproperty)

Example 7 with BwXproperty

use of org.bedework.calfacade.BwXproperty in project bw-calendar-engine by Bedework.

the class EventTimeZonesRegistry method findTzValue.

/**
 * @param ev
 * @param tzId
 * @return tz spec or null.
 */
@SuppressWarnings("deprecation")
public static String findTzValue(final BwEvent ev, final String tzId) {
    if (ev == null) {
        return null;
    }
    Collection<BwXproperty> xps = ev.getXproperties();
    if (Util.isEmpty(xps)) {
        // Try the old way
        xps = ev.getXproperties(BwXproperty.escapeName(BwXproperty.bedeworkTimezonePrefix + tzId));
        if (Util.isEmpty(xps)) {
            return null;
        }
        return xps.iterator().next().getValue();
    }
    for (BwXproperty xp : xps) {
        String val = xp.getValue();
        // value is semicolon escaped name ";" then tzspec
        int pos = BwXproperty.nextSemi(val, 0);
        if (pos < 0) {
            // bad
            continue;
        }
        String id = BwXproperty.unescapeSemi(val.substring(0, pos));
        if (id.equals(tzId)) {
            return val.substring(pos + 1);
        }
    }
    return null;
}
Also used : BwXproperty(org.bedework.calfacade.BwXproperty)

Example 8 with BwXproperty

use of org.bedework.calfacade.BwXproperty in project bw-calendar-engine by Bedework.

the class BwCalDAVEvent method generatePropertyValue.

@Override
public boolean generatePropertyValue(final QName tag, final XmlEmit xml) throws WebdavException {
    try {
        BwEvent ev = getEv();
        if (tag.equals(CaldavTags.scheduleTag)) {
            if (!ev.getOrganizerSchedulingObject() && !ev.getAttendeeSchedulingObject()) {
                return false;
            }
            xml.property(tag, ev.getStag());
            return true;
        }
        if (tag.equals(CaldavTags.originator)) {
            if (ev.getOriginator() != null) {
                xml.openTag(tag);
                xml.property(WebdavTags.href, ev.getOriginator());
                xml.closeTag(tag);
            }
            return true;
        }
        if (tag.equals(CaldavTags.recipient)) {
            Collection<String> r = ev.getRecipients();
            if ((r == null) || (r.isEmpty())) {
                return true;
            }
            xml.openTag(tag);
            for (String recip : r) {
                xml.property(WebdavTags.href, recip);
            }
            xml.closeTag(tag);
            return true;
        }
        if (tag.equals(AppleServerTags.scheduleChanges)) {
            List<BwXproperty> xps = ev.getXproperties(BwXproperty.bedeworkChanges);
            if (Util.isEmpty(xps)) {
                return true;
            }
            BwXproperty xp = xps.get(0);
            String[] vals = xp.getValue().split(";");
            xml.openTag(tag);
            xml.property(AppleServerTags.dtstamp, vals[0]);
            xml.openTag(AppleServerTags.action);
            QName actionTag;
            if ("CANCEL".equals(vals[1])) {
                actionTag = AppleServerTags.cancel;
            } else if ("CREATE".equals(vals[1])) {
                actionTag = AppleServerTags.create;
            } else if ("REPLY".equals(vals[1])) {
                actionTag = AppleServerTags.reply;
            } else {
                // "UPDATE"
                actionTag = AppleServerTags.update;
            }
            xml.openTag(actionTag);
            int i = 2;
            while (i < vals.length) {
                /* Next is master or rid */
                xml.openTag(AppleServerTags.recurrence);
                String val = vals[i];
                if ("MASTER".equals(val)) {
                    xml.emptyTag(AppleServerTags.master);
                    i++;
                }
                if (val.startsWith("RID=")) {
                    xml.openTagNoNewline(AppleServerTags.recurrenceid);
                    xml.value(val);
                    xml.closeTag(AppleServerTags.recurrenceid);
                    i++;
                }
                if ((i < vals.length) && "CHANGES".equals(vals[i])) {
                    i++;
                    xml.openTag(AppleServerTags.changes);
                    while (i < vals.length) {
                        val = vals[i];
                        if ("MASTER".equals(val) || "CHANGES".equals(val) || val.startsWith("RID=")) {
                            break;
                        }
                        xml.startTag(AppleServerTags.changedProperty);
                        xml.attribute("name", val);
                        xml.endEmptyTag();
                        i++;
                    }
                    xml.closeTag(AppleServerTags.changes);
                }
                xml.closeTag(AppleServerTags.recurrence);
            }
            xml.closeTag(actionTag);
            xml.closeTag(AppleServerTags.action);
            xml.closeTag(tag);
            return true;
        }
        if (tag.equals(ICalTags.action)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.attach)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.attendee)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.categories)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags._class)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.comment)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.completed)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.contact)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.created)) {
            xml.property(tag, ev.getCreated());
            return true;
        }
        if (tag.equals(ICalTags.description)) {
            if (ev.getDescription() != null) {
                xml.property(tag, ev.getDescription());
            }
            return true;
        }
        if (tag.equals(ICalTags.dtend)) {
            xml.property(tag, ev.getDtend().getDate());
            return true;
        }
        if (tag.equals(ICalTags.dtstamp)) {
            xml.property(tag, ev.getDtstamp());
            return true;
        }
        if (tag.equals(ICalTags.dtstart)) {
            xml.property(tag, ev.getDtstart().getDate());
            return true;
        }
        if (tag.equals(ICalTags.duration)) {
            xml.property(tag, ev.getDuration());
            return true;
        }
        if (tag.equals(ICalTags.exdate)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.exrule)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.freebusy)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.geo)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.lastModified)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.lastModified)) {
            xml.property(tag, ev.getLastmod());
            return true;
        }
        if (tag.equals(ICalTags.location)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.organizer)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.organizer)) {
            if (ev.getOrganizer() != null) {
                xml.property(tag, ev.getOrganizer().getOrganizerUri());
            }
            return true;
        }
        if (tag.equals(ICalTags.percentComplete)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.priority)) {
            Integer val = ev.getPriority();
            if ((val != null) && (val != 0)) {
                xml.property(tag, String.valueOf(val));
            }
            return true;
        }
        if (tag.equals(ICalTags.rdate)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.recurrenceId)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.recurrenceId)) {
            if (ev.getRecurrenceId() != null) {
                xml.property(tag, ev.getRecurrenceId());
            }
            return true;
        }
        if (tag.equals(ICalTags.relatedTo)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.repeat)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.resources)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.requestStatus)) {
            /*
      if (ev.getRequestStatus() != null) {
        xml.property(tag, ev.getRequestStatus().strVal());
      }
         */
            return true;
        }
        if (tag.equals(ICalTags.rrule)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.sequence)) {
            xml.property(tag, String.valueOf(ev.getSequence()));
            return true;
        }
        if (tag.equals(ICalTags.status)) {
            xml.property(tag, ev.getStatus());
            return true;
        }
        if (tag.equals(ICalTags.summary)) {
            xml.property(tag, ev.getSummary());
            return true;
        }
        if (tag.equals(ICalTags.transp)) {
            xml.property(tag, ev.getPeruserTransparency(intf.getPrincipal().getPrincipalRef()));
            return true;
        }
        if (tag.equals(ICalTags.trigger)) {
            // PROPTODO
            return true;
        }
        if (tag.equals(ICalTags.uid)) {
            xml.property(tag, ev.getUid());
            return true;
        }
        if (tag.equals(ICalTags.url)) {
            if (ev.getLink() != null) {
                xml.property(tag, ev.getLink());
            }
            return true;
        }
        if (tag.equals(ICalTags.version)) {
            // PROPTODO
            return true;
        }
        return false;
    } catch (WebdavException wde) {
        throw wde;
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : BwXproperty(org.bedework.calfacade.BwXproperty) QName(javax.xml.namespace.QName) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent)

Example 9 with BwXproperty

use of org.bedework.calfacade.BwXproperty in project bw-calendar-engine by Bedework.

the class RelatedToPropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    ChangeTableEntry cte = ui.getCte();
    BwEvent ev = ui.getEvent();
    RelatedToPropType pr = (RelatedToPropType) ui.getProp();
    ReltypeParamType rtparm = (ReltypeParamType) UpdaterUtil.getParam(pr, XcalTags.reltype);
    String propRelType = "";
    String propValType;
    String propVal;
    if (rtparm != null) {
        propRelType = rtparm.getText();
    }
    if (pr.getText() != null) {
        propValType = "";
        propVal = pr.getText();
    } else if (pr.getUri() != null) {
        propValType = "URI";
        propVal = pr.getUri();
    } else {
        propValType = "UID";
        propVal = pr.getUid();
    }
    /* We encode related to (maybe) as triples - reltype, value-type, value */
    String[] info = null;
    BwXproperty xprop = null;
    BwRelatedTo relto = ev.getRelatedTo();
    if (relto != null) {
        info = new String[3];
        info[0] = relto.getRelType();
        // default
        info[1] = "";
        info[2] = relto.getValue();
    } else {
        xprop = ev.findXproperty(BwXproperty.bedeworkRelatedTo);
        if (xprop != null) {
            String relx = xprop.getValue();
            if (relx != null) {
                info = Util.decodeArray(relx);
            }
        }
    }
    int pos = findRT(info, propRelType, propValType, propVal);
    if (ui.isAdd()) {
        if (pos >= 0) {
            // Already there
            return UpdateResult.getOkResult();
        }
        int iPos = info.length;
        info = Arrays.copyOf(info, info.length + 3);
        info[iPos] = propRelType;
        info[iPos + 1] = propValType;
        info[iPos + 2] = propVal;
        ev.setRelatedTo(null);
        if (xprop == null) {
            xprop = new BwXproperty(BwXproperty.bedeworkRelatedTo, null, null);
            ev.addXproperty(xprop);
        }
        String newval = Util.encodeArray(info);
        xprop.setValue(newval);
        cte.addAddedValue(newval);
        return UpdateResult.getOkResult();
    }
    if (ui.isRemove()) {
        if (pos < 0) {
            // Nothing to remove
            return UpdateResult.getOkResult();
        }
        if (info.length == 3) {
            // removing only related-to
            ev.setRelatedTo(null);
            ev.removeXproperties(BwXproperty.bedeworkRelatedTo);
            return UpdateResult.getOkResult();
        }
        String[] newInfo = new String[info.length - 3];
        for (int i = 0; i < pos; i++) {
            newInfo[i] = info[i];
        }
        for (int i = pos + 3; i < info.length; i++) {
            newInfo[i] = info[i];
        }
        ev.setRelatedTo(null);
        if (xprop == null) {
            xprop = new BwXproperty(BwXproperty.bedeworkRelatedTo, null, null);
            ev.addXproperty(xprop);
        }
        String newval = Util.encodeArray(newInfo);
        xprop.setValue(newval);
        cte.addRemovedValue(newval);
        return UpdateResult.getOkResult();
    }
    if (ui.isChange()) {
        // Change a value
        if (pos < 0) {
            // Nothing to change
            return new UpdateResult("No comment to change");
        }
        info[pos] = propRelType;
        info[pos + 1] = propValType;
        info[pos + 2] = propVal;
        ev.setRelatedTo(null);
        if (xprop == null) {
            xprop = new BwXproperty(BwXproperty.bedeworkRelatedTo, null, null);
            ev.addXproperty(xprop);
        }
        String newval = Util.encodeArray(info);
        xprop.setValue(newval);
        cte.addChangedValue(newval);
        return UpdateResult.getOkResult();
    }
    return UpdateResult.getOkResult();
}
Also used : RelatedToPropType(ietf.params.xml.ns.icalendar_2.RelatedToPropType) BwRelatedTo(org.bedework.calfacade.BwRelatedTo) BwXproperty(org.bedework.calfacade.BwXproperty) ReltypeParamType(ietf.params.xml.ns.icalendar_2.ReltypeParamType) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)

Example 10 with BwXproperty

use of org.bedework.calfacade.BwXproperty in project bw-calendar-engine by Bedework.

the class DocBuilder method indexAlarms.

private void indexAlarms(final BwDateTime start, final Set<BwAlarm> alarms) throws CalFacadeException {
    try {
        if (Util.isEmpty(alarms)) {
            return;
        }
        startArray(getJname(PropertyInfoIndex.VALARM));
        for (final BwAlarm al : alarms) {
            startObject();
            makeField(PropertyInfoIndex.OWNER, al.getOwnerHref());
            makeField(PropertyInfoIndex.PUBLIC, al.getPublick());
            final int atype = al.getAlarmType();
            final String action;
            if (atype != BwAlarm.alarmTypeOther) {
                action = BwAlarm.alarmTypes[atype];
            } else {
                final List<BwXproperty> xps = al.getXicalProperties("ACTION");
                action = xps.get(0).getValue();
            }
            makeField(PropertyInfoIndex.ACTION, action);
            try {
                final Set<String> triggerTimes = new TreeSet<>();
                Date dt = null;
                for (int i = 0; i < 100; i++) {
                    // Arb limit
                    dt = al.getNextTriggerDate(start, dt);
                    if (dt == null) {
                        break;
                    }
                    triggerTimes.add(DateTimeUtil.isoDateTimeUTC(dt));
                }
                if (!Util.isEmpty(triggerTimes)) {
                    makeField(PropertyInfoIndex.NEXT_TRIGGER_DATE_TIME, triggerTimes);
                }
            } catch (final Throwable t) {
                error("Exception calculating next trigger");
                error(t);
            }
            makeField(PropertyInfoIndex.TRIGGER, al.getTrigger());
            if (al.getTriggerDateTime()) {
                makeField(PropertyInfoIndex.TRIGGER_DATE_TIME, true);
            } else if (!al.getTriggerStart()) {
                makeField(ParameterInfoIndex.RELATED.getJname(), Related.END.getValue());
            }
            if (al.getDuration() != null) {
                makeField(PropertyInfoIndex.DURATION, al.getDuration());
                makeField(PropertyInfoIndex.REPEAT, al.getRepeat());
            }
            if (atype == BwAlarm.alarmTypeAudio) {
                makeField(PropertyInfoIndex.ATTACH, al.getAttach());
            } else if (atype == BwAlarm.alarmTypeDisplay) {
                /* This is required but somehow we got a bunch of alarms with no description
           * Is it possibly because of the rollback issue I (partially) fixed?
           */
                makeField(PropertyInfoIndex.DESCRIPTION, al.getDescription());
            } else if (atype == BwAlarm.alarmTypeEmail) {
                makeField(PropertyInfoIndex.ATTACH, al.getAttach());
                makeField(PropertyInfoIndex.DESCRIPTION, al.getDescription());
                makeField(PropertyInfoIndex.SUMMARY, al.getSummary());
                if (al.getNumAttendees() > 0) {
                    indexAttendees(al.getAttendees(), false);
                }
            } else if (atype == BwAlarm.alarmTypeProcedure) {
                makeField(PropertyInfoIndex.ATTACH, al.getAttach());
                makeField(PropertyInfoIndex.DESCRIPTION, al.getDescription());
            } else {
                makeField(PropertyInfoIndex.DESCRIPTION, al.getDescription());
            }
            indexXprops(al);
            endObject();
        }
        endArray();
    } catch (final IndexException e) {
        throw new CalFacadeException(e);
    }
}
Also used : IndexException(org.bedework.util.indexing.IndexException) BwXproperty(org.bedework.calfacade.BwXproperty) TreeSet(java.util.TreeSet) BwAlarm(org.bedework.calfacade.BwAlarm) Date(java.util.Date) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

BwXproperty (org.bedework.calfacade.BwXproperty)30 BwEvent (org.bedework.calfacade.BwEvent)16 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)11 BwString (org.bedework.calfacade.BwString)9 EventInfo (org.bedework.calfacade.svc.EventInfo)9 BwCategory (org.bedework.calfacade.BwCategory)7 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)7 BwAlarm (org.bedework.calfacade.BwAlarm)5 BwAttendee (org.bedework.calfacade.BwAttendee)5 BwContact (org.bedework.calfacade.BwContact)5 BwEventProxy (org.bedework.calfacade.BwEventProxy)5 PropertyList (net.fortuna.ical4j.model.PropertyList)4 BwLocation (org.bedework.calfacade.BwLocation)4 ChangeTable (org.bedework.calfacade.util.ChangeTable)4 TreeSet (java.util.TreeSet)3 Property (net.fortuna.ical4j.model.Property)3 VEvent (net.fortuna.ical4j.model.component.VEvent)3 VPoll (net.fortuna.ical4j.model.component.VPoll)3 VToDo (net.fortuna.ical4j.model.component.VToDo)3 Uid (net.fortuna.ical4j.model.property.Uid)3