Commit 9ed3ba13 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[JM-1232] Made checks for vcard changes more lenient.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@9727 b35dd754-fafc-0310-a699-88a17e54d16e
parent d52c7d70
......@@ -94,7 +94,7 @@ public class DefaultVCardProvider implements VCardProvider {
}
}
public void createVCard(String username, Element vCardElement) throws AlreadyExistsException {
public Element createVCard(String username, Element vCardElement) throws AlreadyExistsException {
if (loadVCard(username) != null) {
// The user already has a vCard
throw new AlreadyExistsException("Username " + username + " already has a vCard");
......@@ -118,9 +118,10 @@ public class DefaultVCardProvider implements VCardProvider {
try { if (con != null) { con.close(); } }
catch (Exception e) { Log.error(e); }
}
return vCardElement;
}
public void updateVCard(String username, Element vCardElement) throws NotFoundException {
public Element updateVCard(String username, Element vCardElement) throws NotFoundException {
if (loadVCard(username) == null) {
// The user already has a vCard
throw new NotFoundException("Username " + username + " does not have a vCard");
......@@ -143,6 +144,7 @@ public class DefaultVCardProvider implements VCardProvider {
try { if (con != null) { con.close(); } }
catch (Exception e) { Log.error(e); }
}
return vCardElement;
}
public void deleteVCard(String username) {
......
......@@ -129,28 +129,31 @@ public class VCardManager extends BasicModule implements ServerFeaturesProvider
// Only update the vCard in the database if the vCard has changed.
if (!oldVCard.equals(vCardElement)) {
try {
provider.updateVCard(username, vCardElement);
Element newvCard = provider.updateVCard(username, vCardElement);
vcardCache.put(username, newvCard);
updated = true;
}
catch (NotFoundException e) {
Log.warn("Tried to update a vCard that does not exist", e);
provider.createVCard(username, vCardElement);
Element newvCard = provider.createVCard(username, vCardElement);
vcardCache.put(username, newvCard);
created = true;
}
}
}
else {
try {
provider.createVCard(username, vCardElement);
Element newvCard = provider.createVCard(username, vCardElement);
vcardCache.put(username, newvCard);
created = true;
}
catch (AlreadyExistsException e) {
Log.warn("Tried to create a vCard when one already exist", e);
provider.updateVCard(username, vCardElement);
Element newvCard = provider.updateVCard(username, vCardElement);
vcardCache.put(username, newvCard);
updated = true;
}
}
vcardCache.put(username, vCardElement);
// Dispatch vCard events
if (created) {
// Alert listeners that a new vCard has been created
......@@ -187,6 +190,7 @@ public class VCardManager extends BasicModule implements ServerFeaturesProvider
* returned vCard will not be stored in the database. Use the returned vCard as a
* read-only vCard.
*
* @param username Username (not full JID) whose vCard to retrieve.
* @return the vCard of a given user.
*/
public Element getVCard(String username) {
......
......@@ -36,26 +36,36 @@ public interface VCardProvider {
* UnsupportedOperationException if this operation is not supported by
* the backend vcard store.
*
* The method is expected to return the vCard after it has had a chance
* to make any modifications to it that it needed to. In many cases, this
* may be a simple return of the passed in vCard. This change was made in 3.4.4.
*
* @param username the username.
* @param vCardElement the vCard to save.
* @return vCard as it is after the provider has a chance to adjust it.
* @throws AlreadyExistsException if the user already has a vCard.
* @throws UnsupportedOperationException if the provider does not support the
* operation.
*/
void createVCard(String username, Element vCardElement) throws AlreadyExistsException;
Element createVCard(String username, Element vCardElement) throws AlreadyExistsException;
/**
* Updates the user vcard in the backend store. This method should throw an
* UnsupportedOperationException if this operation is not supported by
* the backend vcard store.
*
* The method is expected to return the vCard after it has had a chance
* to make any modifications to it that it needed to. In many cases, this
* may be a simple return of the passed in vCard. This change was made in 3.4.4.
*
* @param username the username.
* @param vCardElement the vCard to save.
* @return vCard as it is after the provider has a chance to adjust it.
* @throws NotFoundException if the vCard to update does not exist.
* @throws UnsupportedOperationException if the provider does not support the
* operation.
*/
void updateVCard(String username, Element vCardElement) throws NotFoundException;
Element updateVCard(String username, Element vCardElement) throws NotFoundException;
/**
* Delets a user vcard. This method should throw an UnsupportedOperationException
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment