2003-10-14 01:05:06 +02:00
|
|
|
/**
|
2004-11-03 00:37:00 +01:00
|
|
|
*
|
2007-02-12 01:59:05 +01:00
|
|
|
* Copyright 2003-2007 Jive Software.
|
2004-11-03 00:37:00 +01:00
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2004-11-03 00:37:00 +01:00
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* 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-10-14 01:05:06 +02:00
|
|
|
|
2014-02-15 11:35:08 +01:00
|
|
|
package org.jivesoftware.smackx.disco.provider;
|
2003-10-14 01:05:06 +02:00
|
|
|
|
|
|
|
import org.jivesoftware.smack.provider.IQProvider;
|
2004-09-19 18:20:10 +02:00
|
|
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2014-02-15 11:35:08 +01:00
|
|
|
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2003-10-14 01:05:06 +02:00
|
|
|
import org.xmlpull.v1.XmlPullParser;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The DiscoverInfoProvider parses Service Discovery information packets.
|
|
|
|
*
|
|
|
|
* @author Gaston Dombiak
|
|
|
|
*/
|
2014-10-07 21:15:20 +02:00
|
|
|
public class DiscoverInfoProvider extends IQProvider<DiscoverInfo> {
|
2003-10-14 01:05:06 +02:00
|
|
|
|
2014-10-07 21:15:20 +02:00
|
|
|
@Override
|
|
|
|
public DiscoverInfo parse(XmlPullParser parser, int initialDepth)
|
2015-03-13 09:27:18 +01:00
|
|
|
throws Exception {
|
2003-10-14 01:05:06 +02:00
|
|
|
DiscoverInfo discoverInfo = new DiscoverInfo();
|
|
|
|
boolean done = false;
|
2017-12-13 23:10:11 +01:00
|
|
|
DiscoverInfo.Identity identity;
|
2003-10-14 01:05:06 +02:00
|
|
|
String category = "";
|
2016-06-03 10:54:18 +02:00
|
|
|
String identityName = "";
|
2003-10-14 01:05:06 +02:00
|
|
|
String type = "";
|
|
|
|
String variable = "";
|
2013-03-18 09:50:48 +01:00
|
|
|
String lang = "";
|
2003-10-14 01:05:06 +02:00
|
|
|
discoverInfo.setNode(parser.getAttributeValue("", "node"));
|
|
|
|
while (!done) {
|
|
|
|
int eventType = parser.next();
|
|
|
|
if (eventType == XmlPullParser.START_TAG) {
|
2016-06-03 10:54:18 +02:00
|
|
|
final String name = parser.getName();
|
|
|
|
final String namespace = parser.getNamespace();
|
|
|
|
if (namespace.equals(DiscoverInfo.NAMESPACE)) {
|
|
|
|
switch (name) {
|
|
|
|
case "identity":
|
|
|
|
// Initialize the variables from the parsed XML
|
|
|
|
category = parser.getAttributeValue("", "category");
|
|
|
|
identityName = parser.getAttributeValue("", "name");
|
|
|
|
type = parser.getAttributeValue("", "type");
|
|
|
|
lang = parser.getAttributeValue(parser.getNamespace("xml"), "lang");
|
|
|
|
break;
|
|
|
|
case "feature":
|
|
|
|
// Initialize the variables from the parsed XML
|
|
|
|
variable = parser.getAttributeValue("", "var");
|
|
|
|
break;
|
|
|
|
}
|
2003-10-14 01:05:06 +02:00
|
|
|
}
|
2004-09-19 18:20:10 +02:00
|
|
|
// Otherwise, it must be a packet extension.
|
|
|
|
else {
|
2015-02-26 18:41:17 +01:00
|
|
|
PacketParserUtils.addExtensionElement(discoverInfo, parser);
|
2004-09-19 18:20:10 +02:00
|
|
|
}
|
2003-10-14 01:05:06 +02:00
|
|
|
} else if (eventType == XmlPullParser.END_TAG) {
|
|
|
|
if (parser.getName().equals("identity")) {
|
|
|
|
// Create a new identity and add it to the discovered info.
|
2016-06-03 10:54:18 +02:00
|
|
|
identity = new DiscoverInfo.Identity(category, type, identityName, lang);
|
2003-10-14 01:05:06 +02:00
|
|
|
discoverInfo.addIdentity(identity);
|
|
|
|
}
|
|
|
|
if (parser.getName().equals("feature")) {
|
|
|
|
// Create a new feature and add it to the discovered info.
|
2014-10-31 22:22:22 +01:00
|
|
|
boolean notADuplicateFeature = discoverInfo.addFeature(variable);
|
2017-05-23 16:45:04 +02:00
|
|
|
assert (notADuplicateFeature);
|
2003-10-14 01:05:06 +02:00
|
|
|
}
|
|
|
|
if (parser.getName().equals("query")) {
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return discoverInfo;
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|