2013-03-31 16:24:50 +02:00
|
|
|
/**
|
2013-03-18 09:50:48 +01:00
|
|
|
*
|
2019-02-05 10:41:50 +01:00
|
|
|
* Copyright © 2009 Jonas Ådahl, 2011-2019 Florian Schmaus
|
2014-02-17 18:57:38 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2013-03-18 09:50:48 +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.
|
|
|
|
*/
|
2014-02-18 10:24:59 +01:00
|
|
|
package org.jivesoftware.smackx.caps.provider;
|
2013-03-18 09:50:48 +01:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
2019-02-15 23:21:30 +01:00
|
|
|
import org.jivesoftware.smack.packet.XmlEnvironment;
|
2015-02-26 18:41:17 +01:00
|
|
|
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
2019-05-06 22:06:13 +02:00
|
|
|
import org.jivesoftware.smack.xml.XmlPullParser;
|
|
|
|
import org.jivesoftware.smack.xml.XmlPullParserException;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2014-02-18 10:24:59 +01:00
|
|
|
import org.jivesoftware.smackx.caps.EntityCapsManager;
|
2014-09-11 23:58:07 +02:00
|
|
|
import org.jivesoftware.smackx.caps.packet.CapsExtension;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2015-02-26 18:41:17 +01:00
|
|
|
public class CapsExtensionProvider extends ExtensionElementProvider<CapsExtension> {
|
2013-03-18 09:50:48 +01:00
|
|
|
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2019-02-15 23:21:30 +01:00
|
|
|
public CapsExtension parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
|
2017-12-13 23:10:11 +01:00
|
|
|
String hash, version, node;
|
2019-05-06 22:06:13 +02:00
|
|
|
if (parser.getEventType() == XmlPullParser.Event.START_ELEMENT
|
2013-03-18 09:50:48 +01:00
|
|
|
&& parser.getName().equalsIgnoreCase(EntityCapsManager.ELEMENT)) {
|
|
|
|
hash = parser.getAttributeValue(null, "hash");
|
|
|
|
version = parser.getAttributeValue(null, "ver");
|
|
|
|
node = parser.getAttributeValue(null, "node");
|
|
|
|
} else {
|
2019-02-05 10:41:50 +01:00
|
|
|
// TODO: Should be SmackParsingException.
|
|
|
|
throw new IOException("Malformed Caps element");
|
2013-03-18 09:50:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
parser.next();
|
|
|
|
|
2019-05-06 22:06:13 +02:00
|
|
|
if (!(parser.getEventType() == XmlPullParser.Event.END_ELEMENT
|
2013-03-18 09:50:48 +01:00
|
|
|
&& parser.getName().equalsIgnoreCase(EntityCapsManager.ELEMENT))) {
|
2019-02-05 10:41:50 +01:00
|
|
|
// TODO: Should be SmackParsingException.
|
|
|
|
throw new IOException("Malformed nested Caps element");
|
2013-03-18 09:50:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hash != null && version != null && node != null) {
|
|
|
|
return new CapsExtension(node, version, hash);
|
|
|
|
} else {
|
2019-02-05 10:41:50 +01:00
|
|
|
// TODO: Should be SmackParsingException.
|
|
|
|
throw new IOException("Caps element with missing attributes. Attributes: hash=" + hash + " version="
|
2015-05-07 22:40:38 +02:00
|
|
|
+ version + " node=" + node);
|
2013-03-18 09:50:48 +01:00
|
|
|
}
|
|
|
|
}
|
2014-09-11 23:58:07 +02:00
|
|
|
|
2013-03-18 09:50:48 +01:00
|
|
|
}
|