Search in sources :

Example 6 with Jid

use of org.jxmpp.jid.Jid in project Smack by igniterealtime.

the class EnhancedDebugger method addSentPacketToTable.

/**
     * Adds the sent stanza(/packet) detail to the messages table.
     *
     * @param dateFormatter the SimpleDateFormat to use to format Dates
     * @param packet        the sent stanza(/packet) to add to the table
     */
private void addSentPacketToTable(final SimpleDateFormat dateFormatter, final Stanza packet) {
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            String messageType;
            Jid to = packet.getTo();
            String type = "";
            Icon packetTypeIcon;
            sentPackets++;
            if (packet instanceof IQ) {
                packetTypeIcon = iqPacketIcon;
                messageType = "IQ Sent (class=" + packet.getClass().getName() + ")";
                type = ((IQ) packet).getType().toString();
                sentIQPackets++;
            } else if (packet instanceof Message) {
                packetTypeIcon = messagePacketIcon;
                messageType = "Message Sent";
                type = ((Message) packet).getType().toString();
                sentMessagePackets++;
            } else if (packet instanceof Presence) {
                packetTypeIcon = presencePacketIcon;
                messageType = "Presence Sent";
                type = ((Presence) packet).getType().toString();
                sentPresencePackets++;
            } else {
                packetTypeIcon = unknownPacketTypeIcon;
                messageType = packet.getClass().getName() + " Sent";
                sentOtherPackets++;
            }
            // Check if we need to remove old rows from the table to keep memory consumption low
            if (EnhancedDebuggerWindow.MAX_TABLE_ROWS > 0 && messagesTable.getRowCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) {
                messagesTable.removeRow(0);
            }
            messagesTable.addRow(new Object[] { formatXML(packet.toXML().toString()), dateFormatter.format(new Date()), packetSentIcon, packetTypeIcon, messageType, packet.getStanzaId(), type, to, "" });
            // Update the statistics table
            updateStatistics();
        }
    });
}
Also used : Jid(org.jxmpp.jid.Jid) EntityFullJid(org.jxmpp.jid.EntityFullJid) Message(org.jivesoftware.smack.packet.Message) IQ(org.jivesoftware.smack.packet.IQ) Presence(org.jivesoftware.smack.packet.Presence) Icon(javax.swing.Icon) ImageIcon(javax.swing.ImageIcon) Date(java.util.Date)

Example 7 with Jid

use of org.jxmpp.jid.Jid in project Smack by igniterealtime.

the class Stanza method setFrom.

/**
     * Sets who the stanza(/packet) is being sent "from". The XMPP protocol often
     * makes the "from" attribute optional, so it does not always need to
     * be set.
     *
     * @param from who the stanza(/packet) is being sent to.
     * @throws IllegalArgumentException if from is not a valid JID String.
     * @deprecated use {@link #setFrom(Jid)} instead.
     */
@Deprecated
public void setFrom(String from) {
    Jid jid;
    try {
        jid = JidCreate.from(from);
    } catch (XmppStringprepException e) {
        throw new IllegalArgumentException(e);
    }
    setFrom(jid);
}
Also used : Jid(org.jxmpp.jid.Jid) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException)

Example 8 with Jid

use of org.jxmpp.jid.Jid in project Smack by igniterealtime.

the class OfferRequestProvider method parse.

// FIXME It seems because OfferRequestPacket is also defined here, we can
// not add it as generic to the provider, the provider and the packet should
// be split, but since this is legacy code, I don't think that this will
// happen anytime soon.
@Override
public OfferRequestPacket parse(XmlPullParser parser, int initialDepth) throws Exception {
    int eventType = parser.getEventType();
    String sessionID = null;
    int timeout = -1;
    OfferContent content = null;
    boolean done = false;
    Map<String, List<String>> metaData = new HashMap<String, List<String>>();
    if (eventType != XmlPullParser.START_TAG) {
    // throw exception
    }
    Jid userJID = ParserUtils.getJidAttribute(parser);
    // Default userID to the JID.
    Jid userID = userJID;
    while (!done) {
        eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            String elemName = parser.getName();
            if ("timeout".equals(elemName)) {
                timeout = Integer.parseInt(parser.nextText());
            } else if (MetaData.ELEMENT_NAME.equals(elemName)) {
                metaData = MetaDataUtils.parseMetaData(parser);
            } else if (SessionID.ELEMENT_NAME.equals(elemName)) {
                sessionID = parser.getAttributeValue("", "id");
            } else if (UserID.ELEMENT_NAME.equals(elemName)) {
                userID = ParserUtils.getJidAttribute(parser, "id");
            } else if ("user-request".equals(elemName)) {
                content = UserRequest.getInstance();
            } else if (RoomInvitation.ELEMENT_NAME.equals(elemName)) {
                RoomInvitation invitation = (RoomInvitation) PacketParserUtils.parseExtensionElement(RoomInvitation.ELEMENT_NAME, RoomInvitation.NAMESPACE, parser);
                content = new InvitationRequest(invitation.getInviter(), invitation.getRoom(), invitation.getReason());
            } else if (RoomTransfer.ELEMENT_NAME.equals(elemName)) {
                RoomTransfer transfer = (RoomTransfer) PacketParserUtils.parseExtensionElement(RoomTransfer.ELEMENT_NAME, RoomTransfer.NAMESPACE, parser);
                content = new TransferRequest(transfer.getInviter(), transfer.getRoom(), transfer.getReason());
            }
        } else if (eventType == XmlPullParser.END_TAG) {
            if ("offer".equals(parser.getName())) {
                done = true;
            }
        }
    }
    OfferRequestPacket offerRequest = new OfferRequestPacket(userJID, userID, timeout, metaData, sessionID, content);
    offerRequest.setType(IQ.Type.set);
    return offerRequest;
}
Also used : Jid(org.jxmpp.jid.Jid) HashMap(java.util.HashMap) InvitationRequest(org.jivesoftware.smackx.workgroup.agent.InvitationRequest) TransferRequest(org.jivesoftware.smackx.workgroup.agent.TransferRequest) OfferContent(org.jivesoftware.smackx.workgroup.agent.OfferContent) List(java.util.List)

Example 9 with Jid

use of org.jxmpp.jid.Jid in project Smack by igniterealtime.

the class OfferRevokeProvider method parse.

@Override
public OfferRevokePacket parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
    // The parser will be positioned on the opening IQ tag, so get the JID attribute.
    Jid userJID = ParserUtils.getJidAttribute(parser);
    // Default the userID to the JID.
    Jid userID = userJID;
    String reason = null;
    String sessionID = null;
    boolean done = false;
    while (!done) {
        int eventType = parser.next();
        if ((eventType == XmlPullParser.START_TAG) && parser.getName().equals("reason")) {
            reason = parser.nextText();
        } else if ((eventType == XmlPullParser.START_TAG) && parser.getName().equals(SessionID.ELEMENT_NAME)) {
            sessionID = parser.getAttributeValue("", "id");
        } else if ((eventType == XmlPullParser.START_TAG) && parser.getName().equals(UserID.ELEMENT_NAME)) {
            userID = ParserUtils.getJidAttribute(parser, "id");
        } else if ((eventType == XmlPullParser.END_TAG) && parser.getName().equals("offer-revoke")) {
            done = true;
        }
    }
    return new OfferRevokePacket(userJID, userID, reason, sessionID);
}
Also used : Jid(org.jxmpp.jid.Jid)

Example 10 with Jid

use of org.jxmpp.jid.Jid in project Smack by igniterealtime.

the class TranscriptsProvider method parse.

@Override
public Transcripts parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
    Jid userID = ParserUtils.getJidAttribute(parser, "userID");
    List<Transcripts.TranscriptSummary> summaries = new ArrayList<Transcripts.TranscriptSummary>();
    boolean done = false;
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("transcript")) {
                summaries.add(parseSummary(parser));
            }
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("transcripts")) {
                done = true;
            }
        }
    }
    return new Transcripts(userID, summaries);
}
Also used : Jid(org.jxmpp.jid.Jid) ArrayList(java.util.ArrayList)

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