use of org.jxmpp.jid.Jid in project Smack by igniterealtime.
the class BytestreamsProvider method parse.
@Override
public Bytestream parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
boolean done = false;
Bytestream toReturn = new Bytestream();
String id = parser.getAttributeValue("", "sid");
String mode = parser.getAttributeValue("", "mode");
// streamhost
Jid JID = null;
String host = null;
String port = null;
int eventType;
String elementName;
while (!done) {
eventType = parser.next();
elementName = parser.getName();
if (eventType == XmlPullParser.START_TAG) {
if (elementName.equals(Bytestream.StreamHost.ELEMENTNAME)) {
JID = ParserUtils.getJidAttribute(parser);
host = parser.getAttributeValue("", "host");
port = parser.getAttributeValue("", "port");
} else if (elementName.equals(Bytestream.StreamHostUsed.ELEMENTNAME)) {
toReturn.setUsedHost(ParserUtils.getJidAttribute(parser));
} else if (elementName.equals(Bytestream.Activate.ELEMENTNAME)) {
toReturn.setToActivate(ParserUtils.getJidAttribute(parser));
}
} else if (eventType == XmlPullParser.END_TAG) {
if (elementName.equals("streamhost")) {
if (port == null) {
toReturn.addStreamHost(JID, host);
} else {
toReturn.addStreamHost(JID, host, Integer.parseInt(port));
}
JID = null;
host = null;
port = null;
} else if (elementName.equals("query")) {
done = true;
}
}
}
if (mode == null) {
toReturn.setMode(Mode.tcp);
} else {
toReturn.setMode((Bytestream.Mode.fromName(mode)));
}
toReturn.setSessionID(id);
return toReturn;
}
use of org.jxmpp.jid.Jid in project Smack by igniterealtime.
the class DiscoverItemsProvider method parse.
@Override
public DiscoverItems parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
DiscoverItems discoverItems = new DiscoverItems();
boolean done = false;
DiscoverItems.Item item;
Jid jid = null;
String name = "";
String action = "";
String node = "";
discoverItems.setNode(parser.getAttributeValue("", "node"));
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG && "item".equals(parser.getName())) {
// Initialize the variables from the parsed XML
jid = ParserUtils.getJidAttribute(parser);
name = parser.getAttributeValue("", "name");
node = parser.getAttributeValue("", "node");
action = parser.getAttributeValue("", "action");
} else if (eventType == XmlPullParser.END_TAG && "item".equals(parser.getName())) {
// Create a new Item and add it to DiscoverItems.
item = new DiscoverItems.Item(jid);
item.setName(name);
item.setNode(node);
item.setAction(action);
discoverItems.addItem(item);
} else if (eventType == XmlPullParser.END_TAG && "query".equals(parser.getName())) {
done = true;
}
}
return discoverItems;
}
use of org.jxmpp.jid.Jid in project Smack by igniterealtime.
the class MultiUserChat method changeAffiliationByAdmin.
private void changeAffiliationByAdmin(Collection<? extends Jid> jids, MUCAffiliation affiliation) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCAdmin iq = new MUCAdmin();
iq.setTo(room);
iq.setType(IQ.Type.set);
for (Jid jid : jids) {
// Set the new affiliation.
MUCItem item = new MUCItem(affiliation, jid);
iq.addItem(item);
}
connection.createStanzaCollectorAndSend(iq).nextResultOrThrow();
}
use of org.jxmpp.jid.Jid in project Smack by igniterealtime.
the class UnblockContactsIQ method getIQChildElementBuilder.
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
if (jids == null) {
xml.setEmptyElement();
return xml;
}
xml.rightAngleBracket();
for (Jid jid : jids) {
xml.halfOpenElement("item");
xml.attribute("jid", jid);
xml.closeEmptyElement();
}
return xml;
}
use of org.jxmpp.jid.Jid in project Smack by igniterealtime.
the class EnhancedDebugger method addReadPacketToTable.
/**
* Adds the received stanza(/packet) detail to the messages table.
*
* @param dateFormatter the SimpleDateFormat to use to format Dates
* @param packet the read stanza(/packet) to add to the table
*/
private void addReadPacketToTable(final SimpleDateFormat dateFormatter, final Stanza packet) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
String messageType;
Jid from = packet.getFrom();
String type = "";
Icon packetTypeIcon;
receivedPackets++;
if (packet instanceof IQ) {
packetTypeIcon = iqPacketIcon;
messageType = "IQ Received (class=" + packet.getClass().getName() + ")";
type = ((IQ) packet).getType().toString();
receivedIQPackets++;
} else if (packet instanceof Message) {
packetTypeIcon = messagePacketIcon;
messageType = "Message Received";
type = ((Message) packet).getType().toString();
receivedMessagePackets++;
} else if (packet instanceof Presence) {
packetTypeIcon = presencePacketIcon;
messageType = "Presence Received";
type = ((Presence) packet).getType().toString();
receivedPresencePackets++;
} else {
packetTypeIcon = unknownPacketTypeIcon;
messageType = packet.getClass().getName() + " Received";
receivedOtherPackets++;
}
// 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()), packetReceivedIcon, packetTypeIcon, messageType, packet.getStanzaId(), type, "", from });
// Update the statistics table
updateStatistics();
}
});
}
Aggregations