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 java.util.List; 021 022import org.jivesoftware.smackx.address.packet.MultipleAddresses; 023 024import org.jxmpp.jid.Jid; 025 026/** 027 * MultipleRecipientInfo keeps information about the multiple recipients extension included 028 * in a received packet. Among the information we can find the list of TO and CC addresses. 029 * 030 * @author Gaston Dombiak 031 */ 032public class MultipleRecipientInfo { 033 034 MultipleAddresses extension; 035 036 MultipleRecipientInfo(MultipleAddresses extension) { 037 this.extension = extension; 038 } 039 040 /** 041 * Returns the list of {@link org.jivesoftware.smackx.address.packet.MultipleAddresses.Address} 042 * that were the primary recipients of the packet. 043 * 044 * @return list of primary recipients of the packet. 045 */ 046 public List<MultipleAddresses.Address> getTOAddresses() { 047 return extension.getAddressesOfType(MultipleAddresses.Type.to); 048 } 049 050 /** 051 * Returns the list of {@link org.jivesoftware.smackx.address.packet.MultipleAddresses.Address} 052 * that were the secondary recipients of the packet. 053 * 054 * @return list of secondary recipients of the packet. 055 */ 056 public List<MultipleAddresses.Address> getCCAddresses() { 057 return extension.getAddressesOfType(MultipleAddresses.Type.cc); 058 } 059 060 /** 061 * Returns the JID of a MUC room to which responses should be sent or <tt>null</tt> if 062 * no specific address was provided. When no specific address was provided then the reply 063 * can be sent to any or all recipients. Otherwise, the user should join the specified room 064 * and send the reply to the room. 065 * 066 * @return the JID of a MUC room to which responses should be sent or <tt>null</tt> if 067 * no specific address was provided. 068 */ 069 // TODO should return EntityBareJid 070 public Jid getReplyRoom() { 071 List<MultipleAddresses.Address> replyRoom = extension.getAddressesOfType(MultipleAddresses.Type.replyroom); 072 return replyRoom.isEmpty() ? null : replyRoom.get(0).getJid(); 073 } 074 075 /** 076 * Returns true if the received stanza should not be replied. Use 077 * {@link MultipleRecipientManager#reply(org.jivesoftware.smack.XMPPConnection, org.jivesoftware.smack.packet.Message, org.jivesoftware.smack.packet.Message)} 078 * to send replies. 079 * 080 * @return true if the received stanza should not be replied. 081 */ 082 public boolean shouldNotReply() { 083 return !extension.getAddressesOfType(MultipleAddresses.Type.noreply).isEmpty(); 084 } 085 086 /** 087 * Returns the address to which all replies are requested to be sent or <tt>null</tt> if 088 * no specific address was provided. When no specific address was provided then the reply 089 * can be sent to any or all recipients. 090 * 091 * @return the address to which all replies are requested to be sent or <tt>null</tt> if 092 * no specific address was provided. 093 */ 094 public MultipleAddresses.Address getReplyAddress() { 095 List<MultipleAddresses.Address> replyTo = extension.getAddressesOfType(MultipleAddresses.Type.replyto); 096 return replyTo.isEmpty() ? null : replyTo.get(0); 097 } 098}