@Override public MultipleAddresses parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException { MultipleAddresses multipleAddresses = new MultipleAddresses(); outerloop: while (true) { int eventType = parser.next(); switch (eventType) { case XmlPullParser.START_TAG: String name = parser.getName(); switch (name) { case MultipleAddresses.Address.ELEMENT: String typeString = parser.getAttributeValue("", "type"); Type type = Type.valueOf(typeString); 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); break; } break; case XmlPullParser.END_TAG: if (parser.getDepth() == initialDepth) { break outerloop; } break; } } return multipleAddresses; }
MultipleRecipientInfo(MultipleAddresses extension) { this.extension = extension; }
/** * Returns the address of the multiple recipients service. To obtain such address service * discovery is going to be used on the connected server and if none was found then another * attempt will be tried on the server items. The discovered information is going to be * cached for 24 hours. * * @param connection the connection to use for disco. The connected server is going to be * queried. * @return the address of the multiple recipients service or <tt>null</tt> if none was found. * @throws NoResponseException if there was no response from the server. * @throws XMPPErrorException * @throws NotConnectedException */ private static String getMultipleRecipienServiceAddress(XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException { ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); List<String> services = sdm.findServices(MultipleAddresses.NAMESPACE, true, true); if (services.size() > 0) { return services.get(0); } return null; }
/** * Returns the {@link MultipleRecipientInfo} contained in the specified stanza(/packet) or * <tt>null</tt> if none was found. Only packets sent to multiple recipients will * contain such information. * * @param packet the stanza(/packet) to check. * @return the MultipleRecipientInfo contained in the specified stanza(/packet) or <tt>null</tt> * if none was found. */ public static MultipleRecipientInfo getMultipleRecipientInfo(Stanza packet) { MultipleAddresses extension = (MultipleAddresses) packet .getExtension(MultipleAddresses.ELEMENT, MultipleAddresses.NAMESPACE); return extension == null ? null : new MultipleRecipientInfo(extension); }
/** * Returns the list of {@link org.jivesoftware.smackx.address.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.Type.to); }
/** * Returns the list of {@link org.jivesoftware.smackx.address.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.Type.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.Type.replyroom); return replyRoom.isEmpty() ? null : ((MultipleAddresses.Address) replyRoom.get(0)).getJid(); }
/** * Returns true if the received stanza(/packet) should not be replied. Use * {@link MultipleRecipientManager#reply(org.jivesoftware.smack.XMPPConnection, org.jivesoftware.smack.packet.Message, org.jivesoftware.smack.packet.Message)} * to send replies. * * @return true if the received stanza(/packet) should not be replied. */ public boolean shouldNotReply() { return !extension.getAddressesOfType(MultipleAddresses.Type.noreply).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<MultipleAddresses.Address> replyTo = extension.getAddressesOfType(MultipleAddresses.Type.replyto); return replyTo.isEmpty() ? null : (MultipleAddresses.Address) replyTo.get(0); }