Class PrivateDataManager

java.lang.Object
org.jivesoftware.smack.Manager
org.jivesoftware.smackx.iqprivate.PrivateDataManager

public final class PrivateDataManager extends org.jivesoftware.smack.Manager
Manages private data, which is a mechanism to allow users to store arbitrary XML data on an XMPP server. Each private data chunk is defined by a element name and XML namespace. Example private data:
 <color xmlns="http://example.com/xmpp/color">
     <favorite>blue</blue>
     <leastFavorite>puce</leastFavorite>
 </color>
 
PrivateDataProvider instances are responsible for translating the XML into objects. If no PrivateDataProvider is registered for a given element name and namespace, then a DefaultPrivateData instance will be returned.

Warning: this is an non-standard protocol documented by XEP-49. Because this is a non-standard protocol, it is subject to change.

  • Method Details

    • getInstanceFor

      public static PrivateDataManager getInstanceFor(org.jivesoftware.smack.XMPPConnection connection)
    • getPrivateDataProvider

      public static PrivateDataProvider getPrivateDataProvider(String elementName, String namespace)
      Returns the private data provider registered to the specified XML element name and namespace. For example, if a provider was registered to the element name "prefs" and the namespace "http://www.xmppclient.com/prefs", then the following stanza would trigger the provider:
       <iq type='result' to='joe@example.com' from='mary@example.com' id='time_1'>
           <query xmlns='jabber:iq:private'>
               <prefs xmlns='http://www.xmppclient.com/prefs'>
                   <value1>ABC</value1>
                   <value2>XYZ</value2>
               </prefs>
           </query>
       </iq>

      Note: this method is generally only called by the internal Smack classes.

      Parameters:
      elementName - the XML element name.
      namespace - the XML namespace.
      Returns:
      the PrivateData provider.
    • addPrivateDataProvider

      public static void addPrivateDataProvider(String elementName, String namespace, PrivateDataProvider provider)
      Adds a private data provider with the specified element name and name space. The provider will override any providers loaded through the classpath.
      Parameters:
      elementName - the XML element name.
      namespace - the XML namespace.
      provider - the private data provider.
    • removePrivateDataProvider

      public static void removePrivateDataProvider(String elementName, String namespace)
      Removes a private data provider with the specified element name and namespace.
      Parameters:
      elementName - The XML element name.
      namespace - The XML namespace.
    • getPrivateData

      public PrivateData getPrivateData(String elementName, String namespace) throws org.jivesoftware.smack.SmackException.NoResponseException, org.jivesoftware.smack.XMPPException.XMPPErrorException, org.jivesoftware.smack.SmackException.NotConnectedException, InterruptedException
      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.

      If a PrivateDataProvider is registered for the specified element name/namespace pair then that provider will determine the specific object type that is returned. If no provider is registered, a DefaultPrivateData instance will be returned.

      Parameters:
      elementName - the element name.
      namespace - the namespace.
      Returns:
      the private data.
      Throws:
      org.jivesoftware.smack.XMPPException.XMPPErrorException - if there was an XMPP error returned.
      org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the remote entity.
      org.jivesoftware.smack.SmackException.NotConnectedException - if the XMPP connection is not connected.
      InterruptedException - if the calling thread was interrupted.
    • setPrivateData

      public void setPrivateData(PrivateData privateData) throws org.jivesoftware.smack.SmackException.NoResponseException, org.jivesoftware.smack.XMPPException.XMPPErrorException, org.jivesoftware.smack.SmackException.NotConnectedException, InterruptedException
      Sets a private data value. Each chunk of private data is uniquely identified by an element name and namespace pair. If private data has already been set with the element name and namespace, then the new private data will overwrite the old value.
      Parameters:
      privateData - the private data.
      Throws:
      org.jivesoftware.smack.XMPPException.XMPPErrorException - if there was an XMPP error returned.
      org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the remote entity.
      org.jivesoftware.smack.SmackException.NotConnectedException - if the XMPP connection is not connected.
      InterruptedException - if the calling thread was interrupted.
    • isSupported

      public boolean isSupported() throws org.jivesoftware.smack.SmackException.NoResponseException, org.jivesoftware.smack.SmackException.NotConnectedException, InterruptedException, org.jivesoftware.smack.XMPPException.XMPPErrorException
      Check if the service supports private data.
      Returns:
      true if the service supports private data, false otherwise.
      Throws:
      org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the remote entity.
      org.jivesoftware.smack.SmackException.NotConnectedException - if the XMPP connection is not connected.
      InterruptedException - if the calling thread was interrupted.
      org.jivesoftware.smack.XMPPException.XMPPErrorException - if there was an XMPP error returned.
      Since:
      4.2