Class PrivacyRule

  • All Implemented Interfaces:
    Comparable<PrivacyRule>

    public final class PrivacyRule
    extends Object
    implements Comparable<PrivacyRule>
    A privacy rule for privacy lists, which is applied by the server.

    2.2 Business Rules

    • The order in which privacy list items are processed by the server is important. List items MUST be processed in ascending order determined by the integer values of the 'order' attribute for each <item/>.
    • As soon as a stanza is matched against a privacy list rule, the server MUST appropriately handle the stanza in accordance with the rule and cease processing.
    • If no fall-through item is provided in a list, the fall-through action is assumed to be "allow".

    Usage

    In order to create a privacy rule, use one of the many static factory methods, e.g.:

    
     // Blocks all messages from juliet@example.net
     PrivacyRule rule1 = PrivacyRule.blockMessagesFrom(Jid.of("juliet@example.net"), 1);
    
     // Blocks outbound presence notifications to the roster group "Bad Friends".
     PrivacyRule rule2 = PrivacyRule.blockPresenceToRosterGroup("Bad Friends", 2);
     

    This class is immutable.

    • Method Detail

      • of

        public static PrivacyRule of​(PrivacyRule.Action action,
                                     long order)
        Creates a privacy list item, which allows or blocks everything.
        Parameters:
        action - The action to perform, i.e. either allow or deny.
        order - The order in which the privacy item is processed by the server. A non-negative integer that is unique among all items in the list.
        Returns:
        The privacy rule.
      • of

        public static PrivacyRule of​(Jid jid,
                                     PrivacyRule.Action action,
                                     long order)
        Creates a privacy rule of type 'jid'.
        Parameters:
        jid - The JID.
        action - The action to perform, i.e. either allow or deny.
        order - The order in which the privacy item is processed by the server. A non-negative integer that is unique among all items in the list.
        Returns:
        The privacy rule.
      • of

        public static PrivacyRule of​(String group,
                                     PrivacyRule.Action action,
                                     long order)
        Creates a privacy rule of type 'group'.
        Parameters:
        group - The roster group.
        action - The action to perform, i.e. either allow or deny.
        order - The order in which the privacy item is processed by the server. A non-negative integer that is unique among all items in the list.
        Returns:
        The privacy rule.
      • of

        public static PrivacyRule of​(SubscriptionState.Subscription subscription,
                                     PrivacyRule.Action action,
                                     long order)
        Creates a privacy rule of type 'subscription'.
        Parameters:
        subscription - The subscription type.
        action - The action to perform, i.e. either allow or deny.
        order - The order in which the privacy item is processed by the server. A non-negative integer that is unique among all items in the list.
        Returns:
        The privacy rule.
      • blockMessagesFrom

        public static PrivacyRule blockMessagesFrom​(Jid entity,
                                                    long order)
        Creates a rule, which blocks all inbound messages from another entity.

        The user will not receive messages from the entity with the specified JID.

        Parameters:
        entity - The entity.
        order - The order, this rule will be applied within the privacy list.
        Returns:
        The privacy rule.
        See Also:
        2.9 Blocking Messages
      • blockMessagesFromRosterGroup

        public static PrivacyRule blockMessagesFromRosterGroup​(String rosterGroup,
                                                               long order)
        Creates a rule, which blocks all inbound messages from contacts, which are in the specified roster group.

        The user will not receive messages from any entities in the specified roster group.

        Parameters:
        rosterGroup - The roster group.
        order - The order, this rule will be applied within the privacy list.
        Returns:
        The privacy rule.
        See Also:
        2.9 Blocking Messages
      • blockMessagesFromEntitiesWithSubscription

        public static PrivacyRule blockMessagesFromEntitiesWithSubscription​(SubscriptionState.Subscription subscription,
                                                                            long order)
        Creates a rule, which blocks all inbound messages from entities with the given subscription type.

        The user will not receive messages from any entities with the specified subscription type.

        Parameters:
        subscription - The subscription type.
        order - The order, this rule will be applied within the privacy list.
        Returns:
        The privacy rule.
        See Also:
        2.9 Blocking Messages
      • blockPresenceFrom

        public static PrivacyRule blockPresenceFrom​(Jid entity,
                                                    long order)
        Creates a rule, which blocks all inbound presence notifications from another entity.

        The user will not receive presence notifications from the entity with the specified JID.

        Parameters:
        entity - The entity.
        order - The order, this rule will be applied within the privacy list.
        Returns:
        The privacy rule.
        See Also:
        2.10 Blocking Inbound Presence Notifications
      • blockPresenceFromRosterGroup

        public static PrivacyRule blockPresenceFromRosterGroup​(String rosterGroup,
                                                               long order)
        Creates a rule, which blocks all inbound presence notifications from contacts, which are in the specified roster group.

        The user will not receive presence notifications from any entities in the specified roster group.

        Parameters:
        rosterGroup - The roster group.
        order - The order, this rule will be applied within the privacy list.
        Returns:
        The privacy rule.
        See Also:
        2.10 Blocking Inbound Presence Notifications
      • blockPresenceFromEntitiesWithSubscription

        public static PrivacyRule blockPresenceFromEntitiesWithSubscription​(SubscriptionState.Subscription subscription,
                                                                            long order)
        Creates a rule, which blocks all inbound presence notifications from entities with the given subscription type.

        The user will not receive presence notifications from any entities with the specified subscription type.

        Parameters:
        subscription - The subscription type.
        order - The order, this rule will be applied within the privacy list.
        Returns:
        The privacy rule.
        See Also:
        2.10 Blocking Inbound Presence Notifications
      • blockInboundPresence

        public static PrivacyRule blockInboundPresence​(long order)
        Creates a rule, which blocks all inbound presence notifications.

        The user will not receive presence notifications from any other users.

        Parameters:
        order - The order, this rule will be applied within the privacy list.
        Returns:
        The privacy rule.
        See Also:
        2.11 Blocking Outbound Presence Notifications
      • blockPresenceTo

        public static PrivacyRule blockPresenceTo​(Jid entity,
                                                  long order)
        Creates a rule, which blocks all outbound presence notifications to another entity.

        The user will not send presence notifications to the entity with the specified JID.

        Parameters:
        entity - The entity.
        order - The order, this rule will be applied within the privacy list.
        Returns:
        The privacy rule.
        See Also:
        2.11 Blocking Outbound Presence Notifications
      • blockPresenceToRosterGroup

        public static PrivacyRule blockPresenceToRosterGroup​(String rosterGroup,
                                                             long order)
        Creates a rule, which blocks all outbound presence notifications to contacts, which are in the specified roster group.

        The user will not send presence notifications to any entities in the specified roster group.

        Parameters:
        rosterGroup - The roster group.
        order - The order, this rule will be applied within the privacy list.
        Returns:
        The privacy rule.
        See Also:
        2.11 Blocking Outbound Presence Notifications
      • blockPresenceToEntitiesWithSubscription

        public static PrivacyRule blockPresenceToEntitiesWithSubscription​(SubscriptionState.Subscription subscription,
                                                                          long order)
        Creates a rule, which blocks all outbound presence notifications to entities with the given subscription type.

        The user will not send presence notifications to any entities with the specified subscription type.

        Parameters:
        subscription - The subscription type.
        order - The order, this rule will be applied within the privacy list.
        Returns:
        The privacy rule.
        See Also:
        2.11 Blocking Outbound Presence Notifications
      • blockOutboundPresence

        public static PrivacyRule blockOutboundPresence​(long order)
        Creates a rule, which blocks all outbound presence notifications.

        The user will not send presence notifications to any other users.

        Parameters:
        order - The order, this rule will be applied within the privacy list.
        Returns:
        The privacy rule.
        See Also:
        2.11 Blocking Outbound Presence Notifications
      • blockIQFrom

        public static PrivacyRule blockIQFrom​(Jid entity,
                                              long order)
        Creates a rule, which blocks all inbound IQ stanzas from another entity.

        The user will not receive IQ stanzas from the entity with the specified JID.

        Parameters:
        entity - The entity.
        order - The order, this rule will be applied within the privacy list.
        Returns:
        The privacy rule.
        See Also:
        2.12 Blocking IQ Stanzas
      • blockIQFromRosterGroup

        public static PrivacyRule blockIQFromRosterGroup​(String rosterGroup,
                                                         long order)
        Creates a rule, which blocks all inbound IQ stanzas from contacts, which are in the specified roster group.

        The user will not receive IQ stanzas from any entities in the specified roster group.

        Parameters:
        rosterGroup - The roster group.
        order - The order, this rule will be applied within the privacy list.
        Returns:
        The privacy rule.
        See Also:
        2.12 Blocking IQ Stanzas
      • blockIQFromEntitiesWithSubscription

        public static PrivacyRule blockIQFromEntitiesWithSubscription​(SubscriptionState.Subscription subscription,
                                                                      long order)
        Creates a rule, which blocks all inbound IQ stanzas from entities with the given subscription type.

        The user will not receive IQ stanzas from any entities with the specified subscription type.

        Parameters:
        subscription - The subscription type.
        order - The order, this rule will be applied within the privacy list.
        Returns:
        The privacy rule.
        See Also:
        2.12 Blocking IQ Stanzas
      • blockAllCommunicationWithRosterGroup

        public static PrivacyRule blockAllCommunicationWithRosterGroup​(String rosterGroup,
                                                                       long order)
        Creates a rule, which blocks all communication from and to any entities in the specified roster group.

        The user will not receive any communications from, nor send any stanzas to, any entities in the specified roster group.

        Parameters:
        rosterGroup - The roster group.
        order - The order, this rule will be applied within the privacy list.
        Returns:
        The privacy rule.
        See Also:
        2.13 Blocking All Communication
      • blockAllCommunicationWithEntitiesWithSubscription

        public static PrivacyRule blockAllCommunicationWithEntitiesWithSubscription​(SubscriptionState.Subscription subscription,
                                                                                    long order)
        Creates a rule, which blocks all communication from and to any entities in the specified roster group.

        The user will not receive any communications from, nor send any stanzas to, any entities in the specified roster group.

        Parameters:
        subscription - The subscription type.
        order - The order, this rule will be applied within the privacy list.
        Returns:
        The privacy rule.
        See Also:
        2.13 Blocking All Communication
      • blockAllCommunicationWith

        public static PrivacyRule blockAllCommunicationWith​(Jid entity,
                                                            long order)
        Creates a rule, which blocks all communication from and to another entity.

        The user will not receive any communications from, nor send any stanzas to, the entity with the specified JID.

        Parameters:
        entity - The entity.
        order - The order, this rule will be applied within the privacy list.
        Returns:
        The privacy rule.
        See Also:
        2.13 Blocking All Communication
      • getType

        public final PrivacyRule.Type getType()
        Gets the type.
        Returns:
        The type.
      • getAction

        public final PrivacyRule.Action getAction()
        Sets the action to perform (either allow or deny).
        Returns:
        The action.
      • getValue

        public final String getValue()
        Gets the value.
        Returns:
        The value.
      • getOrder

        public final long getOrder()
        Gets the order in which privacy items are processed by the server.
        Returns:
        The order.
      • isAppliedToMessages

        public final boolean isAppliedToMessages()
        Indicates, whether this rule is applied to inbound messages.
        Returns:
        True, if this rule is applied to inbound messages.
      • appliedToMessages

        public final PrivacyRule appliedToMessages()
        Creates a new privacy rule, which is applied to inbound messages.
        Returns:
        The privacy rule.
        See Also:
        isAppliedToMessages()
      • isAppliedToIQs

        public final boolean isAppliedToIQs()
        Indicates, whether this rule is applied to inbound IQ stanzas.
        Returns:
        True, if this rule is applied to inbound IQ stanzas.
      • appliedToIQs

        public final PrivacyRule appliedToIQs()
        Creates a new privacy rule, which is applied to IQ stanzas.
        Returns:
        The privacy rule.
        See Also:
        isAppliedToIQs()
      • isAppliedToInboundPresence

        public final boolean isAppliedToInboundPresence()
        Indicates, whether this rule is applied to inbound presence notifications.
        Returns:
        True, if this rule is applied to inbound presence notifications.
      • appliedToInboundPresence

        public final PrivacyRule appliedToInboundPresence()
        Creates a new privacy rule, which is applied to inbound presence notifications.
        Returns:
        The privacy rule.
        See Also:
        isAppliedToInboundPresence()
      • isAppliedToOutboundPresence

        public final boolean isAppliedToOutboundPresence()
        Indicates, whether this rule is applied to outbound presence notifications.
        Returns:
        True, if this rule is applied to outbound presence notifications.
      • appliedToOutboundPresence

        public final PrivacyRule appliedToOutboundPresence()
        Creates a new privacy rule, which is applied to outbound presence notifications.
        Returns:
        The privacy rule.
        See Also:
        isAppliedToOutboundPresence()
      • compareTo

        public final int compareTo​(PrivacyRule o)
        Compares this rule with another rule by comparing their order.
        Specified by:
        compareTo in interface Comparable<PrivacyRule>
        Parameters:
        o - The other rule.
        Returns:
        The comparison result.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object