1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-26 16:22:06 +01:00

Fixes for private data support.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2006 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Matt Tucker 2003-08-04 21:05:44 +00:00 committed by mtucker
parent b8602b80c0
commit 665825b656
3 changed files with 23 additions and 6 deletions

View file

@ -68,6 +68,7 @@ import java.util.Map;
import java.util.Hashtable; import java.util.Hashtable;
/** /**
* Manages private data.
* *
* @author Matt Tucker * @author Matt Tucker
*/ */
@ -145,7 +146,9 @@ public class PrivateDataManager {
IQ privateDataGet = new IQ() { IQ privateDataGet = new IQ() {
public String getChildElementXML() { public String getChildElementXML() {
StringBuffer buf = new StringBuffer(); StringBuffer buf = new StringBuffer();
buf.append("<query xmlns=\"jabber:iq:private\">");
buf.append("<").append(elementName).append(" xmlns=\"").append(namespace).append("\"/>"); buf.append("<").append(elementName).append(" xmlns=\"").append(namespace).append("\"/>");
buf.append("</query>");
return buf.toString(); return buf.toString();
} }
}; };
@ -174,7 +177,11 @@ public class PrivateDataManager {
// Create an IQ packet to set the private data. // Create an IQ packet to set the private data.
IQ privateDataSet = new IQ() { IQ privateDataSet = new IQ() {
public String getChildElementXML() { public String getChildElementXML() {
return privateData.toXML(); StringBuffer buf = new StringBuffer();
buf.append("<query xmlns=\"jabber:iq:private\">");
buf.append(privateData.toXML());
buf.append("</query>");
return buf.toString();
} }
}; };
privateDataSet.setType(IQ.Type.SET); privateDataSet.setType(IQ.Type.SET);
@ -215,7 +222,7 @@ public class PrivateDataManager {
*/ */
public static class PrivateDataIQProvider implements IQProvider { public static class PrivateDataIQProvider implements IQProvider {
public IQ parseIQ(XmlPullParser parser) throws Exception { public IQ parseIQ(XmlPullParser parser) throws Exception {
PrivateData privateData = null;; PrivateData privateData = null;
boolean done = false; boolean done = false;
while (!done) { while (!done) {
int eventType = parser.next(); int eventType = parser.next();
@ -266,12 +273,13 @@ public class PrivateDataManager {
} }
} }
else if (eventType == XmlPullParser.END_TAG) { else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("</query>")) { if (parser.getName().equals("query")) {
done = true; done = true;
} }
} }
} }
return new PrivateDataResult(privateData); IQ result = new PrivateDataResult(privateData);
return result;
} }
} }
@ -352,7 +360,13 @@ public class PrivateDataManager {
} }
public String getChildElementXML() { public String getChildElementXML() {
return privateData.toXML(); StringBuffer buf = new StringBuffer();
buf.append("<query xmlns=\"jabber:iq:private\">");
if (privateData != null) {
privateData.toXML();
}
buf.append("</query>");
return buf.toString();
} }
} }
} }

View file

@ -53,7 +53,7 @@
package org.jivesoftware.smackx.packet; package org.jivesoftware.smackx.packet;
/** /**
* Interface to represent private data. Each private data chunk is an XML subdocument * Interface to represent private data. Each private data chunk is an XML sub-document
* with a root element name and namespace. * with a root element name and namespace.
* *
* @see org.jivesoftware.smackx.PrivateDataManager * @see org.jivesoftware.smackx.PrivateDataManager

View file

@ -56,6 +56,9 @@ import org.xmlpull.v1.XmlPullParser;
import org.jivesoftware.smackx.packet.PrivateData; import org.jivesoftware.smackx.packet.PrivateData;
/** /**
* An interface for parsing custom private data. Each PrivateDataProvider must
* be registered with the PrivateDataManager class for it to be used. Every implementation
* of this interface <b>must</b> have a public, no-argument constructor.
* *
* @author Matt Tucker * @author Matt Tucker
*/ */