Search in sources :

Example 1 with VCardProvider

use of org.jivesoftware.smackx.vcardtemp.provider.VCardProvider in project Zom-Android by zom.

the class XmppConnection method addProviderManagerExtensions.

public static void addProviderManagerExtensions() {
    ProviderManager.addIQProvider("query", "jabber:iq:private", new PrivateDataManager.PrivateDataIQProvider());
    ProviderManager.addIQProvider("query", "http://jabber.org/protocol/bytestreams", new BytestreamsProvider());
    ProviderManager.addIQProvider("query", "http://jabber.org/protocol/disco#items", new DiscoverItemsProvider());
    ProviderManager.addIQProvider("query", "http://jabber.org/protocol/disco#info", new DiscoverInfoProvider());
    // Time
    try {
        ProviderManager.addIQProvider("query", "jabber:iq:time", Class.forName("org.jivesoftware.smackx.packet.Time"));
    } catch (ClassNotFoundException e) {
        Log.w("TestClient", "Can't load class for org.jivesoftware.smackx.packet.Time");
    }
    // Pings
    ProviderManager.addIQProvider("ping", "urn:xmpp:ping", new PingProvider());
    // Roster Exchange
    // providerManager.addExtensionProvider("x", "jabber:x:roster", new RosterExchangeProvider());
    ProviderManager.addIQProvider("vCard", "vcard-temp", new VCardProvider());
    // Message Events
    // providerManager.addExtensionProvider("x", "jabber:x:event",
    // new MessageEventProvider());
    // XHTML
    ProviderManager.addExtensionProvider("html", "http://jabber.org/protocol/xhtml-im", new XHTMLExtensionProvider());
    // Group Chat Invitations
    ProviderManager.addExtensionProvider("x", "jabber:x:conference", new GroupChatInvitation.Provider());
    // Service Discovery # Items
    ProviderManager.addIQProvider("query", "http://jabber.org/protocol/disco#items", new DiscoverItemsProvider());
    // Service Discovery # Info
    ProviderManager.addIQProvider("query", "http://jabber.org/protocol/disco#info", new DiscoverInfoProvider());
    // Data Forms
    ProviderManager.addExtensionProvider("x", "jabber:x:data", new DataFormProvider());
    // MUC User
    ProviderManager.addExtensionProvider("x", "http://jabber.org/protocol/muc#user", new MUCUserProvider());
    // MUC Admin
    ProviderManager.addIQProvider("query", "http://jabber.org/protocol/muc#admin", new MUCAdminProvider());
    // MUC Owner
    ProviderManager.addIQProvider("query", "http://jabber.org/protocol/muc#owner", new MUCOwnerProvider());
    // Version
    try {
        ProviderManager.addIQProvider("query", "jabber:iq:version", Class.forName("org.jivesoftware.smackx.packet.Version"));
    } catch (ClassNotFoundException e) {
    // Not sure what's happening here.
    }
    // VCard
    ProviderManager.addIQProvider("vCard", "vcard-temp", new VCardProvider());
    // Offline Message Requests
    ProviderManager.addIQProvider("offline", "http://jabber.org/protocol/offline", new OfflineMessageRequest.Provider());
    // Offline Message Indicator
    ProviderManager.addExtensionProvider("offline", "http://jabber.org/protocol/offline", new OfflineMessageInfo.Provider());
    // Last Activity
    ProviderManager.addIQProvider("query", "jabber:iq:last", new LastActivity.Provider());
    // User Search
    ProviderManager.addIQProvider("query", "jabber:iq:search", new UserSearch.Provider());
    // SharedGroupsInfo
    ProviderManager.addIQProvider("sharedgroup", "http://www.jivesoftware.org/protocol/sharedgroup", new SharedGroupsInfo.Provider());
    // JEP-33: Extended Stanza Addressing
    ProviderManager.addExtensionProvider("addresses", "http://jabber.org/protocol/address", new MultipleAddressesProvider());
    // FileTransfer
    ProviderManager.addIQProvider("si", "http://jabber.org/protocol/si", new StreamInitiationProvider());
    // Privacy
    ProviderManager.addIQProvider("query", "jabber:iq:privacy", new PrivacyProvider());
    ProviderManager.addIQProvider("command", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider());
    ProviderManager.addExtensionProvider("malformed-action", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.MalformedActionError());
    ProviderManager.addExtensionProvider("bad-locale", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadLocaleError());
    ProviderManager.addExtensionProvider("bad-payload", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadPayloadError());
    ProviderManager.addExtensionProvider("bad-sessionid", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadSessionIDError());
    ProviderManager.addExtensionProvider("session-expired", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.SessionExpiredError());
    ProviderManager.addIQProvider("offline", "http://jabber.org/protocol/offline", new OfflineMessageRequest.Provider());
    // Offline Message Indicator
    ProviderManager.addExtensionProvider("offline", "http://jabber.org/protocol/offline", new OfflineMessageInfo.Provider());
    ProviderManager.addIQProvider("query", "http://jabber.org/protocol/disco#info", new DiscoverInfoProvider());
    ProviderManager.addExtensionProvider("x", "jabber:x:data", new DataFormProvider());
    // pm.addExtensionProvider("status ","", new XMLPlayerList());
    ProviderManager.addIQProvider("query", "http://jabber.org/protocol/bytestreams", new BytestreamsProvider());
    ProviderManager.addIQProvider("query", "http://jabber.org/protocol/disco#items", new DiscoverItemsProvider());
    ProviderManager.addIQProvider("query", "http://jabber.org/protocol/disco#info", new DiscoverInfoProvider());
    // Private Data Storage
    // ProviderManager.addIQProvider("query","jabber:iq:private", new PrivateDataManager.PrivateDataIQProvider());
    // Time
    /**
     *        try {
     *            ProviderManager.addIQProvider("query","jabber:iq:time", Class.forName("org.jivesoftware.smackx.packet.Time"));
     *        } catch (ClassNotFoundException e) {
     *            Log.w("TestClient", "Can't load class for org.jivesoftware.smackx.packet.Time");
     *        }
     */
    // Roster Exchange
    // ProviderManager.addExtensionProvider("x","jabber:x:roster", new RosterExchangeProvider());
    // Message Events
    // ProviderManager.addExtensionProvider("x","jabber:x:event", new MessageEventProvider());
    // Chat State
    ChatStateExtensionProvider csep = new ChatStateExtensionProvider();
    ProviderManager.addExtensionProvider("active", "http://jabber.org/protocol/chatstates", csep);
    ProviderManager.addExtensionProvider("composing", "http://jabber.org/protocol/chatstates", csep);
    ProviderManager.addExtensionProvider("paused", "http://jabber.org/protocol/chatstates", csep);
    ProviderManager.addExtensionProvider("inactive", "http://jabber.org/protocol/chatstates", csep);
    ProviderManager.addExtensionProvider("gone", "http://jabber.org/protocol/chatstates", csep);
// XHTML
// ProviderManager.addExtensionProvider("html","http://jabber.org/protocol/xhtml-im", new XHTMLExtensionProvider());
// Group Chat Invitations
// ProviderManager.addExtensionProvider("x","jabber:x:conference", new GroupChatInvitation.Provider());
// Service Discovery # Items
// ProviderManager.addIQProvider("query","http://jabber.org/protocol/disco#items", new DiscoverItemsProvider());
// Service Discovery # Info
// ProviderManager.addIQProvider("query","http://jabber.org/protocol/disco#info", new DiscoverInfoProvider());
// Data Forms
// ProviderManager.addExtensionProvider("x","jabber:x:data", new DataFormProvider());
// MUC User
// ProviderManager.addExtensionProvider("x","http://jabber.org/protocol/muc#user", new MUCUserProvider());
// MUC Admin
// ProviderManager.addIQProvider("query","http://jabber.org/protocol/muc#admin", new MUCAdminProvider());
// MUC Owner
// ProviderManager.addIQProvider("query","http://jabber.org/protocol/muc#owner", new MUCOwnerProvider());
// Delayed Delivery
// ProviderManager.addExtensionProvider("x","jabber:x:delay", new DelayInformationProvider());
// Version
/**
 *        try {
 *            ProviderManager.addIQProvider("query","jabber:iq:version", Class.forName("org.jivesoftware.smackx.packet.Version"));
 *        } catch (ClassNotFoundException err) {
 *            //  Not sure what's happening here.
 *        }
 */
// VCard
// ProviderManager.addIQProvider("vCard","vcard-temp", new VCardProvider());
// Offline Message Requests
// ProviderManager.addIQProvider("offline","http://jabber.org/protocol/offline", new OfflineMessageRequest.Provider());
// Offline Message Indicator
// ProviderManager.addExtensionProvider("offline","http://jabber.org/protocol/offline", new OfflineMessageInfo.Provider());
// Last Activity
// ProviderManager.addIQProvider("query","jabber:iq:last", new LastActivity.Provider());
// User Search
// ProviderManager.addIQProvider("query","jabber:iq:search", new UserSearch.Provider());
// SharedGroupsInfo
// ProviderManager.addIQProvider("sharedgroup","http://www.jivesoftware.org/protocol/sharedgroup", new SharedGroupsInfo.Provider());
// JEP-33: Extended Stanza Addressing
// ProviderManager.addExtensionProvider("addresses","http://jabber.org/protocol/address", new MultipleAddressesProvider());
// FileTransfer
// ProviderManager.addIQProvider("si","http://jabber.org/protocol/si", new StreamInitiationProvider());
// ProviderManager.addIQProvider("query","http://jabber.org/protocol/bytestreams", new BytestreamsProvider());
// Privacy
/**
 *        ProviderManager.addIQProvider("query","jabber:iq:privacy", new PrivacyProvider());
 *        ProviderManager.addIQProvider("command", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider());
 *        ProviderManager.addExtensionProvider("malformed-action", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.MalformedActionError());
 *        ProviderManager.addExtensionProvider("bad-locale", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadLocaleError());
 *        ProviderManager.addExtensionProvider("bad-payload", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadPayloadError());
 *        ProviderManager.addExtensionProvider("bad-sessionid", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadSessionIDError());
 *        ProviderManager.addExtensionProvider("session-expired", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.SessionExpiredError());
 */
}
Also used : GroupChatInvitation(org.jivesoftware.smackx.muc.packet.GroupChatInvitation) MUCUserProvider(org.jivesoftware.smackx.muc.provider.MUCUserProvider) SharedGroupsInfo(org.jivesoftware.smackx.sharedgroups.packet.SharedGroupsInfo) PingProvider(org.jivesoftware.smackx.ping.provider.PingProvider) OfflineMessageInfo(org.jivesoftware.smackx.offline.packet.OfflineMessageInfo) DiscoverInfoProvider(org.jivesoftware.smackx.disco.provider.DiscoverInfoProvider) DiscoverItemsProvider(org.jivesoftware.smackx.disco.provider.DiscoverItemsProvider) VCardProvider(org.jivesoftware.smackx.vcardtemp.provider.VCardProvider) MUCAdminProvider(org.jivesoftware.smackx.muc.provider.MUCAdminProvider) BytestreamsProvider(org.jivesoftware.smackx.bytestreams.socks5.provider.BytestreamsProvider) AdHocCommandDataProvider(org.jivesoftware.smackx.commands.provider.AdHocCommandDataProvider) MUCOwnerProvider(org.jivesoftware.smackx.muc.provider.MUCOwnerProvider) OfflineMessageRequest(org.jivesoftware.smackx.offline.packet.OfflineMessageRequest) PrivateDataManager(org.jivesoftware.smackx.iqprivate.PrivateDataManager) ChatStateExtensionProvider(org.jivesoftware.smackx.chatstates.provider.ChatStateExtensionProvider) MultipleAddressesProvider(org.jivesoftware.smackx.address.provider.MultipleAddressesProvider) PrivacyProvider(org.jivesoftware.smackx.privacy.provider.PrivacyProvider) DataFormProvider(org.jivesoftware.smackx.xdata.provider.DataFormProvider) XHTMLExtensionProvider(org.jivesoftware.smackx.xhtmlim.provider.XHTMLExtensionProvider) LastActivity(org.jivesoftware.smackx.iqlast.packet.LastActivity) UserSearch(org.jivesoftware.smackx.search.UserSearch) StreamInitiationProvider(org.jivesoftware.smackx.si.provider.StreamInitiationProvider)

Example 2 with VCardProvider

use of org.jivesoftware.smackx.vcardtemp.provider.VCardProvider in project xabber-android by redsolution.

the class ContactVcardViewerFragment method parseVCard.

public static VCard parseVCard(String xml) throws Exception {
    XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
    parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
    parser.setInput(new StringReader(xml));
    int eventType = parser.next();
    if (eventType != XmlPullParser.START_TAG) {
        throw new IllegalStateException(String.valueOf(eventType));
    }
    if (!VCard.ELEMENT.equals(parser.getName())) {
        throw new IllegalStateException(parser.getName());
    }
    if (!VCard.NAMESPACE.equals(parser.getNamespace())) {
        throw new IllegalStateException(parser.getNamespace());
    }
    return (new VCardProvider()).parse(parser);
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) StringReader(java.io.StringReader) VCardProvider(org.jivesoftware.smackx.vcardtemp.provider.VCardProvider)

Example 3 with VCardProvider

use of org.jivesoftware.smackx.vcardtemp.provider.VCardProvider in project Spark by igniterealtime.

the class VCardManager method loadFromFileSystem.

/**
 * Attempts to load
 *
 * @param jid the jid of the user.
 * @return the VCard if found, otherwise null.
 */
private VCard loadFromFileSystem(String jid) {
    if (jid == null || jid.trim().isEmpty()) {
        return null;
    }
    // Unescape JID
    String fileName = Base64.encodeBytes(jid.getBytes());
    // remove tab
    fileName = fileName.replaceAll("\t", "");
    // remove new line (Unix)
    fileName = fileName.replaceAll("\n", "");
    // remove new line (Windows)
    fileName = fileName.replaceAll("\r", "");
    final File vcardFile = new File(vcardStorageDirectory, fileName);
    if (!vcardFile.exists()) {
        return null;
    }
    final VCard vcard;
    try (final BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(vcardFile), "UTF-8"))) {
        // Otherwise load from file system.
        VCardProvider provider = new VCardProvider();
        parser.setInput(in);
        // Skip forward until we're at <vCard xmlns='vcard-temp'>
        while (!(parser.getEventType() == XmlPullParser.START_TAG && VCard.ELEMENT.equals(parser.getName()) && VCard.NAMESPACE.equals(parser.getNamespace()))) {
            parser.next();
        }
        vcard = provider.parse(parser);
    } catch (Exception e) {
        Log.warning("Unable to load vCard for " + jid, e);
        vcardFile.delete();
        return null;
    }
    addVCard(jid, vcard);
    // Check to see if the file is older 60 minutes. If so, reload.
    final String timestamp = vcard.getField("timestamp");
    if (timestamp != null) {
        final Duration duration = Duration.between(Instant.ofEpochMilli(Long.parseLong(timestamp)), Instant.now());
        if (duration.toMinutes() >= 60) {
            addToQueue(jid);
        }
    }
    return vcard;
}
Also used : Duration(java.time.Duration) VCard(org.jivesoftware.smackx.vcardtemp.packet.VCard) SmackException(org.jivesoftware.smack.SmackException) MalformedURLException(java.net.MalformedURLException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) XMPPException(org.jivesoftware.smack.XMPPException) VCardProvider(org.jivesoftware.smackx.vcardtemp.provider.VCardProvider)

Aggregations

VCardProvider (org.jivesoftware.smackx.vcardtemp.provider.VCardProvider)3 StringReader (java.io.StringReader)1 MalformedURLException (java.net.MalformedURLException)1 Duration (java.time.Duration)1 SmackException (org.jivesoftware.smack.SmackException)1 XMPPException (org.jivesoftware.smack.XMPPException)1 MultipleAddressesProvider (org.jivesoftware.smackx.address.provider.MultipleAddressesProvider)1 BytestreamsProvider (org.jivesoftware.smackx.bytestreams.socks5.provider.BytestreamsProvider)1 ChatStateExtensionProvider (org.jivesoftware.smackx.chatstates.provider.ChatStateExtensionProvider)1 AdHocCommandDataProvider (org.jivesoftware.smackx.commands.provider.AdHocCommandDataProvider)1 DiscoverInfoProvider (org.jivesoftware.smackx.disco.provider.DiscoverInfoProvider)1 DiscoverItemsProvider (org.jivesoftware.smackx.disco.provider.DiscoverItemsProvider)1 LastActivity (org.jivesoftware.smackx.iqlast.packet.LastActivity)1 PrivateDataManager (org.jivesoftware.smackx.iqprivate.PrivateDataManager)1 GroupChatInvitation (org.jivesoftware.smackx.muc.packet.GroupChatInvitation)1 MUCAdminProvider (org.jivesoftware.smackx.muc.provider.MUCAdminProvider)1 MUCOwnerProvider (org.jivesoftware.smackx.muc.provider.MUCOwnerProvider)1 MUCUserProvider (org.jivesoftware.smackx.muc.provider.MUCUserProvider)1 OfflineMessageInfo (org.jivesoftware.smackx.offline.packet.OfflineMessageInfo)1 OfflineMessageRequest (org.jivesoftware.smackx.offline.packet.OfflineMessageRequest)1