コード例 #1
0
  @Override
  protected String plainTextContent(Event event) {
    StringBuilder buf = new StringBuilder();
    String newline = "\n\r";

    // get the message
    Reference ref = entityManager.newReference(event.getResource());
    AnnouncementMessage msg = (AnnouncementMessage) ref.getEntity();
    AnnouncementMessageHeader hdr = (AnnouncementMessageHeader) msg.getAnnouncementHeader();

    // use either the configured site, or if not configured, the site (context) of the resource
    String siteId = (getSite() != null) ? getSite() : ref.getContext();

    String url = ServerConfigurationService.getPortalUrl() + "/site/" + siteId;

    // get a site title
    String title = siteId;
    try {
      Site site = siteService.getSite(siteId);
      title = site.getTitle();
    } catch (Exception ignore) {

    }

    // Now build up the message text.
    if (AnnouncementService.SECURE_ANNC_ADD.equals(event.getEvent())) {
      buf.append(
          FormattedText.convertFormattedTextToPlaintext(
              rb.getFormattedMessage("noti.header.add", new Object[] {title, url})));

    } else {
      buf.append(
          FormattedText.convertFormattedTextToPlaintext(
              rb.getFormattedMessage("noti.header.update", new Object[] {title, url})));
    }

    buf.append(" " + rb.getString("at_date") + " ");
    buf.append(hdr.getDate().toStringLocalFull());
    buf.append(newline);
    buf.append(FormattedText.convertFormattedTextToPlaintext(msg.getBody()));
    buf.append(newline);

    // add any attachments
    List attachments = hdr.getAttachments();
    if (attachments.size() > 0) {
      buf.append(newline + rb.getString("Attachments") + newline);
      for (Iterator iAttachments = attachments.iterator(); iAttachments.hasNext(); ) {
        Reference attachment = (Reference) iAttachments.next();
        String attachmentTitle =
            attachment.getProperties().getPropertyFormatted(ResourceProperties.PROP_DISPLAY_NAME);
        buf.append(attachmentTitle + ": " + attachment.getUrl() + newline);
      }
    }

    return buf.toString();
  }
コード例 #2
0
  /** @inheritDoc */
  protected String htmlContent(Event event) {
    StringBuilder buf = new StringBuilder();
    String newline = "<br />\n";

    // get the message
    Reference ref = EntityManager.newReference(event.getResource());
    AnnouncementMessage msg = (AnnouncementMessage) ref.getEntity();
    AnnouncementMessageHeader hdr = (AnnouncementMessageHeader) msg.getAnnouncementHeader();

    // use either the configured site, or if not configured, the site (context) of the resource
    String siteId = (getSite() != null) ? getSite() : ref.getContext();

    // get a site title
    String title = siteId;
    String url = ServerConfigurationService.getPortalUrl() + "/site/" + siteId;
    try {
      Site site = SiteService.getSite(siteId);
      title = site.getTitle();
      url = site.getUrl(); // Might have a better URL.
    } catch (Exception ignore) {
      M_log.warn("Failed to load site: " + siteId + " for: " + event.getResource());
    }

    // Now build up the message text.
    if (AnnouncementService.SECURE_ANNC_ADD.equals(event.getEvent())) {
      buf.append(rb.getFormattedMessage("noti.header.add", new Object[] {title, url}));
    } else {
      buf.append(rb.getFormattedMessage("noti.header.update", new Object[] {title, url}));
    }
    buf.append(" " + rb.getString("at_date") + " ");
    buf.append(hdr.getDate().toStringLocalFull());
    buf.append(newline);

    // add any attachments
    List<Reference> attachments = hdr.getAttachments();
    if (attachments.size() > 0) {
      buf.append(newline + rb.getString("Attachments") + newline);
      for (Iterator<Reference> iAttachments = attachments.iterator(); iAttachments.hasNext(); ) {
        Reference attachment = (Reference) iAttachments.next();
        String attachmentTitle =
            attachment.getProperties().getPropertyFormatted(ResourceProperties.PROP_DISPLAY_NAME);
        buf.append("<a href=\"" + attachment.getUrl() + "\">");
        buf.append(attachmentTitle);
        buf.append("</a>" + newline);
      }
    }

    return buf.toString();
  }
コード例 #3
0
  /** @inheritDoc */
  public void notify(Notification notification, Event event) {
    // get the message
    Reference ref = EntityManager.newReference(event.getResource());
    AnnouncementMessageEdit msg = (AnnouncementMessageEdit) ref.getEntity();
    AnnouncementMessageHeader hdr = (AnnouncementMessageHeader) msg.getAnnouncementHeader();

    // do not do notification for hidden (draft) messages
    if (hdr.getDraft()) return;

    // Put here since if release date after now, do not notify
    // since scheduled notification has been set.
    Time now = TimeService.newTime();

    if (now.after(hdr.getDate())) {
      super.notify(notification, event);
    }
  }