Search in sources :

Example 1 with IcalendarType

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

the class IcalTranslator method toXMLIcalendar.

/**
 * @param val
 * @param methodType
 * @param pattern
 * @return XML IcalendarType
 * @throws CalFacadeException
 */
public IcalendarType toXMLIcalendar(final EventInfo val, final int methodType, final IcalendarType pattern, final boolean wrapXprops) throws CalFacadeException {
    IcalendarType ical = new IcalendarType();
    VcalendarType vcal = new VcalendarType();
    ical.getVcalendar().add(vcal);
    vcal.setProperties(new ArrayOfProperties());
    List<JAXBElement<? extends BasePropertyType>> pl = vcal.getProperties().getBasePropertyOrTzid();
    ProdidPropType prod = new ProdidPropType();
    prod.setText(prodId);
    pl.add(Xutil.of.createProdid(prod));
    VersionPropType vers = new VersionPropType();
    vers.setText("2.0");
    pl.add(Xutil.of.createVersion(vers));
    if ((methodType > ScheduleMethods.methodTypeNone) && (methodType < ScheduleMethods.methodTypeUnknown)) {
        MethodPropType m = new MethodPropType();
        m.setText(ScheduleMethods.methods[methodType]);
        pl.add(Xutil.of.createMethod(m));
    }
    ArrayOfComponents aoc = vcal.getComponents();
    if (aoc == null) {
        aoc = new ArrayOfComponents();
        vcal.setComponents(aoc);
    }
    BwEvent ev = val.getEvent();
    JAXBElement<? extends BaseComponentType> el = null;
    VcalendarType vc = null;
    if ((pattern != null) && !pattern.getVcalendar().isEmpty()) {
        vc = pattern.getVcalendar().get(0);
    }
    BaseComponentType bc = matches(vc, ev.getEntityType());
    if ((vc != null) && (bc == null)) {
        return ical;
    }
    if (!ev.getSuppressed()) {
        if (ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy) {
            el = ToXEvent.toComponent(ev, false, wrapXprops, bc);
        } else {
            el = ToXEvent.toComponent(ev, false, wrapXprops, bc);
        }
        if (el != null) {
            aoc.getBaseComponent().add(el);
        }
    }
    if (val.getNumOverrides() == 0) {
        return ical;
    }
    for (EventInfo oei : val.getOverrides()) {
        ev = oei.getEvent();
        el = ToXEvent.toComponent(ev, true, wrapXprops, bc);
        if (el != null) {
            aoc.getBaseComponent().add(el);
        }
    }
    if (val.getNumContainedItems() > 0) {
        for (EventInfo aei : val.getContainedItems()) {
            ev = aei.getEvent();
            el = ToXEvent.toComponent(ev, true, wrapXprops, bc);
            if (el != null) {
                aoc.getBaseComponent().add(el);
            }
        }
    }
    return ical;
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) BwEvent(org.bedework.calfacade.BwEvent) JAXBElement(javax.xml.bind.JAXBElement) ArrayOfProperties(ietf.params.xml.ns.icalendar_2.ArrayOfProperties) ProdidPropType(ietf.params.xml.ns.icalendar_2.ProdidPropType) VcalendarType(ietf.params.xml.ns.icalendar_2.VcalendarType) BaseComponentType(ietf.params.xml.ns.icalendar_2.BaseComponentType) BasePropertyType(ietf.params.xml.ns.icalendar_2.BasePropertyType) IcalendarType(ietf.params.xml.ns.icalendar_2.IcalendarType) MethodPropType(ietf.params.xml.ns.icalendar_2.MethodPropType) ArrayOfComponents(ietf.params.xml.ns.icalendar_2.ArrayOfComponents) VersionPropType(ietf.params.xml.ns.icalendar_2.VersionPropType)

Aggregations

ArrayOfComponents (ietf.params.xml.ns.icalendar_2.ArrayOfComponents)1 ArrayOfProperties (ietf.params.xml.ns.icalendar_2.ArrayOfProperties)1 BaseComponentType (ietf.params.xml.ns.icalendar_2.BaseComponentType)1 BasePropertyType (ietf.params.xml.ns.icalendar_2.BasePropertyType)1 IcalendarType (ietf.params.xml.ns.icalendar_2.IcalendarType)1 MethodPropType (ietf.params.xml.ns.icalendar_2.MethodPropType)1 ProdidPropType (ietf.params.xml.ns.icalendar_2.ProdidPropType)1 VcalendarType (ietf.params.xml.ns.icalendar_2.VcalendarType)1 VersionPropType (ietf.params.xml.ns.icalendar_2.VersionPropType)1 JAXBElement (javax.xml.bind.JAXBElement)1 BwEvent (org.bedework.calfacade.BwEvent)1 EventInfo (org.bedework.calfacade.svc.EventInfo)1