public void setVCard(String username, Element vCardElement) throws Exception {
        boolean created = false;
        boolean updated = false;

        if (provider.isReadOnly()) {
            throw new UnsupportedOperationException("VCard provider is read-only.");
        }
        Element oldVCard = getOrLoadVCard(username);
        Element newvCard = null;
        // See if we need to update the vCard or insert a new one.
        if (oldVCard != null) {
            // Only update the vCard in the database if the vCard has changed.
            if (!oldVCard.equals(vCardElement)) {
                try {
                    newvCard = provider.updateVCard(username, vCardElement);
                    vcardCache.put(username, (DefaultElement) newvCard);
                    updated = true;
                }
                catch (NotFoundException e) {
                    Log.warn("Tried to update a vCard that does not exist", e);
                    newvCard = provider.createVCard(username, vCardElement);
                    vcardCache.put(username, (DefaultElement) newvCard);
                    created = true;
                }
            }
        }
        else {
            try {
                newvCard = provider.createVCard(username, vCardElement);
                vcardCache.put(username, (DefaultElement) newvCard);
                created = true;
            }
            catch (AlreadyExistsException e) {
                Log.warn("Tried to create a vCard when one already exist", e);
                newvCard = provider.updateVCard(username, vCardElement);
                vcardCache.put(username, (DefaultElement) newvCard);
                updated = true;
            }
        }
        // Dispatch vCard events
        if (created) {
            // Alert listeners that a new vCard has been created
            VCardEventDispatcher.dispatchVCardCreated(username, newvCard);
        } else if (updated) {
            // Alert listeners that a vCard has been updated
            VCardEventDispatcher.dispatchVCardUpdated(username, newvCard);
        }
    }
Sets the user's vCard information. The new vCard information will be persistent. Advanced
user systems can use vCard information to link to user directory information or store
other relevant user information.

@param username     The username of the user to set his new vCard.
@param vCardElement The DOM element sent by the user as his new vCard.
@throws Exception if an error occurred while storing the new vCard.
xmppserver/src/main/java/org/jivesoftware/openfire/vcard/VCardManager.java