use of org.jxmpp.jid.Jid in project Smack by igniterealtime.
the class UnblockContactsIQTest method checkUnblockContactIQStanza.
@Test
public void checkUnblockContactIQStanza() throws Exception {
List<Jid> jids = new ArrayList<>();
jids.add(JidCreate.from("romeo@montague.net"));
jids.add(JidCreate.from("pepe@montague.net"));
UnblockContactsIQ unblockContactIQ = new UnblockContactsIQ(jids);
unblockContactIQ.setStanzaId("unblock1");
Assert.assertEquals(unblockContactIQExample, unblockContactIQ.toXML().toString());
}
use of org.jxmpp.jid.Jid in project Smack by igniterealtime.
the class PacketParserUtils method parseIQ.
/**
* Parses an IQ packet.
*
* @param parser the XML parser, positioned at the start of an IQ packet.
* @return an IQ object.
* @throws Exception
*/
public static IQ parseIQ(XmlPullParser parser) throws Exception {
ParserUtils.assertAtStartTag(parser);
final int initialDepth = parser.getDepth();
IQ iqPacket = null;
XMPPError.Builder error = null;
final String id = parser.getAttributeValue("", "id");
final Jid to = ParserUtils.getJidAttribute(parser, "to");
final Jid from = ParserUtils.getJidAttribute(parser, "from");
final IQ.Type type = IQ.Type.fromString(parser.getAttributeValue("", "type"));
outerloop: while (true) {
int eventType = parser.next();
switch(eventType) {
case XmlPullParser.START_TAG:
String elementName = parser.getName();
String namespace = parser.getNamespace();
switch(elementName) {
case "error":
error = PacketParserUtils.parseError(parser);
break;
// this element name and namespace.
default:
IQProvider<IQ> provider = ProviderManager.getIQProvider(elementName, namespace);
if (provider != null) {
iqPacket = provider.parse(parser);
} else // Note that if we reach this code, it is guranteed that the result IQ contained a child element
// (RFC 6120 ยง 8.2.3 6) because otherwhise we would have reached the END_TAG first.
{
// No Provider found for the IQ stanza, parse it to an UnparsedIQ instance
// so that the content of the IQ can be examined later on
iqPacket = new UnparsedIQ(elementName, namespace, parseElement(parser));
}
break;
}
break;
case XmlPullParser.END_TAG:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
}
}
// Decide what to do when an IQ packet was not understood
if (iqPacket == null) {
switch(type) {
case error:
// If an IQ packet wasn't created above, create an empty error IQ packet.
iqPacket = new ErrorIQ(error);
break;
case result:
iqPacket = new EmptyResultIQ();
break;
default:
break;
}
}
// Set basic values on the iq packet.
iqPacket.setStanzaId(id);
iqPacket.setTo(to);
iqPacket.setFrom(from);
iqPacket.setType(type);
iqPacket.setError(error);
return iqPacket;
}
use of org.jxmpp.jid.Jid in project Smack by igniterealtime.
the class ParserUtils method getEntityJidAttribute.
public static EntityJid getEntityJidAttribute(XmlPullParser parser, String name) throws XmppStringprepException {
final String jidString = parser.getAttributeValue("", name);
if (jidString == null) {
return null;
}
Jid jid = JidCreate.from(jidString);
if (!jid.hasLocalpart())
return null;
EntityFullJid fullJid = jid.asEntityFullJidIfPossible();
if (fullJid != null) {
return fullJid;
}
EntityBareJid bareJid = jid.asEntityBareJidIfPossible();
return bareJid;
}
use of org.jxmpp.jid.Jid in project Smack by igniterealtime.
the class Stanza method setTo.
/**
* Sets who the stanza(/packet) is being sent "to". The XMPP protocol often makes
* the "to" attribute optional, so it does not always need to be set.
*
* @param to who the stanza(/packet) is being sent to.
* @throws IllegalArgumentException if to is not a valid JID String.
* @deprecated use {@link #setTo(Jid)} instead.
*/
@Deprecated
public void setTo(String to) {
Jid jid;
try {
jid = JidCreate.from(to);
} catch (XmppStringprepException e) {
throw new IllegalArgumentException(e);
}
setTo(jid);
}
use of org.jxmpp.jid.Jid in project Smack by igniterealtime.
the class MUCLightChangeAffiliationsIQTest method checkChangeAffiliationsMUCLightStanza.
@Test
public void checkChangeAffiliationsMUCLightStanza() throws Exception {
HashMap<Jid, MUCLightAffiliation> affiliations = new HashMap<>();
affiliations.put(JidCreate.from("sarasa2@shakespeare.lit"), MUCLightAffiliation.owner);
affiliations.put(JidCreate.from("sarasa1@shakespeare.lit"), MUCLightAffiliation.member);
affiliations.put(JidCreate.from("sarasa3@shakespeare.lit"), MUCLightAffiliation.none);
MUCLightChangeAffiliationsIQ mucLightChangeAffiliationsIQ = new MUCLightChangeAffiliationsIQ(JidCreate.from("coven@muclight.shakespeare.lit"), affiliations);
mucLightChangeAffiliationsIQ.setStanzaId("member1");
Assert.assertEquals(mucLightChangeAffiliationsIQ.getTo(), "coven@muclight.shakespeare.lit");
Assert.assertEquals(mucLightChangeAffiliationsIQ.getType(), IQ.Type.set);
HashMap<Jid, MUCLightAffiliation> iqAffiliations = mucLightChangeAffiliationsIQ.getAffiliations();
Assert.assertEquals(iqAffiliations.get(JidCreate.from("sarasa1@shakespeare.lit")), MUCLightAffiliation.member);
Assert.assertEquals(iqAffiliations.get(JidCreate.from("sarasa2@shakespeare.lit")), MUCLightAffiliation.owner);
Assert.assertEquals(iqAffiliations.get(JidCreate.from("sarasa3@shakespeare.lit")), MUCLightAffiliation.none);
}
Aggregations