Search in sources :

Example 51 with Jid

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;
}
Also used : Message(org.jivesoftware.smack.packet.Message) Jid(org.jxmpp.jid.Jid)

Example 52 with Jid

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;
}
Also used : Jid(org.jxmpp.jid.Jid) SmackException(org.jivesoftware.smack.SmackException) JingleActionEnum(org.jivesoftware.smackx.jingleold.JingleActionEnum) Jingle(org.jivesoftware.smackx.jingleold.packet.Jingle) JingleContentInfo(org.jivesoftware.smackx.jingleold.packet.JingleContentInfo) JingleContent(org.jivesoftware.smackx.jingleold.packet.JingleContent)

Example 53 with Jid

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;
        }
    }
}
Also used : Jid(org.jxmpp.jid.Jid) EntityFullJid(org.jxmpp.jid.EntityFullJid) Presence(org.jivesoftware.smack.packet.Presence) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Example 54 with Jid

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());
                        }
                    }
                }
            }
        }
    }
}
Also used : Jid(org.jxmpp.jid.Jid) EntityFullJid(org.jxmpp.jid.EntityFullJid) Presence(org.jivesoftware.smack.packet.Presence) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Example 55 with Jid

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);
}
Also used : Jid(org.jxmpp.jid.Jid) BareJid(org.jxmpp.jid.BareJid)

Aggregations

Jid (org.jxmpp.jid.Jid)78 EntityBareJid (org.jxmpp.jid.EntityBareJid)18 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)14 Test (org.junit.Test)14 DomainBareJid (org.jxmpp.jid.DomainBareJid)14 EntityFullJid (org.jxmpp.jid.EntityFullJid)12 BareJid (org.jxmpp.jid.BareJid)11 IQ (org.jivesoftware.smack.packet.IQ)7 Presence (org.jivesoftware.smack.packet.Presence)7 MUCLightBlockingIQ (org.jivesoftware.smackx.muclight.element.MUCLightBlockingIQ)7 SmackException (org.jivesoftware.smack.SmackException)6 Message (org.jivesoftware.smack.packet.Message)6 WeakHashMap (java.util.WeakHashMap)4 XMPPConnection (org.jivesoftware.smack.XMPPConnection)4 Map (java.util.Map)3 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)3 FeatureNotSupportedException (org.jivesoftware.smack.SmackException.FeatureNotSupportedException)3 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)3 Bytestream (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream)3