예제 #1
0
 /**
  * @return the calendar
  * @throws ParserException where calendar parsing fails
  * @throws IOException where a communication error occurs
  */
 public final Calendar getCalendar() throws IOException, ParserException {
   if (calendar == null) {
     CalendarBuilder builder = new CalendarBuilder();
     //            calendar = builder.build(new
     // ByteArrayInputStream(file.getDataProvider().getBytes()));
     calendar = builder.build(file.getDataProvider().getInputStream());
   }
   return calendar;
 }
예제 #2
0
  /** @param calendar the calendar to set */
  public final void setCalendar(final Calendar calendar) {
    this.calendar = calendar;

    try {
      Uid uidProp = Calendars.getUid(calendar);
      this.uid = uidProp.getValue();
      setName(uidProp.getValue());
    } catch (ConstraintViolationException e) {
      LOG.error("Invalid UID", e);
      setName("calendar");
    }

    file = new JcrFile();
    file.setName("data");
    file.setDataProvider(new JcrDataProviderImpl(calendar.toString().getBytes()));
    //        file.setMimeType(MediaType.ICALENDAR_2_0.getContentType());
    file.setMimeType(Calendars.getContentType(calendar, null));
    file.setLastModified(java.util.Calendar.getInstance());

    for (Object component : calendar.getComponents()) {

      // save first available summary..
      if (summary == null) {
        Summary summaryProp = (Summary) ((Component) component).getProperty(Property.SUMMARY);
        if (summaryProp != null) {
          this.summary = summaryProp.getValue();
        }
      }

      // save first available description..
      if (description == null) {
        Description descriptionProp =
            (Description) ((Component) component).getProperty(Property.DESCRIPTION);
        if (descriptionProp != null) {
          description = new JcrFile();
          description.setName("text");
          description.setMimeType("text/plain");
          description.setDataProvider(
              new JcrDataProviderImpl(descriptionProp.getValue().getBytes()));
          description.setLastModified(java.util.Calendar.getInstance());
        }
      }

      // save attachments..
      attachments.clear();
      PropertyList attachments = ((Component) component).getProperties(Property.ATTACH);
      for (Object attach : attachments) {
        try {
          JcrFile attachment = new JcrFile();
          attachment.setName("attachment");
          if (Value.BINARY.equals(((Property) attach).getParameter(Parameter.VALUE))) {
            attachment.setDataProvider(new JcrDataProviderImpl(((Attach) attach).getBinary()));
            FmtType contentType = (FmtType) ((Property) attach).getParameter(Parameter.FMTTYPE);
            if (contentType != null) {
              attachment.setMimeType(contentType.getValue());
            }
          } else {
            ByteArrayOutputStream aout = new ByteArrayOutputStream();
            IOUtils.copy(((Attach) attach).getUri().toURL().openStream(), aout);
            attachment.setDataProvider(new JcrDataProviderImpl(aout.toByteArray()));
          }
          attachment.setLastModified(java.util.Calendar.getInstance());
          this.attachments.add(attachment);
        } catch (Exception e) {
          LOG.error("Error saving attachment", e);
        }
      }
    }
  }