예제 #1
1
  /**
   * @param cal
   * @param pattern
   * @param doTimezones
   * @return Internal XML representation of iCalendar object
   * @throws Throwable
   */
  @SuppressWarnings("unchecked")
  public static IcalendarType fromIcal(
      final Calendar cal,
      final BaseComponentType pattern,
      final boolean doTimezones,
      final boolean wrapXprops)
      throws Throwable {
    final IcalendarType ical = new IcalendarType();
    final VcalendarType vcal = new VcalendarType();

    ical.getVcalendar().add(vcal);

    processProperties(cal.getProperties(), vcal, pattern, wrapXprops);

    final ComponentList icComps = cal.getComponents();

    if (icComps == null) {
      return ical;
    }

    final ArrayOfComponents aoc = new ArrayOfComponents();
    vcal.setComponents(aoc);

    for (final Object o : icComps) {
      if (!doTimezones && (o instanceof VTimeZone)) {
        // Skip these
        continue;
      }
      aoc.getBaseComponent().add(toComponent((CalendarComponent) o, pattern, wrapXprops));
    }

    return ical;
  }
  /* (non-Javadoc)
   * @see org.bedework.synch.cnctrs.ConnectorInstance#fetchItem(java.lang.String)
   */
  @Override
  public FetchItemResponseType fetchItem(final String uid) throws SynchException {
    getIcal();

    if (sub.changed()) {
      cnctr.getSyncher().updateSubscription(sub);
    }

    MapEntry me = uidMap.get(uid);

    FetchItemResponseType fir = new FetchItemResponseType();

    if (me == null) {
      fir.setStatus(StatusType.NOT_FOUND);
      return fir;
    }

    fir.setHref(info.getUri() + "#" + uid);
    fir.setChangeToken(info.getChangeToken());

    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(of.createProdid(prod));

    VersionPropType vers = new VersionPropType();
    vers.setText("2.0");
    pl.add(of.createVersion(vers));

    ArrayOfComponents aoc = new ArrayOfComponents();
    vcal.setComponents(aoc);

    aoc.getBaseComponent().addAll(me.comps);
    fir.setIcalendar(ical);

    return fir;
  }
예제 #3
0
  /**
   * Make a BaseComponentType component from an ical4j object. This may produce a VEvent, VTodo or
   * VJournal.
   *
   * @param val
   * @param pattern - if non-null limit returned components and values to those supplied in the
   *     pattern.
   * @return JAXBElement<? extends BaseComponentType>
   * @throws Throwable
   */
  public static JAXBElement toComponent(
      final Component val, final BaseComponentType pattern, final boolean wrapXprops)
      throws Throwable {
    if (val == null) {
      return null;
    }

    final PropertyList icprops = val.getProperties();
    ComponentList icComps = null;

    if (icprops == null) {
      // Empty component
      return null;
    }

    final JAXBElement el;

    if (val instanceof VEvent) {
      el = of.createVevent(new VeventType());
      icComps = ((VEvent) val).getAlarms();
    } else if (val instanceof VToDo) {
      el = of.createVtodo(new VtodoType());
      icComps = ((VToDo) val).getAlarms();
    } else if (val instanceof VJournal) {
      el = of.createVjournal(new VjournalType());
    } else if (val instanceof VFreeBusy) {
      el = of.createVfreebusy(new VfreebusyType());
    } else if (val instanceof VAlarm) {
      el = of.createValarm(new ValarmType());
    } else if (val instanceof VTimeZone) {
      el = of.createVtimezone(new VtimezoneType());
      icComps = ((VTimeZone) val).getObservances();
    } else if (val instanceof Daylight) {
      el = of.createDaylight(new DaylightType());
    } else if (val instanceof Standard) {
      el = of.createStandard(new StandardType());
    } else {
      throw new Exception("org.bedework.invalid.entity.type" + val.getClass().getName());
    }

    final BaseComponentType comp = (BaseComponentType) el.getValue();

    processProperties(val.getProperties(), comp, pattern, wrapXprops);

    if (Util.isEmpty(icComps)) {
      return el;
    }

    /* Process any sub-components */
    final ArrayOfComponents aoc = new ArrayOfComponents();
    comp.setComponents(aoc);

    for (final Object o : icComps) {
      @SuppressWarnings("unchecked")
      final JAXBElement<? extends BaseComponentType> subel =
          toComponent((Component) o, pattern, wrapXprops);
      aoc.getBaseComponent().add(subel);
    }

    return el;
  }