MultipleRecipientInfo.java

  1. /**
  2.  *
  3.  * Copyright 2003-2006 Jive Software.
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.jivesoftware.smackx.address;

  18. import org.jivesoftware.smackx.address.packet.MultipleAddresses;
  19. import org.jxmpp.jid.Jid;

  20. import java.util.List;

  21. /**
  22.  * MultipleRecipientInfo keeps information about the multiple recipients extension included
  23.  * in a received packet. Among the information we can find the list of TO and CC addresses.
  24.  *
  25.  * @author Gaston Dombiak
  26.  */
  27. public class MultipleRecipientInfo {

  28.     MultipleAddresses extension;

  29.     MultipleRecipientInfo(MultipleAddresses extension) {
  30.         this.extension = extension;
  31.     }

  32.     /**
  33.      * Returns the list of {@link org.jivesoftware.smackx.address.packet.MultipleAddresses.Address}
  34.      * that were the primary recipients of the packet.
  35.      *
  36.      * @return list of primary recipients of the packet.
  37.      */
  38.     public List<MultipleAddresses.Address> getTOAddresses() {
  39.         return extension.getAddressesOfType(MultipleAddresses.Type.to);
  40.     }

  41.     /**
  42.      * Returns the list of {@link org.jivesoftware.smackx.address.packet.MultipleAddresses.Address}
  43.      * that were the secondary recipients of the packet.
  44.      *
  45.      * @return list of secondary recipients of the packet.
  46.      */
  47.     public List<MultipleAddresses.Address> getCCAddresses() {
  48.         return extension.getAddressesOfType(MultipleAddresses.Type.cc);
  49.     }

  50.     /**
  51.      * Returns the JID of a MUC room to which responses should be sent or <tt>null</tt>  if
  52.      * no specific address was provided. When no specific address was provided then the reply
  53.      * can be sent to any or all recipients. Otherwise, the user should join the specified room
  54.      * and send the reply to the room.
  55.      *
  56.      * @return the JID of a MUC room to which responses should be sent or <tt>null</tt>  if
  57.      *         no specific address was provided.
  58.      */
  59.     // TODO should return BareJid
  60.     public Jid getReplyRoom() {
  61.         List<MultipleAddresses.Address> replyRoom = extension.getAddressesOfType(MultipleAddresses.Type.replyroom);
  62.         return replyRoom.isEmpty() ? null : ((MultipleAddresses.Address) replyRoom.get(0)).getJid();
  63.     }

  64.     /**
  65.      * Returns true if the received packet should not be replied. Use
  66.      * {@link MultipleRecipientManager#reply(org.jivesoftware.smack.XMPPConnection, org.jivesoftware.smack.packet.Message, org.jivesoftware.smack.packet.Message)}
  67.      * to send replies.
  68.      *
  69.      * @return true if the received packet should not be replied.
  70.      */
  71.     public boolean shouldNotReply() {
  72.         return !extension.getAddressesOfType(MultipleAddresses.Type.noreply).isEmpty();
  73.     }

  74.     /**
  75.      * Returns the address to which all replies are requested to be sent or <tt>null</tt> if
  76.      * no specific address was provided. When no specific address was provided then the reply
  77.      * can be sent to any or all recipients.
  78.      *
  79.      * @return the address to which all replies are requested to be sent or <tt>null</tt> if
  80.      *         no specific address was provided.
  81.      */
  82.     public MultipleAddresses.Address getReplyAddress() {
  83.         List<MultipleAddresses.Address> replyTo = extension.getAddressesOfType(MultipleAddresses.Type.replyto);
  84.         return replyTo.isEmpty() ? null : (MultipleAddresses.Address) replyTo.get(0);
  85.     }
  86. }