1/**
2 * $RCSfile$
3 * $Revision$
4 * $Date$
5 *
6 * Copyright 2003-2006 Jive Software.
7 *
8 * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 *     http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21package org.jivesoftware.smackx;
22
23import org.jivesoftware.smackx.packet.MultipleAddresses;
24
25import java.util.List;
26
27/**
28 * MultipleRecipientInfo keeps information about the multiple recipients extension included
29 * in a received packet. Among the information we can find the list of TO and CC addresses.
30 *
31 * @author Gaston Dombiak
32 */
33public class MultipleRecipientInfo {
34
35    MultipleAddresses extension;
36
37    MultipleRecipientInfo(MultipleAddresses extension) {
38        this.extension = extension;
39    }
40
41    /**
42     * Returns the list of {@link org.jivesoftware.smackx.packet.MultipleAddresses.Address}
43     * that were the primary recipients of the packet.
44     *
45     * @return list of primary recipients of the packet.
46     */
47    public List<MultipleAddresses.Address> getTOAddresses() {
48        return extension.getAddressesOfType(MultipleAddresses.TO);
49    }
50
51    /**
52     * Returns the list of {@link org.jivesoftware.smackx.packet.MultipleAddresses.Address}
53     * that were the secondary recipients of the packet.
54     *
55     * @return list of secondary recipients of the packet.
56     */
57    public List<MultipleAddresses.Address> getCCAddresses() {
58        return extension.getAddressesOfType(MultipleAddresses.CC);
59    }
60
61    /**
62     * Returns the JID of a MUC room to which responses should be sent or <tt>null</tt>  if
63     * no specific address was provided. When no specific address was provided then the reply
64     * can be sent to any or all recipients. Otherwise, the user should join the specified room
65     * and send the reply to the room.
66     *
67     * @return the JID of a MUC room to which responses should be sent or <tt>null</tt>  if
68     *         no specific address was provided.
69     */
70    public String getReplyRoom() {
71        List<MultipleAddresses.Address> replyRoom = extension.getAddressesOfType(MultipleAddresses.REPLY_ROOM);
72        return replyRoom.isEmpty() ? null : ((MultipleAddresses.Address) replyRoom.get(0)).getJid();
73    }
74
75    /**
76     * Returns true if the received packet should not be replied. Use
77     * {@link MultipleRecipientManager#reply(org.jivesoftware.smack.Connection, org.jivesoftware.smack.packet.Message, org.jivesoftware.smack.packet.Message)}
78     * to send replies.
79     *
80     * @return true if the received packet should not be replied.
81     */
82    public boolean shouldNotReply() {
83        return !extension.getAddressesOfType(MultipleAddresses.NO_REPLY).isEmpty();
84    }
85
86    /**
87     * Returns the address to which all replies are requested to be sent or <tt>null</tt> if
88     * no specific address was provided. When no specific address was provided then the reply
89     * can be sent to any or all recipients.
90     *
91     * @return the address to which all replies are requested to be sent or <tt>null</tt> if
92     *         no specific address was provided.
93     */
94    public MultipleAddresses.Address getReplyAddress() {
95        List<MultipleAddresses.Address> replyTo = extension.getAddressesOfType(MultipleAddresses.REPLY_TO);
96        return replyTo.isEmpty() ? null : (MultipleAddresses.Address) replyTo.get(0);
97    }
98}
99