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();
}
});
}
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);
}
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;
}
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);
}
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);
}
Aggregations