2003-08-18 22:21:00 +02:00
|
|
|
/**
|
|
|
|
*
|
2007-02-12 01:59:05 +01:00
|
|
|
* Copyright 2003-2007 Jive Software.
|
2003-08-18 22:21:00 +02:00
|
|
|
*
|
2004-11-03 00:37:00 +01:00
|
|
|
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2003-08-18 22:21:00 +02:00
|
|
|
*
|
2004-11-03 00:37:00 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2003-08-18 22:21:00 +02:00
|
|
|
*
|
2004-11-03 00:37:00 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2003-08-02 20:46:55 +02:00
|
|
|
*/
|
2003-08-18 22:21:00 +02:00
|
|
|
|
2003-08-02 20:46:55 +02:00
|
|
|
package org.jivesoftware.smackx.provider;
|
|
|
|
|
2003-08-26 18:05:57 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2003-08-02 20:46:55 +02:00
|
|
|
import org.jivesoftware.smack.packet.PacketExtension;
|
|
|
|
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
2003-08-26 18:05:57 +02:00
|
|
|
import org.jivesoftware.smackx.*;
|
2003-08-02 20:46:55 +02:00
|
|
|
import org.jivesoftware.smackx.packet.*;
|
|
|
|
import org.xmlpull.v1.XmlPullParser;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* The RosterExchangeProvider parses RosterExchange packets.
|
|
|
|
*
|
|
|
|
* @author Gaston Dombiak
|
|
|
|
*/
|
|
|
|
public class RosterExchangeProvider implements PacketExtensionProvider {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new RosterExchangeProvider.
|
|
|
|
* ProviderManager requires that every PacketExtensionProvider has a public, no-argument constructor
|
|
|
|
*/
|
|
|
|
public RosterExchangeProvider() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses a RosterExchange packet (extension sub-packet).
|
|
|
|
*
|
|
|
|
* @param parser the XML parser, positioned at the starting element of the extension.
|
|
|
|
* @return a PacketExtension.
|
|
|
|
* @throws Exception if a parsing error occurs.
|
|
|
|
*/
|
2003-08-18 22:21:00 +02:00
|
|
|
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
|
2003-08-02 20:46:55 +02:00
|
|
|
|
|
|
|
RosterExchange rosterExchange = new RosterExchange();
|
|
|
|
boolean done = false;
|
2003-08-24 18:05:45 +02:00
|
|
|
RemoteRosterEntry remoteRosterEntry = null;
|
2003-08-26 18:05:57 +02:00
|
|
|
String jid = "";
|
|
|
|
String name = "";
|
2012-10-26 12:47:55 +02:00
|
|
|
ArrayList<String> groupsName = new ArrayList<String>();
|
2003-08-02 20:46:55 +02:00
|
|
|
while (!done) {
|
|
|
|
int eventType = parser.next();
|
|
|
|
if (eventType == XmlPullParser.START_TAG) {
|
|
|
|
if (parser.getName().equals("item")) {
|
2003-08-26 18:05:57 +02:00
|
|
|
// Reset this variable since they are optional for each item
|
2012-10-26 12:47:55 +02:00
|
|
|
groupsName = new ArrayList<String>();
|
2003-08-26 18:05:57 +02:00
|
|
|
// Initialize the variables from the parsed XML
|
|
|
|
jid = parser.getAttributeValue("", "jid");
|
|
|
|
name = parser.getAttributeValue("", "name");
|
2003-08-02 20:46:55 +02:00
|
|
|
}
|
|
|
|
if (parser.getName().equals("group")) {
|
2003-08-26 18:05:57 +02:00
|
|
|
groupsName.add(parser.nextText());
|
2003-08-02 20:46:55 +02:00
|
|
|
}
|
|
|
|
} else if (eventType == XmlPullParser.END_TAG) {
|
|
|
|
if (parser.getName().equals("item")) {
|
2003-08-26 18:05:57 +02:00
|
|
|
// Create packet.
|
|
|
|
remoteRosterEntry = new RemoteRosterEntry(jid, name, (String[]) groupsName.toArray(new String[groupsName.size()]));
|
2003-08-24 18:05:45 +02:00
|
|
|
rosterExchange.addRosterEntry(remoteRosterEntry);
|
2003-08-02 20:46:55 +02:00
|
|
|
}
|
|
|
|
if (parser.getName().equals("x")) {
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rosterExchange;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|