📄 node.java
字号:
created = true; } if (savedToDB) { // Add or update the affiliate in the database PubSubPersistenceManager.saveAffiliation(service, this, affiliate, created); } return affiliate; } private void removeAffiliation(JID jid, NodeAffiliate.Affiliation affiliation) { // Get the current affiliation of the specified JID NodeAffiliate affiliate = getAffiliate(jid); // Check if the current affiliatin of the user is the one to remove if (affiliate != null && affiliation == affiliate.getAffiliation()) { removeAffiliation(affiliate); } } private void removeAffiliation(NodeAffiliate affiliate) { // Remove the existing affiliate from the list in memory affiliates.remove(affiliate); if (savedToDB) { // Remove the affiliate from the database PubSubPersistenceManager.removeAffiliation(service, this, affiliate); } } /** * Removes all subscriptions owned by the specified entity. * * @param owner the owner of the subscriptions to be cancelled. */ private void removeSubscriptions(JID owner) { for (NodeSubscription subscription : getSubscriptions(owner)) { cancelSubscription(subscription); } } /** * Returns the list of subscriptions owned by the specified user. The subscription owner * may have more than one subscription based on {@link #isMultipleSubscriptionsEnabled()}. * Each subscription may have a different subscription JID if the owner wants to receive * notifications in different resources (or even JIDs). * * @param owner the owner of the subscriptions. * @return the list of subscriptions owned by the specified user. */ public Collection<NodeSubscription> getSubscriptions(JID owner) { Collection<NodeSubscription> subscriptions = new ArrayList<NodeSubscription>(); for (NodeSubscription subscription : subscriptionsByID.values()) { if (owner.equals(subscription.getOwner())) { subscriptions.add(subscription); } } return subscriptions; } /** * Returns all subscriptions to the node. * * @return all subscriptions to the node. */ Collection<NodeSubscription> getSubscriptions() { return subscriptionsByID.values(); } /** * Returns the {@link NodeAffiliate} of the specified {@link JID} or <tt>null</tt> * if none was found. Users that have a subscription with the node will ALWAYS * have an affiliation even if the affiliation is of type <tt>none</tt>. * * @param jid the JID of the user to look his affiliation with this node. * @return the NodeAffiliate of the specified JID or <tt>null</tt> if none was found. */ public NodeAffiliate getAffiliate(JID jid) { for (NodeAffiliate affiliate : affiliates) { if (jid.equals(affiliate.getJID())) { return affiliate; } } return null; } /** * Returns a collection with the JID of the node owners. Entities that are node owners have * an affiliation of {@link NodeAffiliate.Affiliation#owner}. Owners are allowed to purge * and delete the node. Moreover, owners may also get The collection can be modified * since it represents a snapshot. * * @return a collection with the JID of the node owners. */ public Collection<JID> getOwners() { Collection<JID> jids = new ArrayList<JID>(); for (NodeAffiliate affiliate : affiliates) { if (NodeAffiliate.Affiliation.owner == affiliate.getAffiliation()) { jids.add(affiliate.getJID()); } } return jids; } /** * Returns a collection with the JID of the enitities with an affiliation of * {@link NodeAffiliate.Affiliation#publisher}. When using the publisher model * {@link org.jivesoftware.openfire.pubsub.models.OpenPublisher} anyone may publish * to the node so this collection may be empty or may not contain the complete list * of publishers. The returned collection can be modified since it represents a snapshot. * * @return a collection with the JID of the enitities with an affiliation of publishers. */ public Collection<JID> getPublishers() { Collection<JID> jids = new ArrayList<JID>(); for (NodeAffiliate affiliate : affiliates) { if (NodeAffiliate.Affiliation.publisher == affiliate.getAffiliation()) { jids.add(affiliate.getJID()); } } return jids; } /** * Changes the node configuration based on the completed data form. Only owners or * sysadmins are allowed to change the node configuration. The completed data form * cannot remove all node owners. An exception is going to be thrown if the new form * tries to leave the node without owners. * * @param completedForm the completed data form. * @throws NotAcceptableException if completed data form tries to leave the node without owners. */ public void configure(DataForm completedForm) throws NotAcceptableException { boolean wasPresenceBased = isPresenceBasedDelivery(); if (DataForm.Type.cancel.equals(completedForm.getType())) { // Existing node configuration is applied (i.e. nothing is changed) } else if (DataForm.Type.submit.equals(completedForm.getType())) { List<String> values; String booleanValue; // Get the new list of owners FormField ownerField = completedForm.getField("pubsub#owner"); boolean ownersSent = ownerField != null; List<JID> owners = new ArrayList<JID>(); if (ownersSent) { for (String value : ownerField.getValues()) { try { owners.add(new JID(value)); } catch (Exception e) { // Do nothing } } } // Answer a not-acceptable error if all the current owners will be removed if (ownersSent && owners.isEmpty()) { throw new NotAcceptableException(); } for (FormField field : completedForm.getFields()) { if ("FORM_TYPE".equals(field.getVariable())) { // Do nothing } else if ("pubsub#deliver_payloads".equals(field.getVariable())) { values = field.getValues(); booleanValue = (values.size() > 0 ? values.get(0) : "1"); deliverPayloads = "1".equals(booleanValue); } else if ("pubsub#notify_config".equals(field.getVariable())) { values = field.getValues(); booleanValue = (values.size() > 0 ? values.get(0) : "1"); notifyConfigChanges = "1".equals(booleanValue); } else if ("pubsub#notify_delete".equals(field.getVariable())) { values = field.getValues(); booleanValue = (values.size() > 0 ? values.get(0) : "1"); notifyDelete = "1".equals(booleanValue); } else if ("pubsub#notify_retract".equals(field.getVariable())) { values = field.getValues(); booleanValue = (values.size() > 0 ? values.get(0) : "1"); notifyRetract = "1".equals(booleanValue); } else if ("pubsub#presence_based_delivery".equals(field.getVariable())) { values = field.getValues(); booleanValue = (values.size() > 0 ? values.get(0) : "1"); presenceBasedDelivery = "1".equals(booleanValue); } else if ("pubsub#subscribe".equals(field.getVariable())) { values = field.getValues(); booleanValue = (values.size() > 0 ? values.get(0) : "1"); subscriptionEnabled = "1".equals(booleanValue); } else if ("pubsub#subscription_required".equals(field.getVariable())) { // TODO Replace this variable for the one defined in the JEP (once one is defined) values = field.getValues(); booleanValue = (values.size() > 0 ? values.get(0) : "1"); subscriptionConfigurationRequired = "1".equals(booleanValue); } else if ("pubsub#type".equals(field.getVariable())) { values = field.getValues(); payloadType = values.size() > 0 ? values.get(0) : " "; } else if ("pubsub#body_xslt".equals(field.getVariable())) { values = field.getValues(); bodyXSLT = values.size() > 0 ? values.get(0) : " "; } else if ("pubsub#dataform_xslt".equals(field.getVariable())) { values = field.getValues(); dataformXSLT = values.size() > 0 ? values.get(0) : " "; } else if ("pubsub#access_model".equals(field.getVariable())) { values = field.getValues(); if (values.size() > 0) { accessModel = AccessModel.valueOf(values.get(0)); } } else if ("pubsub#publish_model".equals(field.getVariable())) { values = field.getValues(); if (values.size() > 0) { publisherModel = PublisherModel.valueOf(values.get(0)); } } else if ("pubsub#roster_groups_allowed".equals(field.getVariable())) { // Get the new list of roster group(s) allowed to subscribe and retrieve items rosterGroupsAllowed = new ArrayList<String>(); for (String value : field.getValues()) { addAllowedRosterGroup(value); } } else if ("pubsub#contact".equals(field.getVariable())) { // Get the new list of users that may be contacted with questions contacts = new ArrayList<JID>(); for (String value : field.getValues()) { try { addContact(new JID(value)); } catch (Exception e) { // Do nothing } } } else if ("pubsub#description".equals(field.getVariable())) { values = field.getValues(); description = values.size() > 0 ? values.get(0) : " "; } else if ("pubsub#language".equals(field.getVariable())) { values = field.getValues(); language = values.size() > 0 ? values.get(0) : " "; } else if ("pubsub#title".equals(field.getVariable())) { values = field.getValues(); name = values.size() > 0 ? values.get(0) : " "; } else if ("pubsub#itemreply".equals(field.getVariable())) { values = field.getValues(); if (values.size() > 0) { replyPolicy = ItemReplyPolicy.valueOf(values.get(0)); } } else if ("pubsub#replyroom".equals(field.getVariable())) { // Get the new list of multi-user chat rooms to specify for replyroom replyRooms = new ArrayList<JID>(); for (String value : field.getValues()) { try { addReplyRoom(new JID(value)); } catch (Exception e) { // Do nothing } } } else if ("pubsub#replyto".equals(field.getVariable())) { // Get the new list of JID(s) to specify for replyto replyTo = new ArrayList<JID>(); for (String value : field.getValues()) { try { addReplyTo(new JID(value)); } catch (Exception e) { // Do nothing } } } else { // Let subclasses be configured by specified fields configure(field); } } // Set new list of owners of the node if (ownersSent) { // Calculate owners to remove and remove them from the DB Collection<JID> oldOwners = getOwners(); oldOwners.removeAll(owners); for (JID jid : oldOwners) { removeOwner(jid); } // Calculate new owners and add them to the DB owners.removeAll(getOwners()); for (JID jid : owners) { addOwner(jid); } } // TODO Before removing owner or admin check if user was changed from admin to owner or vice versa. This way his susbcriptions are not going to be deleted. // Set the new list of publishers FormField publisherField = completedForm.getField("pubsub#publisher"); if (publisherField != null) { // New list of publishers was sent to update publishers of the node List<JID> publishers = new ArrayList<JID>(); for (String value : publisherField.getValues()) { try { publishers.add(new JID(value)); } catch (Exception e) { // Do nothing } } // Calculate publishers to remove and remove them from the DB Collection<JID> oldPublishers = getPublishers(); oldPublishers.removeAll(publishers); for (JID jid : oldPublishers) { removePublisher(jid); } // Calculate new publishers and add them to the DB publishers.removeAll(getPublishers()); for (JID jid : publishers) { addPublisher(jid); } } // Let subclasses have a chance to finish node configuration based on // the completed form postConfigure(completedForm);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -