Beispiel #1
0
 /**
  * Sends an event notification for the last published item to the subscriber. If the subscription
  * has not yet been authorized or is pending to be configured then no notification is going to be
  * sent.
  *
  * <p>Depending on the subscription configuration the event notification may or may not have a
  * payload, may not be sent if a keyword (i.e. filter) was defined and it was not matched.
  *
  * @param publishedItem the last item that was published to the node.
  */
 void sendLastPublishedItem(PublishedItem publishedItem) {
   // Check if the published item can be sent to the subscriber
   if (!canSendPublicationEvent(publishedItem.getNode(), publishedItem)) {
     return;
   }
   // Send event notification to the subscriber
   Message notification = new Message();
   Element event =
       notification.getElement().addElement("event", "http://jabber.org/protocol/pubsub#event");
   Element items = event.addElement("items");
   items.addAttribute("node", node.getNodeID());
   Element item = items.addElement("item");
   if (((LeafNode) node).isItemRequired()) {
     item.addAttribute("id", publishedItem.getID());
   }
   if (node.isPayloadDelivered() && publishedItem.getPayload() != null) {
     item.add(publishedItem.getPayload().createCopy());
   }
   // Add a message body (if required)
   if (isIncludingBody()) {
     notification.setBody(LocaleUtils.getLocalizedString("pubsub.notification.message.body"));
   }
   // Include date when published item was created
   notification
       .getElement()
       .addElement("delay", "urn:xmpp:delay")
       .addAttribute("stamp", fastDateFormat.format(publishedItem.getCreationDate()));
   // Send the event notification to the subscriber
   service.sendNotification(node, notification, jid);
 }
  /**
   * Calculate the real file name from the base filename.
   *
   * @return File the calculated file name
   */
  public File nextFile() {
    final StringBuilder sb = new StringBuilder();
    sb.append(m_baseFile);
    if (m_formatter == null) {
      sb.append(System.currentTimeMillis());
    } else {
      final String dateString = m_formatter.format(new Date());
      sb.append(dateString);
    }

    if (m_suffix != null) {
      sb.append(m_suffix);
    }

    m_currentFile = new File(sb.toString());
    return m_currentFile;
  }
 public UniqueFileStrategy(final File baseFile, String pattern) {
   this(baseFile);
   m_formatter = FastDateFormat.getInstance(pattern);
 }
Beispiel #4
0
  /**
   * Returns a data form with the subscription configuration. The data form can be used to edit the
   * subscription configuration.
   *
   * @return data form used by the subscriber to edit the subscription configuration.
   */
  public DataForm getConfigurationForm() {
    DataForm form = new DataForm(DataForm.Type.form);
    form.setTitle(LocaleUtils.getLocalizedString("pubsub.form.subscription.title"));
    List<String> params = new ArrayList<String>();
    params.add(node.getNodeID());
    form.addInstruction(
        LocaleUtils.getLocalizedString("pubsub.form.subscription.instruction", params));
    // Add the form fields and configure them for edition
    FormField formField = form.addField();
    formField.setVariable("FORM_TYPE");
    formField.setType(FormField.Type.hidden);
    formField.addValue("http://jabber.org/protocol/pubsub#subscribe_options");

    formField = form.addField();
    formField.setVariable("pubsub#deliver");
    formField.setType(FormField.Type.boolean_type);
    formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.deliver"));
    formField.addValue(deliverNotifications);

    formField = form.addField();
    formField.setVariable("pubsub#digest");
    formField.setType(FormField.Type.boolean_type);
    formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.digest"));
    formField.addValue(usingDigest);

    formField = form.addField();
    formField.setVariable("pubsub#digest_frequency");
    formField.setType(FormField.Type.text_single);
    formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.digest_frequency"));
    formField.addValue(digestFrequency);

    formField = form.addField();
    formField.setVariable("pubsub#expire");
    formField.setType(FormField.Type.text_single);
    formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.expire"));
    if (expire != null) {
      formField.addValue(fastDateFormat.format(expire));
    }

    formField = form.addField();
    formField.setVariable("pubsub#include_body");
    formField.setType(FormField.Type.boolean_type);
    formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.include_body"));
    formField.addValue(includingBody);

    formField = form.addField();
    formField.setVariable("pubsub#show-values");
    formField.setType(FormField.Type.list_multi);
    formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.show-values"));
    formField.addOption(null, Presence.Show.away.name());
    formField.addOption(null, Presence.Show.chat.name());
    formField.addOption(null, Presence.Show.dnd.name());
    formField.addOption(null, "online");
    formField.addOption(null, Presence.Show.xa.name());
    for (String value : presenceStates) {
      formField.addValue(value);
    }

    if (node.isCollectionNode()) {
      formField = form.addField();
      formField.setVariable("pubsub#subscription_type");
      formField.setType(FormField.Type.list_single);
      formField.setLabel(
          LocaleUtils.getLocalizedString("pubsub.form.subscription.subscription_type"));
      formField.addOption(null, Type.items.name());
      formField.addOption(null, Type.nodes.name());
      formField.addValue(type);

      formField = form.addField();
      formField.setVariable("pubsub#subscription_depth");
      formField.setType(FormField.Type.list_single);
      formField.setLabel(
          LocaleUtils.getLocalizedString("pubsub.form.subscription.subscription_depth"));
      formField.addOption(null, "1");
      formField.addOption(null, "all");
      formField.addValue(depth == 1 ? "1" : "all");
    }

    if (!node.isCollectionNode() || type == Type.items) {
      formField = form.addField();
      formField.setVariable("x-pubsub#keywords");
      formField.setType(FormField.Type.text_single);
      formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.keywords"));
      if (keyword != null) {
        formField.addValue(keyword);
      }
    }

    return form;
  }
Beispiel #5
0
 static {
   dateFormat = new SimpleDateFormat("yyyy-MM-DD'T'HH:mm:ss.SSS'Z'");
   dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
   fastDateFormat =
       FastDateFormat.getInstance(JiveConstants.XMPP_DATETIME_FORMAT, TimeZone.getTimeZone("UTC"));
 }