示例#1
0
 public static List listEventsForPeriod(
     final OlatCalendar calendar, final Date periodStart, final Date periodEnd) {
   final List periodEvents = new ArrayList();
   final Collection calendarEntries = calendar.getAllCalendarEntries();
   for (final Iterator iter = calendarEntries.iterator(); iter.hasNext(); ) {
     final CalendarEntry calendarEntry = (CalendarEntry) iter.next();
     final List<CalendarRecurEntry> lstEvnt =
         calendarEntry.getRecurringDatesInPeriod(periodStart, periodEnd);
     for (final CalendarRecurEntry recurEvent : lstEvnt) {
       periodEvents.add(recurEvent);
     }
     if (calendarEntry.getEnd().before(periodStart) || calendarEntry.getBegin().after(periodEnd)) {
       continue;
     }
     periodEvents.add(calendarEntry);
   }
   return periodEvents;
 }
示例#2
0
 /**
  * Find all events in this calendar with the given subject.
  *
  * @param calendar
  * @param subject
  * @return
  */
 public static List findEvents(
     final OlatCalendar calendar,
     final String subject,
     final String location,
     final Date beginPeriod,
     final Date endPeriod,
     final boolean publicOnly) {
   final List results = new ArrayList();
   final Collection calendarEntries = calendar.getAllCalendarEntries();
   String regExSubject = subject.replace("*", ".*");
   String regExLocation = location.replace("*", ".*");
   regExSubject = ".*" + regExSubject + ".*";
   regExLocation = ".*" + regExLocation + ".*";
   for (final Iterator iter = calendarEntries.iterator(); iter.hasNext(); ) {
     final CalendarEntry event = (CalendarEntry) iter.next();
     if (publicOnly && event.getClassification() != CalendarEntry.CLASS_PUBLIC) {
       continue;
     }
     if (beginPeriod != null && event.getBegin().before(beginPeriod)) {
       continue;
     }
     if (endPeriod != null && event.getEnd().after(endPeriod)) {
       continue;
     }
     String eventSubject = event.getSubject().toLowerCase();
     eventSubject = eventSubject.replace("\n", " ");
     eventSubject = eventSubject.replace("\r", " ");
     if ((subject != null)
         && !subject.trim().isEmpty()
         && !eventSubject.matches(regExSubject.toLowerCase())) {
       log.debug(
           "Does not add event because subject did not match eventSubject="
               + eventSubject
               + "  regExSubject="
               + regExSubject);
       continue;
     }
     if ((location != null) && !location.trim().isEmpty() && (event.getLocation() != null)) {
       String eventLocation = event.getLocation().toLowerCase();
       eventLocation = eventLocation.replace("\n", " ");
       eventLocation = eventLocation.replace("\r", " ");
       if (!eventLocation.matches(regExLocation.toLowerCase())) {
         log.debug(
             "Does not add event because subject did not match eventLocation="
                 + eventLocation
                 + "  regExLocation="
                 + regExLocation);
         continue;
       }
     }
     log.debug(
         "add to results event.Location="
             + event.getLocation()
             + " ,Subject="
             + event.getSubject());
     results.add(event);
     final Date periodStart = beginPeriod == null ? event.getBegin() : beginPeriod;
     final long year = (long) 60 * (long) 60 * 24 * 365 * 1000;
     final Date periodEnd = endPeriod == null ? new Date(periodStart.getTime() + year) : endPeriod;
     final List<CalendarRecurEntry> lstEvnt =
         event.getRecurringDatesInPeriod(periodStart, periodEnd);
     for (final CalendarRecurEntry recurEvent : lstEvnt) {
       if (publicOnly && event.getClassification() != CalendarEntry.CLASS_PUBLIC) {
         continue;
       }
       if (beginPeriod != null && event.getBegin().before(beginPeriod)) {
         continue;
       }
       if (endPeriod != null && event.getEnd().after(endPeriod)) {
         continue;
       }
       if (subject != null && !event.getSubject().matches(regExSubject)) {
         continue;
       }
       if (location != null && !event.getLocation().matches(regExLocation)) {
         continue;
       }
       if ((subject != null)
           && !subject.trim().isEmpty()
           && !event.getSubject().toLowerCase().matches(regExSubject.toLowerCase())) {
         continue;
       }
       if ((location != null)
           && !location.trim().isEmpty()
           && !event.getLocation().toLowerCase().matches(regExLocation.toLowerCase())) {
         continue;
       }
       results.add(recurEvent);
     }
   }
   Collections.sort(results);
   return results;
 }