コード例 #1
0
ファイル: IcalToXcal.java プロジェクト: yehecan/bw-util
  /**
   * @param icprops
   * @param comp
   * @param pattern
   * @throws Throwable
   */
  public static void processProperties(
      final PropertyList icprops,
      final BaseComponentType comp,
      final BaseComponentType pattern,
      final boolean wrapXprops)
      throws Throwable {
    if ((icprops == null) || icprops.isEmpty()) {
      return;
    }

    comp.setProperties(new ArrayOfProperties());
    final List<JAXBElement<? extends BasePropertyType>> pl =
        comp.getProperties().getBasePropertyOrTzid();

    for (final Object icprop : icprops) {
      final Property prop = (Property) icprop;

      final PropertyInfoIndex pii = PropertyInfoIndex.fromName(prop.getName());

      if ((pii != null) && !emit(pattern, comp.getClass(), pii.getXmlClass())) {
        continue;
      }

      final JAXBElement<? extends BasePropertyType> xmlprop = doProperty(prop, pii, wrapXprops);

      if (xmlprop != null) {
        processParameters(prop.getParameters(), xmlprop.getValue());
        pl.add(xmlprop);
      }
    }
  }
コード例 #2
0
ファイル: IcalToXcal.java プロジェクト: yehecan/bw-util
  private static boolean emit(
      final BaseComponentType pattern, final Class compCl, final Class... cl) {
    if (pattern == null) {
      return true;
    }

    if (!compCl.getName().equals(pattern.getClass().getName())) {
      return false;
    }

    if ((cl == null) | (cl.length == 0)) {
      // Any property
      return true;
    }

    String className = cl[0].getName();

    if (BasePropertyType.class.isAssignableFrom(cl[0])) {
      if (pattern.getProperties() == null) {
        return false;
      }

      List<JAXBElement<? extends BasePropertyType>> patternProps =
          pattern.getProperties().getBasePropertyOrTzid();

      for (JAXBElement<? extends BasePropertyType> jp : patternProps) {
        if (jp.getValue().getClass().getName().equals(className)) {
          return true;
        }
      }

      return false;
    }

    List<JAXBElement<? extends BaseComponentType>> patternComps = XcalUtil.getComponents(pattern);

    if (patternComps == null) {
      return false;
    }

    // Check for component

    for (JAXBElement<? extends BaseComponentType> jp : patternComps) {
      if (jp.getValue().getClass().getName().equals(className)) {
        return emit(pattern, cl[0], Arrays.copyOfRange(cl, 1, cl.length - 1));
      }
    }

    return false;
  }
コード例 #3
0
ファイル: IcalToXcal.java プロジェクト: yehecan/bw-util
  /**
   * 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;
  }