use of org.jxmpp.jid.Jid in project Smack by igniterealtime.
the class ChatConnectionTest method createChatPacket.
private static Message createChatPacket(final String threadId, final boolean isEntityFullJid) {
Message chatMsg = new Message(JidTestUtil.BARE_JID_1, Message.Type.chat);
chatMsg.setBody("the body message - " + System.currentTimeMillis());
Jid jid;
if (isEntityFullJid) {
jid = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
} else {
jid = JidTestUtil.DUMMY_AT_EXAMPLE_ORG;
}
chatMsg.setFrom(jid);
chatMsg.setThread(threadId);
return chatMsg;
}
use of org.jxmpp.jid.Jid in project Smack by igniterealtime.
the class JingleProvider method parse.
/**
* Parse a iq/jingle element.
* @throws Exception
*/
@Override
public Jingle parse(XmlPullParser parser, int intialDepth) throws Exception {
Jingle jingle = new Jingle();
String sid = "";
JingleActionEnum action;
Jid initiator = null;
Jid responder = null;
boolean done = false;
JingleContent currentContent = null;
// Sub-elements providers
JingleContentProvider jcp = new JingleContentProvider();
JingleDescriptionProvider jdpAudio = new JingleDescriptionProvider.Audio();
JingleTransportProvider jtpRawUdp = new JingleTransportProvider.RawUdp();
JingleTransportProvider jtpIce = new JingleTransportProvider.Ice();
ExtensionElementProvider<?> jmipAudio = new JingleContentInfoProvider.Audio();
int eventType;
String elementName;
String namespace;
// Get some attributes for the <jingle> element
sid = parser.getAttributeValue("", "sid");
action = JingleActionEnum.getAction(parser.getAttributeValue("", "action"));
initiator = ParserUtils.getJidAttribute(parser, "initiator");
responder = ParserUtils.getJidAttribute(parser, "responder");
jingle.setSid(sid);
jingle.setAction(action);
jingle.setInitiator(initiator);
jingle.setResponder(responder);
// Start processing sub-elements
while (!done) {
eventType = parser.next();
elementName = parser.getName();
namespace = parser.getNamespace();
if (eventType == XmlPullParser.START_TAG) {
if (elementName.equals(JingleContent.NODENAME)) {
// Add a new <content> element to the jingle
currentContent = jcp.parse(parser);
jingle.addContent(currentContent);
} else if (elementName.equals(JingleDescription.NODENAME) && namespace.equals(JingleDescription.Audio.NAMESPACE)) {
// Set the <description> element of the <content>
currentContent.setDescription(jdpAudio.parse(parser));
} else if (elementName.equals(JingleTransport.NODENAME)) {
// Parse the possible transport namespaces
if (namespace.equals(JingleTransport.RawUdp.NAMESPACE)) {
currentContent.addJingleTransport(jtpRawUdp.parse(parser));
} else if (namespace.equals(JingleTransport.Ice.NAMESPACE)) {
currentContent.addJingleTransport(jtpIce.parse(parser));
} else {
throw new SmackException("Unknown transport namespace \"" + namespace + "\" in Jingle packet.");
}
} else if (namespace.equals(JingleContentInfo.Audio.NAMESPACE)) {
jingle.setContentInfo((JingleContentInfo) jmipAudio.parse(parser));
} else {
throw new SmackException("Unknown combination of namespace \"" + namespace + "\" and element name \"" + elementName + "\" in Jingle packet.");
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals(Jingle.getElementName())) {
done = true;
}
}
}
return jingle;
}
use of org.jxmpp.jid.Jid in project Smack by igniterealtime.
the class AgentRoster method getPresence.
/**
* Returns the presence info for a particular agent, or <tt>null</tt> if the agent
* is unavailable (offline) or if no presence information is available.<p>
*
* @param user a fully qualified xmpp JID. The address could be in any valid format (e.g.
* "domain/resource", "user@domain" or "user@domain/resource").
* @return the agent's current presence, or <tt>null</tt> if the agent is unavailable
* or if no presence information is available..
*/
public Presence getPresence(Jid user) {
Jid key = getPresenceMapKey(user);
Map<Resourcepart, Presence> userPresences = presenceMap.get(key);
if (userPresences == null) {
Presence presence = new Presence(Presence.Type.unavailable);
presence.setFrom(user);
return presence;
} else {
// Find the resource with the highest priority
// Might be changed to use the resource with the highest availability instead.
Iterator<Resourcepart> it = userPresences.keySet().iterator();
Presence p;
Presence presence = null;
while (it.hasNext()) {
p = userPresences.get(it.next());
if (presence == null) {
presence = p;
} else {
if (p.getPriority() > presence.getPriority()) {
presence = p;
}
}
}
if (presence == null) {
presence = new Presence(Presence.Type.unavailable);
presence.setFrom(user);
return presence;
} else {
return presence;
}
}
}
use of org.jxmpp.jid.Jid in project Smack by igniterealtime.
the class AgentRoster method addListener.
/**
* Adds a listener to this roster. The listener will be fired anytime one or more
* changes to the roster are pushed from the server.
*
* @param listener an agent roster listener.
*/
public void addListener(AgentRosterListener listener) {
synchronized (listeners) {
if (!listeners.contains(listener)) {
listeners.add(listener);
// Fire events for the existing entries and presences in the roster
for (Iterator<String> it = getAgents().iterator(); it.hasNext(); ) {
String jid = it.next();
// but possible)
if (entries.contains(jid)) {
// Fire the agent added event
listener.agentAdded(jid);
Jid j;
try {
j = JidCreate.from(jid);
} catch (XmppStringprepException e) {
throw new IllegalStateException(e);
}
Map<Resourcepart, Presence> userPresences = presenceMap.get(j);
if (userPresences != null) {
Iterator<Presence> presences = userPresences.values().iterator();
while (presences.hasNext()) {
// Fire the presence changed event
listener.presenceChanged(presences.next());
}
}
}
}
}
}
}
use of org.jxmpp.jid.Jid in project Smack by igniterealtime.
the class IoTDiscoveryManager method unregister.
public void unregister(NodeInfo nodeInfo) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
Jid registry = findRegistry();
unregister(registry, nodeInfo);
}
Aggregations