public PacketExtension parseExtension(XmlPullParser parser) throws Exception { boolean done = false; MultipleAddresses multipleAddresses = new MultipleAddresses(); while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { if (parser.getName().equals("address")) { String type = parser.getAttributeValue("", "type"); String jid = parser.getAttributeValue("", "jid"); String node = parser.getAttributeValue("", "node"); String desc = parser.getAttributeValue("", "desc"); boolean delivered = "true".equals(parser.getAttributeValue("", "delivered")); String uri = parser.getAttributeValue("", "uri"); // Add the parsed address multipleAddresses.addAddress(type, jid, node, desc, delivered, uri); } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals(multipleAddresses.getElementName())) { done = true; } } } return multipleAddresses; }
public PacketExtension parseExtension(XmlPullParser parser) throws Exception { boolean done = false; MultipleAddresses multipleAddresses = new MultipleAddresses(); while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { if (parser.getName().equals("address")) { String type = parser.getAttributeValue("", "type"); String jid = parser.getAttributeValue("", "jid"); String node = parser.getAttributeValue("", "node"); String desc = parser.getAttributeValue("", "desc"); boolean delivered = "true".equals(parser.getAttributeValue( "", "delivered")); String uri = parser.getAttributeValue("", "uri"); // Add the parsed address multipleAddresses.addAddress(type, jid, node, desc, delivered, uri); } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals(multipleAddresses.getElementName())) { done = true; } } } return multipleAddresses; }
/** * Ensures that sending and receiving of packets is ok. */ public void testSending() throws XMPPException { PacketCollector collector1 = getConnection(1).createPacketCollector(new MessageTypeFilter(Message.Type.normal)); PacketCollector collector2 = getConnection(2).createPacketCollector(new MessageTypeFilter(Message.Type.normal)); PacketCollector collector3 = getConnection(3).createPacketCollector(new MessageTypeFilter(Message.Type.normal)); Message message = new Message(); message.setBody("Hola"); List<String> to = Arrays.asList(new String[]{getBareJID(1)}); List<String> cc = Arrays.asList(new String[]{getBareJID(2)}); List<String> bcc = Arrays.asList(new String[]{getBareJID(3)}); MultipleRecipientManager.send(getConnection(0), message, to, cc, bcc); Packet message1 = collector1.nextResult(SmackConfiguration.getPacketReplyTimeout()); assertNotNull("XMPPConnection 1 never received the message", message1); MultipleRecipientInfo info1 = MultipleRecipientManager.getMultipleRecipientInfo(message1); assertNotNull("Message 1 does not contain MultipleRecipientInfo", info1); assertFalse("Message 1 should be 'replyable'", info1.shouldNotReply()); List<?> addresses1 = info1.getTOAddresses(); assertEquals("Incorrect number of TO addresses", 1, addresses1.size()); String address1 = ((MultipleAddresses.Address) addresses1.get(0)).getJid(); assertEquals("Incorrect TO address", getBareJID(1), address1); addresses1 = info1.getCCAddresses(); assertEquals("Incorrect number of CC addresses", 1, addresses1.size()); address1 = ((MultipleAddresses.Address) addresses1.get(0)).getJid(); assertEquals("Incorrect CC address", getBareJID(2), address1); Packet message2 = collector2.nextResult(SmackConfiguration.getPacketReplyTimeout()); assertNotNull("XMPPConnection 2 never received the message", message2); MultipleRecipientInfo info2 = MultipleRecipientManager.getMultipleRecipientInfo(message2); assertNotNull("Message 2 does not contain MultipleRecipientInfo", info2); assertFalse("Message 2 should be 'replyable'", info2.shouldNotReply()); List<MultipleAddresses.Address> addresses2 = info2.getTOAddresses(); assertEquals("Incorrect number of TO addresses", 1, addresses2.size()); String address2 = ((MultipleAddresses.Address) addresses2.get(0)).getJid(); assertEquals("Incorrect TO address", getBareJID(1), address2); addresses2 = info2.getCCAddresses(); assertEquals("Incorrect number of CC addresses", 1, addresses2.size()); address2 = ((MultipleAddresses.Address) addresses2.get(0)).getJid(); assertEquals("Incorrect CC address", getBareJID(2), address2); Packet message3 = collector3.nextResult(SmackConfiguration.getPacketReplyTimeout()); assertNotNull("XMPPConnection 3 never received the message", message3); MultipleRecipientInfo info3 = MultipleRecipientManager.getMultipleRecipientInfo(message3); assertNotNull("Message 3 does not contain MultipleRecipientInfo", info3); assertFalse("Message 3 should be 'replyable'", info3.shouldNotReply()); List<MultipleAddresses.Address> addresses3 = info3.getTOAddresses(); assertEquals("Incorrect number of TO addresses", 1, addresses3.size()); String address3 = ((MultipleAddresses.Address) addresses3.get(0)).getJid(); assertEquals("Incorrect TO address", getBareJID(1), address3); addresses3 = info3.getCCAddresses(); assertEquals("Incorrect number of CC addresses", 1, addresses3.size()); address3 = ((MultipleAddresses.Address) addresses3.get(0)).getJid(); assertEquals("Incorrect CC address", getBareJID(2), address3); collector1.cancel(); collector2.cancel(); collector3.cancel(); }
MultipleRecipientInfo(MultipleAddresses extension) { this.extension = extension; }
/** * Ensures that sending and receiving of packets is ok. */ public void testSending() throws XMPPException { PacketCollector collector1 = getConnection(1).createPacketCollector(new MessageTypeFilter(Message.Type.normal)); PacketCollector collector2 = getConnection(2).createPacketCollector(new MessageTypeFilter(Message.Type.normal)); PacketCollector collector3 = getConnection(3).createPacketCollector(new MessageTypeFilter(Message.Type.normal)); Message message = new Message(); message.setBody("Hola"); List<String> to = Arrays.asList(new String[]{getBareJID(1)}); List<String> cc = Arrays.asList(new String[]{getBareJID(2)}); List<String> bcc = Arrays.asList(new String[]{getBareJID(3)}); MultipleRecipientManager.send(getConnection(0), message, to, cc, bcc); Packet message1 = collector1.nextResult(SmackConfiguration.getPacketReplyTimeout()); assertNotNull("Connection 1 never received the message", message1); MultipleRecipientInfo info1 = MultipleRecipientManager.getMultipleRecipientInfo(message1); assertNotNull("Message 1 does not contain MultipleRecipientInfo", info1); assertFalse("Message 1 should be 'replyable'", info1.shouldNotReply()); List<?> addresses1 = info1.getTOAddresses(); assertEquals("Incorrect number of TO addresses", 1, addresses1.size()); String address1 = ((MultipleAddresses.Address) addresses1.get(0)).getJid(); assertEquals("Incorrect TO address", getBareJID(1), address1); addresses1 = info1.getCCAddresses(); assertEquals("Incorrect number of CC addresses", 1, addresses1.size()); address1 = ((MultipleAddresses.Address) addresses1.get(0)).getJid(); assertEquals("Incorrect CC address", getBareJID(2), address1); Packet message2 = collector2.nextResult(SmackConfiguration.getPacketReplyTimeout()); assertNotNull("Connection 2 never received the message", message2); MultipleRecipientInfo info2 = MultipleRecipientManager.getMultipleRecipientInfo(message2); assertNotNull("Message 2 does not contain MultipleRecipientInfo", info2); assertFalse("Message 2 should be 'replyable'", info2.shouldNotReply()); List<MultipleAddresses.Address> addresses2 = info2.getTOAddresses(); assertEquals("Incorrect number of TO addresses", 1, addresses2.size()); String address2 = ((MultipleAddresses.Address) addresses2.get(0)).getJid(); assertEquals("Incorrect TO address", getBareJID(1), address2); addresses2 = info2.getCCAddresses(); assertEquals("Incorrect number of CC addresses", 1, addresses2.size()); address2 = ((MultipleAddresses.Address) addresses2.get(0)).getJid(); assertEquals("Incorrect CC address", getBareJID(2), address2); Packet message3 = collector3.nextResult(SmackConfiguration.getPacketReplyTimeout()); assertNotNull("Connection 3 never received the message", message3); MultipleRecipientInfo info3 = MultipleRecipientManager.getMultipleRecipientInfo(message3); assertNotNull("Message 3 does not contain MultipleRecipientInfo", info3); assertFalse("Message 3 should be 'replyable'", info3.shouldNotReply()); List<MultipleAddresses.Address> addresses3 = info3.getTOAddresses(); assertEquals("Incorrect number of TO addresses", 1, addresses3.size()); String address3 = ((MultipleAddresses.Address) addresses3.get(0)).getJid(); assertEquals("Incorrect TO address", getBareJID(1), address3); addresses3 = info3.getCCAddresses(); assertEquals("Incorrect number of CC addresses", 1, addresses3.size()); address3 = ((MultipleAddresses.Address) addresses3.get(0)).getJid(); assertEquals("Incorrect CC address", getBareJID(2), address3); collector1.cancel(); collector2.cancel(); collector3.cancel(); }
/** * Returns the JID of a MUC room to which responses should be sent or * <tt>null</tt> if no specific address was provided. When no specific * address was provided then the reply can be sent to any or all recipients. * Otherwise, the user should join the specified room and send the reply to * the room. * * @return the JID of a MUC room to which responses should be sent or * <tt>null</tt> if no specific address was provided. */ public String getReplyRoom() { List replyRoom = extension .getAddressesOfType(MultipleAddresses.REPLY_ROOM); return replyRoom.isEmpty() ? null : ((MultipleAddresses.Address) replyRoom.get(0)).getJid(); }
/** * Returns the {@link MultipleRecipientInfo} contained in the specified packet or * <tt>null</tt> if none was found. Only packets sent to multiple recipients will * contain such information. * * @param packet the packet to check. * @return the MultipleRecipientInfo contained in the specified packet or <tt>null</tt> * if none was found. */ public static MultipleRecipientInfo getMultipleRecipientInfo(Packet packet) { MultipleAddresses extension = (MultipleAddresses) packet .getExtension("addresses", "http://jabber.org/protocol/address"); return extension == null ? null : new MultipleRecipientInfo(extension); }
/** * Returns the list of {@link org.jivesoftware.smackx.packet.MultipleAddresses.Address} * that were the primary recipients of the packet. * * @return list of primary recipients of the packet. */ public List getTOAddresses() { return extension.getAddressesOfType(MultipleAddresses.TO); }
/** * Returns the list of {@link org.jivesoftware.smackx.packet.MultipleAddresses.Address} * that were the secondary recipients of the packet. * * @return list of secondary recipients of the packet. */ public List getCCAddresses() { return extension.getAddressesOfType(MultipleAddresses.CC); }
/** * Returns the JID of a MUC room to which responses should be sent or <tt>null</tt> if * no specific address was provided. When no specific address was provided then the reply * can be sent to any or all recipients. Otherwise, the user should join the specified room * and send the reply to the room. * * @return the JID of a MUC room to which responses should be sent or <tt>null</tt> if * no specific address was provided. */ public String getReplyRoom() { List replyRoom = extension.getAddressesOfType(MultipleAddresses.REPLY_ROOM); return replyRoom.isEmpty() ? null : ((MultipleAddresses.Address) replyRoom.get(0)).getJid(); }
/** * Returns true if the received packet should not be replied. Use * {@link MultipleRecipientManager#reply(org.jivesoftware.smack.Connection, org.jivesoftware.smack.packet.Message, org.jivesoftware.smack.packet.Message)} * to send replies. * * @return true if the received packet should not be replied. */ public boolean shouldNotReply() { return !extension.getAddressesOfType(MultipleAddresses.NO_REPLY).isEmpty(); }
/** * Returns the address to which all replies are requested to be sent or <tt>null</tt> if * no specific address was provided. When no specific address was provided then the reply * can be sent to any or all recipients. * * @return the address to which all replies are requested to be sent or <tt>null</tt> if * no specific address was provided. */ public MultipleAddresses.Address getReplyAddress() { List replyTo = extension.getAddressesOfType(MultipleAddresses.REPLY_TO); return replyTo.isEmpty() ? null : (MultipleAddresses.Address) replyTo.get(0); }
/** * Returns the list of {@link org.jivesoftware.smackx.packet.MultipleAddresses.Address} * that were the primary recipients of the packet. * * @return list of primary recipients of the packet. */ public List<MultipleAddresses.Address> getTOAddresses() { return extension.getAddressesOfType(MultipleAddresses.TO); }
/** * Returns the list of {@link org.jivesoftware.smackx.packet.MultipleAddresses.Address} * that were the secondary recipients of the packet. * * @return list of secondary recipients of the packet. */ public List<MultipleAddresses.Address> getCCAddresses() { return extension.getAddressesOfType(MultipleAddresses.CC); }
/** * Returns the JID of a MUC room to which responses should be sent or <tt>null</tt> if * no specific address was provided. When no specific address was provided then the reply * can be sent to any or all recipients. Otherwise, the user should join the specified room * and send the reply to the room. * * @return the JID of a MUC room to which responses should be sent or <tt>null</tt> if * no specific address was provided. */ public String getReplyRoom() { List<MultipleAddresses.Address> replyRoom = extension.getAddressesOfType(MultipleAddresses.REPLY_ROOM); return replyRoom.isEmpty() ? null : ((MultipleAddresses.Address) replyRoom.get(0)).getJid(); }
/** * Returns the address to which all replies are requested to be sent or <tt>null</tt> if * no specific address was provided. When no specific address was provided then the reply * can be sent to any or all recipients. * * @return the address to which all replies are requested to be sent or <tt>null</tt> if * no specific address was provided. */ public MultipleAddresses.Address getReplyAddress() { List<MultipleAddresses.Address> replyTo = extension.getAddressesOfType(MultipleAddresses.REPLY_TO); return replyTo.isEmpty() ? null : (MultipleAddresses.Address) replyTo.get(0); }
/** * Returns the {@link MultipleRecipientInfo} contained in the specified * packet or <tt>null</tt> if none was found. Only packets sent to multiple * recipients will contain such information. * * @param packet * the packet to check. * @return the MultipleRecipientInfo contained in the specified packet or * <tt>null</tt> if none was found. */ public static MultipleRecipientInfo getMultipleRecipientInfo(Packet packet) { MultipleAddresses extension = (MultipleAddresses) packet.getExtension( "addresses", "http://jabber.org/protocol/address"); return extension == null ? null : new MultipleRecipientInfo(extension); }
/** * Returns the list of * {@link org.jivesoftware.smackx.packet.MultipleAddresses.Address} that * were the primary recipients of the packet. * * @return list of primary recipients of the packet. */ public List getTOAddresses() { return extension.getAddressesOfType(MultipleAddresses.TO); }
/** * Returns the list of * {@link org.jivesoftware.smackx.packet.MultipleAddresses.Address} that * were the secondary recipients of the packet. * * @return list of secondary recipients of the packet. */ public List getCCAddresses() { return extension.getAddressesOfType(MultipleAddresses.CC); }
/** * Returns true if the received packet should not be replied. Use * {@link MultipleRecipientManager#reply(org.jivesoftware.smack.Connection, org.jivesoftware.smack.packet.Message, org.jivesoftware.smack.packet.Message)} * to send replies. * * @return true if the received packet should not be replied. */ public boolean shouldNotReply() { return !extension.getAddressesOfType(MultipleAddresses.NO_REPLY) .isEmpty(); }
/** * Returns the address to which all replies are requested to be sent or * <tt>null</tt> if no specific address was provided. When no specific * address was provided then the reply can be sent to any or all recipients. * * @return the address to which all replies are requested to be sent or * <tt>null</tt> if no specific address was provided. */ public MultipleAddresses.Address getReplyAddress() { List replyTo = extension.getAddressesOfType(MultipleAddresses.REPLY_TO); return replyTo.isEmpty() ? null : (MultipleAddresses.Address) replyTo .get(0); }