001/** 002 * 003 * Copyright 2003-2006 Jive Software. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.jivesoftware.smackx.address; 019 020import org.jivesoftware.smackx.address.packet.MultipleAddresses; 021 022import java.util.List; 023 024/** 025 * MultipleRecipientInfo keeps information about the multiple recipients extension included 026 * in a received packet. Among the information we can find the list of TO and CC addresses. 027 * 028 * @author Gaston Dombiak 029 */ 030public class MultipleRecipientInfo { 031 032 MultipleAddresses extension; 033 034 MultipleRecipientInfo(MultipleAddresses extension) { 035 this.extension = extension; 036 } 037 038 /** 039 * Returns the list of {@link org.jivesoftware.smackx.address.packet.MultipleAddresses.Address} 040 * that were the primary recipients of the packet. 041 * 042 * @return list of primary recipients of the packet. 043 */ 044 public List<MultipleAddresses.Address> getTOAddresses() { 045 return extension.getAddressesOfType(MultipleAddresses.Type.to); 046 } 047 048 /** 049 * Returns the list of {@link org.jivesoftware.smackx.address.packet.MultipleAddresses.Address} 050 * that were the secondary recipients of the packet. 051 * 052 * @return list of secondary recipients of the packet. 053 */ 054 public List<MultipleAddresses.Address> getCCAddresses() { 055 return extension.getAddressesOfType(MultipleAddresses.Type.cc); 056 } 057 058 /** 059 * Returns the JID of a MUC room to which responses should be sent or <tt>null</tt> if 060 * no specific address was provided. When no specific address was provided then the reply 061 * can be sent to any or all recipients. Otherwise, the user should join the specified room 062 * and send the reply to the room. 063 * 064 * @return the JID of a MUC room to which responses should be sent or <tt>null</tt> if 065 * no specific address was provided. 066 */ 067 public String getReplyRoom() { 068 List<MultipleAddresses.Address> replyRoom = extension.getAddressesOfType(MultipleAddresses.Type.replyroom); 069 return replyRoom.isEmpty() ? null : ((MultipleAddresses.Address) replyRoom.get(0)).getJid(); 070 } 071 072 /** 073 * Returns true if the received stanza(/packet) should not be replied. Use 074 * {@link MultipleRecipientManager#reply(org.jivesoftware.smack.XMPPConnection, org.jivesoftware.smack.packet.Message, org.jivesoftware.smack.packet.Message)} 075 * to send replies. 076 * 077 * @return true if the received stanza(/packet) should not be replied. 078 */ 079 public boolean shouldNotReply() { 080 return !extension.getAddressesOfType(MultipleAddresses.Type.noreply).isEmpty(); 081 } 082 083 /** 084 * Returns the address to which all replies are requested to be sent or <tt>null</tt> if 085 * no specific address was provided. When no specific address was provided then the reply 086 * can be sent to any or all recipients. 087 * 088 * @return the address to which all replies are requested to be sent or <tt>null</tt> if 089 * no specific address was provided. 090 */ 091 public MultipleAddresses.Address getReplyAddress() { 092 List<MultipleAddresses.Address> replyTo = extension.getAddressesOfType(MultipleAddresses.Type.replyto); 093 return replyTo.isEmpty() ? null : (MultipleAddresses.Address) replyTo.get(0); 094 } 095}