Example #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);
 }
Example #2
0
    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      if (isSelected) this.setBackground(table.getSelectionBackground());
      else this.setBackground(table.getBackground());

      Node node = nodes.get(row);
      Request request = nodeIDToRequest.get(node.getNodeID());
      if (request == null) {
        this.setString("NONE");
        this.setValue(0);
      } else {
        int percent = (int) Math.round(request.getPercentDone());
        this.setString(request.getType().toString() + "  " + percent + "%");
        this.setValue(percent);
      }
      return this;
    }
Example #3
0
 /**
  * Sends the current subscription status to the user that tried to create a subscription to the
  * node. The subscription status is sent to the subsciber after the subscription was created or if
  * the subscriber tries to subscribe many times and the node does not support multpiple
  * subscriptions.
  *
  * @param originalRequest the IQ packet sent by the subscriber to create the subscription.
  */
 void sendSubscriptionState(IQ originalRequest) {
   IQ result = IQ.createResultIQ(originalRequest);
   Element child = result.setChildElement("pubsub", "http://jabber.org/protocol/pubsub");
   Element entity = child.addElement("subscription");
   if (!node.isRootCollectionNode()) {
     entity.addAttribute("node", node.getNodeID());
   }
   entity.addAttribute("jid", getJID().toString());
   if (node.isMultipleSubscriptionsEnabled()) {
     entity.addAttribute("subid", getID());
   }
   entity.addAttribute("subscription", getState().name());
   Element subscribeOptions = entity.addElement("subscribe-options");
   if (node.isSubscriptionConfigurationRequired() && isConfigurationPending()) {
     subscribeOptions.addElement("required");
   }
   // Send the result
   service.send(result);
 }
Example #4
0
  public synchronized Object getValueAt(int row, int col) {
    Node node = nodes.get(row);

    switch (col) {
      case 0:
        return node.getNodeID();
      case 1:
        return node.getCurrState();
      case 2:
        return node.getTailBlockID();
      case 3:
        return node.getHeadBlockID();
      case 4:
        return node.getLocalTime();
      case 5:
        return node.getGlobalTime();
      case 6:
        return node.getIsTimeSynchronized();
      case 7:
        return new LastRequestCellRendererClass();
      default:
        return "UNKNOWN";
    }
  }
Example #5
0
 /** Reads the network geometry from mainScenario and populates the nodes hashmap */
 public void createNodeStructureFromMainScenario() {
   for (int i = 0;
       i < this.mainScenario.getNetworkList().getNetwork().get(0).getNodeList().getNode().size();
       i++) {
     ArrayList<Integer> inputs = new ArrayList<Integer>();
     ArrayList<Integer> outputs = new ArrayList<Integer>();
     Node n = new Node();
     n.setNodeID(
         Integer.parseInt(
             this.mainScenario
                 .getNetworkList()
                 .getNetwork()
                 .get(0)
                 .getNodeList()
                 .getNode()
                 .get(i)
                 .getId()));
     n.setNodeType(
         this.mainScenario
             .getNetworkList()
             .getNetwork()
             .get(0)
             .getNodeList()
             .getNode()
             .get(i)
             .getType());
     for (int j = 0;
         j
             < this.mainScenario
                 .getNetworkList()
                 .getNetwork()
                 .get(0)
                 .getNodeList()
                 .getNode()
                 .get(i)
                 .getInputs()
                 .getInput()
                 .size();
         j++) {
       inputs.add(
           Integer.parseInt(
               this.mainScenario
                   .getNetworkList()
                   .getNetwork()
                   .get(0)
                   .getNodeList()
                   .getNode()
                   .get(i)
                   .getInputs()
                   .getInput()
                   .get(j)
                   .getLinkId()));
     }
     for (int j = 0;
         j
             < this.mainScenario
                 .getNetworkList()
                 .getNetwork()
                 .get(0)
                 .getNodeList()
                 .getNode()
                 .get(i)
                 .getOutputs()
                 .getOutput()
                 .size();
         j++) {
       outputs.add(
           Integer.parseInt(
               this.mainScenario
                   .getNetworkList()
                   .getNetwork()
                   .get(0)
                   .getNodeList()
                   .getNode()
                   .get(i)
                   .getOutputs()
                   .getOutput()
                   .get(j)
                   .getLinkId()));
     }
     n.setInLinks(inputs);
     n.setOutLinks(outputs);
     nodes.put(n.getNodeID(), n);
   }
 }
Example #6
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;
  }