From 779f6ab82f2dcdfb8397d0e01ca862076daf285f Mon Sep 17 00:00:00 2001 From: Matt Tucker Date: Sun, 24 Aug 2003 14:20:44 +0000 Subject: [PATCH] Support for getting and setting private data for other users. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2064 b35dd754-fafc-0310-a699-88a17e54d16e --- .../smackx/PrivateDataManager.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/source/org/jivesoftware/smackx/PrivateDataManager.java b/source/org/jivesoftware/smackx/PrivateDataManager.java index 765337a39..64bd4e054 100644 --- a/source/org/jivesoftware/smackx/PrivateDataManager.java +++ b/source/org/jivesoftware/smackx/PrivateDataManager.java @@ -134,6 +134,13 @@ public class PrivateDataManager { private XMPPConnection connection; + /** + * The user to get and set private data for. In most cases, this value should + * be null, as the typical use of private data is to get and set + * your own private data and not others. + */ + private String user; + /** * Creates a new private data manager. The connection must have * undergone a successful login before being used to construct an instance of @@ -149,6 +156,26 @@ public class PrivateDataManager { this.connection = connection; } + /** + * Creates a new private data manager for a specific user (special case). Most + * servers only support getting and setting private data for the user that + * authenticated via the connection. However, some servers support the ability + * to get and set private data for other users (for example, if you are the + * administrator). The connection must have undergone a successful login before + * being used to construct an instance of this class. + * + * @param connection an XMPP connection which must have already undergone a + * successful login. + * @param user the XMPP address of the user to get and set private data for. + */ + public PrivateDataManager(XMPPConnection connection, String user) { + if (!connection.isAuthenticated()) { + throw new IllegalStateException("Must be logged in to XMPP server."); + } + this.connection = connection; + this.user = user; + } + /** * Returns the private data specified by the given element name and namespace. Each chunk * of private data is uniquely identified by an element name and namespace pair.

@@ -176,6 +203,10 @@ public class PrivateDataManager { } }; privateDataGet.setType(IQ.Type.GET); + // Address the packet to the other account if user has been set. + if (user != null) { + privateDataGet.setTo(user); + } // Setup a listener for the reply to the set operation. String packetID = privateDataGet.getPacketID(); @@ -216,6 +247,10 @@ public class PrivateDataManager { } }; privateDataSet.setType(IQ.Type.SET); + // Address the packet to the other account if user has been set. + if (user != null) { + privateDataSet.setTo(user); + } // Setup a listener for the reply to the set operation. String packetID = privateDataSet.getPacketID();