org.jivesoftware.smackx.vcardtemp.provider.VCardProvider Java Examples

The following examples show how to use org.jivesoftware.smackx.vcardtemp.provider.VCardProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XMPPManager.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
public VCard getUserVCard(String jid) {
    //ProviderManager.getInstance().addIQProvider("vCard", "vcard-temp", new VCardProvider());

    VCard vCard = new VCard();

    try {
        vCard.load(XMPPManager.getInstance().getConnection(), JidCreate.entityBareFrom(jid/*+DOMAIN*/));
        VCardProvider vCardProvider = new VCardProvider();

    } catch (Exception e) {
        e.printStackTrace();
    }
    return vCard;
}
 
Example #2
Source File: VCardManager.java    From Spark with Apache License 2.0 4 votes vote down vote up
/**
 * Attempts to load
 *
 * @param jid the jid of the user.
 * @return the VCard if found, otherwise null.
 */
private VCard loadFromFileSystem(BareJid jid) {
	if (jid == null) {
		return null;
	}
	
    // Unescape JID
    String fileName = Base64.encodeBytes(jid.toString().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;
}