Example #1
0
 void insertAllAppointments(Reservation reservation, StringBuffer buf) {
   buf.append("<table cellpadding=\"2\">");
   buf.append("<tr>\n");
   buf.append("<td colspan=\"2\" class=\"label\">");
   String appointmentLabel = getString("appointments");
   encode(appointmentLabel, buf);
   buf.append(":");
   buf.append("</td>\n");
   buf.append("</tr>\n");
   Appointment[] appointments = reservation.getAppointments();
   for (int i = 0; i < appointments.length; i++) {
     buf.append("<tr>\n");
     buf.append("<td valign=\"top\">\n");
     if (appointments[i].getRepeating() != null) {
       buf.append("<img width=\"16\" height=\"16\" src=\"org/rapla/gui/images/repeating.png\">");
     } else {
       buf.append("<img width=\"16\" height=\"16\" src=\"org/rapla/gui/images/single.png\">");
     }
     buf.append("</td>\n");
     buf.append("<td>\n");
     String appointmentSummary = getAppointmentFormater().getSummary(appointments[i]);
     encode(appointmentSummary, buf);
     Repeating repeating = appointments[i].getRepeating();
     if (repeating != null) {
       buf.append("<br>");
       buf.append("<small>");
       List<Period> periods = getPeriodModel().getPeriodsFor(appointments[i].getStart());
       String repeatingSummary = getAppointmentFormater().getSummary(repeating, periods);
       encode(repeatingSummary, buf);
       if (repeating.hasExceptions()) {
         buf.append("<br>");
         buf.append(getAppointmentFormater().getExceptionSummary(repeating));
       }
       buf.append("</small>");
     }
     buf.append("</td>\n");
     buf.append("<td></td>");
     buf.append("</tr>\n");
   }
   buf.append("</table>\n");
 }
  /**
   * F&uuml;gt die Wiederholungen des &uuml;bergebenen Appointment-Objekts dem &uuml;bergebenen
   * Event-Objekt hinzu.
   *
   * @param appointment Ein Rapla Appointment.
   */
  private void addRepeatings(Appointment appointment, PropertyList properties) {
    Repeating repeating = appointment.getRepeating();

    if (repeating == null) {
      return;
    }

    // This returns the strings DAYLY, WEEKLY, MONTHLY, YEARLY
    String type = repeating.getType().toString().toUpperCase();

    Recur recur;

    // here is evaluated, if a COUNT is set in Rapla, or an enddate is
    // specified
    if (repeating.getNumber() == -1) {
      recur = new Recur(type, -1);
    } else if (repeating.isFixedNumber()) {
      recur = new Recur(type, repeating.getNumber());
    } else {
      net.fortuna.ical4j.model.Date endDate = new net.fortuna.ical4j.model.Date(repeating.getEnd());
      // TODO do we need to translate the enddate in utc?
      recur = new Recur(type, endDate);
    }

    if (repeating.isDaily()) {
      // DAYLY -> settings : intervall
      recur.setInterval(repeating.getInterval());

    } else if (repeating.isWeekly()) {
      // WEEKLY -> settings : every nTh Weekday
      recur.setInterval(repeating.getInterval());

      calendar.setTime(appointment.getStart());
      recur.getDayList().add(WeekDay.getWeekDay(calendar));
    } else if (repeating.isMonthly()) {
      // MONTHLY -> settings : every nTh Weekday
      recur.setInterval(repeating.getInterval());
      calendar.setTime(appointment.getStart());
      int weekofmonth =
          Math.round(calendar.get(java.util.Calendar.DAY_OF_MONTH) / DateTools.DAYS_PER_WEEK) + 1;
      recur.getDayList().add(new WeekDay(WeekDay.getWeekDay(calendar), weekofmonth));
    } else if (repeating.isYearly()) {
      // YEARLY -> settings : every nTh day mTh Monthname
      calendar.setTime(appointment.getStart());
      calendar.get(java.util.Calendar.DAY_OF_YEAR);
    } else {
      getLogger().warn("Invalid data in recurrency rule!");
    }

    properties.add(new RRule(recur));

    // bugfix - if rapla has no exceptions, an empty EXDATE: element is
    // produced. This may bother some iCal tools
    if (repeating.getExceptions().length == 0) {
      return;
    }

    // Add exception dates
    // DateList dl = new DateList(Value.DATE);

    ExDate exDate = new ExDate();
    TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
    net.fortuna.ical4j.model.TimeZone tz = registry.getTimeZone(timeZone.getID());

    // rku: use seperate EXDATE for each exception
    for (Iterator<Date> itExceptions = Arrays.asList(repeating.getExceptions()).iterator();
        itExceptions.hasNext(); ) {
      // DateList dl = new DateList(Value.DATE);
      Date date = itExceptions.next();
      // dl.add(new net.fortuna.ical4j.model.Date( date));
      java.util.Calendar cal = raplaLocale.createCalendar();
      cal.setTime(date);
      int year = cal.get(java.util.Calendar.YEAR);
      int day_of_year = cal.get(java.util.Calendar.DAY_OF_YEAR);
      cal.setTime(appointment.getStart());
      cal.set(java.util.Calendar.YEAR, year);
      cal.set(java.util.Calendar.DAY_OF_YEAR, day_of_year);
      int offset =
          (int) (tz.getOffset(DateTools.cutDate(date).getTime()) / DateTools.MILLISECONDS_PER_HOUR);
      cal.add(java.util.Calendar.HOUR, -offset);
      Date dateToSave = cal.getTime();
      net.fortuna.ical4j.model.DateTime dateTime = new net.fortuna.ical4j.model.DateTime();
      dateTime.setTime(dateToSave.getTime());
      exDate.getDates().add(dateTime);
    }
    exDate.setTimeZone(tz);

    properties.add(exDate);
    // properties.add(new ExDate(dl));
  }
Example #3
0
  @Override
  public void processElement(String namespaceURI, String localName, RaplaSAXAttributes atts)
      throws RaplaSAXParseException {
    if (namespaceURI.equals(DYNATT_NS) || namespaceURI.equals(EXTENSION_NS)) {
      dynAttHandler.setClassifiable(reservation);
      delegateElement(dynAttHandler, namespaceURI, localName, atts);
      return;
    }

    if (!namespaceURI.equals(RAPLA_NS)) return;

    if (localName.equals("permission")) {
      permissionHandler.setContainer(reservation);
      delegateElement(permissionHandler, namespaceURI, localName, atts);
      return;
    }
    if (localName.equals("reservation")) {
      TimestampDates ts = readTimestamps(atts);
      reservation = new ReservationImpl(ts.createTime, ts.changeTime);
      reservation.setResolver(store);
      currentAnnotatable = reservation;
      setId(reservation, atts);
      setLastChangedBy(reservation, atts);
      setOwner(reservation, atts);
    }

    if (localName.equals("appointment")) {
      String id = atts.getValue("id");
      String startDate = atts.getValue("start-date");
      String endDate = atts.getValue("end-date");
      if (endDate == null) endDate = startDate;

      String startTime = atts.getValue("start-time");
      String endTime = atts.getValue("end-time");

      Date start;
      Date end;
      if (startTime != null && endTime != null) {
        start = parseDateTime(startDate, startTime);
        end = parseDateTime(endDate, endTime);
      } else {
        start = parseDate(startDate, false);
        end = parseDate(endDate, true);
      }

      appointment = new AppointmentImpl(start, end);
      appointment.setWholeDays(startTime == null && endTime == null);
      if (id != null) {
        setId(appointment, atts);
      } else {
        setNewId(appointment);
      }
      addAppointment(appointment);
    }

    if (localName.equals("repeating")) {
      String type = atts.getValue("type");
      String interval = atts.getValue("interval");
      String enddate = atts.getValue("end-date");
      String number = atts.getValue("number");
      appointment.setRepeatingEnabled(true);
      repeating = appointment.getRepeating();
      repeating.setType(RepeatingType.findForString(type));
      if (interval != null) {
        repeating.setInterval(Integer.valueOf(interval).intValue());
      }
      if (enddate != null) {
        repeating.setEnd(parseDate(enddate, true));
      } else if (number != null) {
        repeating.setNumber(Integer.valueOf(number).intValue());
      } else {
        repeating.setEnd(null);
      }
      /*
      if (getLogger().enabled(6))
          getLogger().log(6, "Repeating " + repeating.toString() );
      */
    }

    if (localName.equals("allocate")) {
      String id = getString(atts, "idref");
      allocatableId = getId(Allocatable.TYPE, id);
      reservation.addId("resources", allocatableId);
      if (appointment != null) {
        reservation.addRestrictionForId(allocatableId, appointment.getId());
      }
    }

    if (localName.equals("annotation") && namespaceURI.equals(RAPLA_NS)) {
      annotationKey = atts.getValue("key");
      Assert.notNull(annotationKey, "key attribute cannot be null");
      startContent();
    }

    if (localName.equals("exception")) {}

    if (localName.equals("date")) {
      String dateString = atts.getValue("date");
      if (dateString != null && repeating != null)
        repeating.addException(parseDate(dateString, false));
    }
  }