/**
   * This method returns a list of events
   *
   * @return
   */
  public ArrayList<Event> getList() {
    String time = "";
    String summary = "";
    String description = "";

    try {
      FileInputStream fin = new FileInputStream("composite.ics");
      CalendarBuilder builder = new CalendarBuilder();

      Calendar calendar = builder.build(fin);
      for (Component c : calendar.getComponents()) {
        for (Property property : c.getProperties()) {

          switch (property.getName()) {
            case "DTSTART":
              time = property.getValue();
              break;
            case "SUMMARY":
              summary = property.getValue();
              break;
            case "DESCRIPTION":
              description = property.getValue();
              break;
          }
        }
        list.add(new AthleticsEvent(summary, description, time));
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return list;
  }
예제 #2
0
파일: Ical.java 프로젝트: stefanaj/TvTor
  public ArrayList<TVEvent> getTVEventsToday(Collection<?> eventsToday) {

    ArrayList<TVEvent> tvEventsToday = new ArrayList<TVEvent>();

    for (Iterator<?> i = eventsToday.iterator(); i.hasNext(); ) {
      Component component = (Component) i.next();
      //		    System.out.println("Component [" + component.getName() + "]");

      for (Iterator<?> j = component.getProperties().iterator(); j.hasNext(); ) {
        Property property = (Property) j.next();
        //		        System.out.println("Property [" + property.getName() + ", " +
        // property.getValue() + "]");
        if (property.getName().equals(Property.DESCRIPTION)) {
          //		        	System.out.println(property.getValue());
          String[] tvName = property.getValue().split("( - Season )|(, Episode )|( - )|(, )");
          tvEventsToday.add(
              new TVEvent(
                  tvName[TV.TV_SHOW],
                  tvName[TV.EPISODE_TITLE],
                  tvName[TV.SEASON_NR],
                  tvName[TV.EPISODE_NR]));
          //		        	System.out.println(tvName[0]+"\n"+tvName[1]+"\n"+tvName[2]+"\n"+tvName[3]);
        }
      }
    }

    return tvEventsToday;
  }
예제 #3
0
 /**
  * Two components are equal if and only if their name and property lists are equal.
  *
  * @see java.lang.Object#equals(java.lang.Object)
  */
 public final boolean equals(final Object arg0) {
   if (arg0 instanceof Component) {
     Component c = (Component) arg0;
     return getName().equals(c.getName()) && getProperties().equals(c.getProperties());
   }
   return super.equals(arg0);
 }
예제 #4
0
 public static Component copyComponent(Component comp) {
   try {
     return comp.copy();
   } catch (Exception e) {
     throw new CosmoException("error copying component: " + comp, e);
   }
 }
예제 #5
0
  /**
   * Tests limit recurrence set.
   *
   * @throws Exception - if something is wrong this exception is thrown.
   */
  @Test
  public void testLimitRecurrenceSet() throws Exception {
    CalendarBuilder cb = new CalendarBuilder();
    FileInputStream fis = new FileInputStream(baseDir + "limit_recurr_test.ics");
    Calendar calendar = cb.build(fis);

    Assert.assertEquals(5, calendar.getComponents().getComponents("VEVENT").size());

    VTimeZone vtz = (VTimeZone) calendar.getComponents().getComponent("VTIMEZONE");
    TimeZone tz = new TimeZone(vtz);
    OutputFilter filter = new OutputFilter("test");
    DateTime start = new DateTime("20060104T010000", tz);
    DateTime end = new DateTime("20060106T010000", tz);
    start.setUtc(true);
    end.setUtc(true);

    Period period = new Period(start, end);
    filter.setLimit(period);
    filter.setAllSubComponents();
    filter.setAllProperties();

    StringBuffer buffer = new StringBuffer();
    filter.filter(calendar, buffer);
    StringReader sr = new StringReader(buffer.toString());

    Calendar filterCal = cb.build(sr);

    ComponentList comps = filterCal.getComponents();
    Assert.assertEquals(3, comps.getComponents("VEVENT").size());
    Assert.assertEquals(1, comps.getComponents("VTIMEZONE").size());

    // Make sure 3rd and 4th override are dropped
    @SuppressWarnings("unchecked")
    Iterator<Component> it = comps.getComponents("VEVENT").iterator();
    while (it.hasNext()) {
      Component c = it.next();
      Assert.assertNotSame(
          "event 6 changed 3", c.getProperties().getProperty("SUMMARY").getValue());
      Assert.assertNotSame(
          "event 6 changed 4", c.getProperties().getProperty("SUMMARY").getValue());
    }
  }
예제 #6
0
  /**
   * Perform validation on the calendar in its current state.
   *
   * @param recurse indicates whether to validate the calendar's properties and components
   * @throws ValidationException where the calendar is not in a valid state
   */
  public void validate(final boolean recurse) throws ValidationException {
    // 'prodid' and 'version' are both REQUIRED,
    // but MUST NOT occur more than once
    PropertyValidator.getInstance().assertOne(Property.PRODID, properties);
    PropertyValidator.getInstance().assertOne(Property.VERSION, properties);

    // 'calscale' and 'method' are optional,
    // but MUST NOT occur more than once
    PropertyValidator.getInstance().assertOneOrLess(Property.CALSCALE, properties);
    PropertyValidator.getInstance().assertOneOrLess(Property.METHOD, properties);

    // must contain at least one component
    if (getComponents().isEmpty()) {
      throw new ValidationException("Calendar must contain at least one component");
    }

    // validate properties..
    for (Iterator i = getProperties().iterator(); i.hasNext(); ) {
      Property property = (Property) i.next();

      if (!(property instanceof XProperty) && !property.isCalendarProperty()) {
        throw new ValidationException("Invalid property: " + property.getName());
      }
    }

    // validate components..
    for (Iterator i = getComponents().iterator(); i.hasNext(); ) {
      Component component = (Component) i.next();

      if (!(component instanceof CalendarComponent)) {
        throw new ValidationException("Not a valid calendar component: " + component.getName());
      }
    }

    if (recurse) {
      validateProperties();
      validateComponents();
    }
  }
예제 #7
0
  /**
   * Tests the set of limit recurrence.
   *
   * @throws Exception - if something is wrong this exception is thrown.
   */
  @Test
  public void testLimitRecurrenceSetThisAndFuture() throws Exception {
    CalendarBuilder cb = new CalendarBuilder();
    FileInputStream fis = new FileInputStream(baseDir + "limit_recurr_taf_test.ics");
    Calendar calendar = cb.build(fis);

    Assert.assertEquals(4, calendar.getComponents().getComponents("VEVENT").size());

    VTimeZone vtz = (VTimeZone) calendar.getComponents().getComponent("VTIMEZONE");
    TimeZone tz = new TimeZone(vtz);
    OutputFilter filter = new OutputFilter("test");
    DateTime start = new DateTime("20060108T170000", tz);
    DateTime end = new DateTime("20060109T170000", tz);
    start.setUtc(true);
    end.setUtc(true);

    Period period = new Period(start, end);
    filter.setLimit(period);
    filter.setAllSubComponents();
    filter.setAllProperties();

    StringBuffer buffer = new StringBuffer();
    filter.filter(calendar, buffer);
    StringReader sr = new StringReader(buffer.toString());

    Calendar filterCal = cb.build(sr);

    Assert.assertEquals(2, filterCal.getComponents().getComponents("VEVENT").size());
    // Make sure 2nd and 3rd override are dropped
    ComponentList vevents = filterCal.getComponents().getComponents(VEvent.VEVENT);
    Iterator<VEvent> it = vevents.iterator();
    while (it.hasNext()) {
      Component c = it.next();
      Assert.assertNotSame("event 6 changed", c.getProperties().getProperty("SUMMARY").getValue());
      Assert.assertNotSame(
          "event 6 changed 2", c.getProperties().getProperty("SUMMARY").getValue());
    }
  }
예제 #8
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;
  }
예제 #9
0
 /**
  * Invoke validation on the calendar components in its current state.
  *
  * @throws ValidationException where any of the calendar components is not in a valid state
  */
 private void validateComponents() throws ValidationException {
   for (Iterator i = getComponents().iterator(); i.hasNext(); ) {
     Component component = (Component) i.next();
     component.validate();
   }
 }
예제 #10
0
파일: Calendar.java 프로젝트: codirk/ical4j
 /**
  * Invoke validation on the calendar components in its current state.
  *
  * @throws ValidationException where any of the calendar components is not in a valid state
  */
 private void validateComponents() throws ValidationException {
   for (Component component : getComponents()) {
     component.validate();
   }
 }
예제 #11
0
  /*
   * (non-Javadoc)
   * @see net.fortuna.ical4j.model.Component#validate(boolean)
   */
  public final void validate(final boolean recurse) throws ValidationException {

    // validate that getAlarms() only contains VAlarm components
    Iterator iterator = getAlarms().iterator();
    while (iterator.hasNext()) {
      Component component = (Component) iterator.next();

      if (!(component instanceof VAlarm)) {
        throw new ValidationException(
            "Component [" + component.getName() + "] may not occur in VTODO");
      }

      ((VAlarm) component).validate(recurse);
    }

    if (!CompatibilityHints.isHintEnabled(CompatibilityHints.KEY_RELAXED_VALIDATION)) {

      // From "4.8.4.7 Unique Identifier":
      // Conformance: The property MUST be specified in the "VEVENT", "VTODO",
      // "VJOURNAL" or "VFREEBUSY" calendar components.
      PropertyValidator.getInstance().assertOne(Property.UID, getProperties());

      // From "4.8.7.2 Date/Time Stamp":
      // Conformance: This property MUST be included in the "VEVENT", "VTODO",
      // "VJOURNAL" or "VFREEBUSY" calendar components.
      PropertyValidator.getInstance().assertOne(Property.DTSTAMP, getProperties());
    }

    /*
     * ; the following are optional, ; but MUST NOT occur more than once class / completed / created / description /
     * dtstamp / dtstart / geo / last-mod / location / organizer / percent / priority / recurid / seq / status /
     * summary / uid / url /
     */
    PropertyValidator.getInstance().assertOneOrLess(Property.CLASS, getProperties());
    PropertyValidator.getInstance().assertOneOrLess(Property.COMPLETED, getProperties());
    PropertyValidator.getInstance().assertOneOrLess(Property.CREATED, getProperties());
    PropertyValidator.getInstance().assertOneOrLess(Property.DESCRIPTION, getProperties());
    PropertyValidator.getInstance().assertOneOrLess(Property.DTSTAMP, getProperties());
    PropertyValidator.getInstance().assertOneOrLess(Property.DTSTART, getProperties());
    PropertyValidator.getInstance().assertOneOrLess(Property.GEO, getProperties());
    PropertyValidator.getInstance().assertOneOrLess(Property.LAST_MODIFIED, getProperties());
    PropertyValidator.getInstance().assertOneOrLess(Property.LOCATION, getProperties());
    PropertyValidator.getInstance().assertOneOrLess(Property.ORGANIZER, getProperties());
    PropertyValidator.getInstance().assertOneOrLess(Property.PERCENT_COMPLETE, getProperties());
    PropertyValidator.getInstance().assertOneOrLess(Property.PRIORITY, getProperties());
    PropertyValidator.getInstance().assertOneOrLess(Property.RECURRENCE_ID, getProperties());
    PropertyValidator.getInstance().assertOneOrLess(Property.SEQUENCE, getProperties());
    PropertyValidator.getInstance().assertOneOrLess(Property.STATUS, getProperties());
    PropertyValidator.getInstance().assertOneOrLess(Property.SUMMARY, getProperties());
    PropertyValidator.getInstance().assertOneOrLess(Property.UID, getProperties());
    PropertyValidator.getInstance().assertOneOrLess(Property.URL, getProperties());

    Status status = (Status) getProperty(Property.STATUS);
    if (status != null
        && !Status.VTODO_NEEDS_ACTION.equals(status)
        && !Status.VTODO_COMPLETED.equals(status)
        && !Status.VTODO_IN_PROCESS.equals(status)
        && !Status.VTODO_CANCELLED.equals(status)) {
      throw new ValidationException(
          "Status property [" + status.toString() + "] may not occur in VTODO");
    }

    /*
     * ; either 'due' or 'duration' may appear in ; a 'todoprop', but 'due' and 'duration' ; MUST NOT occur in the
     * same 'todoprop' due / duration /
     */
    try {
      PropertyValidator.getInstance().assertNone(Property.DUE, getProperties());
    } catch (ValidationException ve) {
      PropertyValidator.getInstance().assertNone(Property.DURATION, getProperties());
    }

    /*
     * ; the following are optional, ; and MAY occur more than once attach / attendee / categories / comment /
     * contact / exdate / exrule / rstatus / related / resources / rdate / rrule / x-prop
     */

    if (recurse) {
      validateProperties();
    }
  }