1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-10 02:39:42 +02:00

Add support for XEP-0059: Result Set Management

SMACK-581
This commit is contained in:
Florian Schmaus 2014-09-13 11:03:40 +02:00
parent d3cea48c0d
commit 2dc93d7639
11 changed files with 407 additions and 10 deletions

View file

@ -17,6 +17,7 @@
package org.jivesoftware.smack.packet;
import org.jivesoftware.smack.util.PacketUtil;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.XmlStringBuilder;
@ -232,19 +233,11 @@ public abstract class Packet extends TopLevelStreamElement {
* @param namespace the XML element namespace of the packet extension.
* @return the extension, or <tt>null</tt> if it doesn't exist.
*/
@SuppressWarnings("unchecked")
public <PE extends PacketExtension> PE getExtension(String elementName, String namespace) {
if (namespace == null) {
return null;
}
for (PacketExtension ext : packetExtensions) {
if ((elementName == null || elementName.equals(ext.getElementName()))
&& namespace.equals(ext.getNamespace()))
{
return (PE) ext;
}
}
return null;
return PacketUtil.packetExtensionfromCollection(packetExtensions, elementName, namespace);
}
/**

View file

@ -0,0 +1,38 @@
/**
*
* Copyright © 2014 Florian Schmaus
*
* 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
*
* 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.
*/
package org.jivesoftware.smack.util;
import java.util.Collection;
import org.jivesoftware.smack.packet.PacketExtension;
public class PacketUtil {
@SuppressWarnings("unchecked")
public static <PE extends PacketExtension> PE packetExtensionfromCollection(
Collection<PacketExtension> collection, String element,
String namespace) {
for (PacketExtension packetExtension : collection) {
if ((element == null || packetExtension.getElementName().equals(
element))
&& packetExtension.getNamespace().equals(namespace)) {
return (PE) packetExtension;
}
}
return null;
}
}

View file

@ -16,6 +16,7 @@
*/
package org.jivesoftware.smack.util;
import java.io.IOException;
import java.util.Locale;
import org.xmlpull.v1.XmlPullParser;
@ -77,6 +78,11 @@ public class ParserUtils {
}
}
public static int getIntegerFromNextText(XmlPullParser parser) throws XmlPullParserException, IOException {
String intString = parser.nextText();
return Integer.valueOf(intString);
}
public static Long getLongAttribute(XmlPullParser parser, String name) {
String valueString = parser.getAttributeValue("", name);
if (valueString == null)

View file

@ -86,6 +86,13 @@ public class XmlStringBuilder implements Appendable, CharSequence {
return this;
}
public XmlStringBuilder optIntElement(String name, int value) {
if (value >= 0) {
element(name, String.valueOf(value));
}
return this;
}
public XmlStringBuilder halfOpenElement(String name) {
sb.append('<').append(name);
return this;