Commit 8a01362d authored by Alex Wenckus's avatar Alex Wenckus Committed by alex

Removed VCardManager dependency from the DefaultUserProvider. JM-663

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3822 b35dd754-fafc-0310-a699-88a17e54d16e
parent c968b97a
...@@ -39,6 +39,7 @@ import org.jivesoftware.wildfire.roster.RosterManager; ...@@ -39,6 +39,7 @@ import org.jivesoftware.wildfire.roster.RosterManager;
import org.jivesoftware.wildfire.spi.*; import org.jivesoftware.wildfire.spi.*;
import org.jivesoftware.wildfire.transport.TransportHandler; import org.jivesoftware.wildfire.transport.TransportHandler;
import org.jivesoftware.wildfire.user.UserManager; import org.jivesoftware.wildfire.user.UserManager;
import org.jivesoftware.wildfire.vcard.VCardManager;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import java.io.File; import java.io.File;
...@@ -420,6 +421,7 @@ public class XMPPServer { ...@@ -420,6 +421,7 @@ public class XMPPServer {
loadModule(TransportHandler.class.getName()); loadModule(TransportHandler.class.getName());
loadModule(OfflineMessageStrategy.class.getName()); loadModule(OfflineMessageStrategy.class.getName());
loadModule(OfflineMessageStore.class.getName()); loadModule(OfflineMessageStore.class.getName());
loadModule(VCardManager.class.getName());
// Load standard modules // Load standard modules
loadModule(IQBindHandler.class.getName()); loadModule(IQBindHandler.class.getName());
loadModule(IQSessionEstablishmentHandler.class.getName()); loadModule(IQSessionEstablishmentHandler.class.getName());
......
/**
* $RCSfile $
* $Revision $
* $Date $
*
* Copyright (C) 1999-2005 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.wildfire.event;
import org.jivesoftware.wildfire.user.User;
import java.util.Map;
/**
* An abstract adapter class for receiving user events.
* The methods in this class are empty. This class exists as convenience for creating listener objects.
*/
public class UserEventAdapter implements UserEventListener {
public void userCreated(User user, Map params) {
}
public void userDeleting(User user, Map params) {
}
public void userModified(User user, Map params) {
}
}
...@@ -13,7 +13,6 @@ package org.jivesoftware.wildfire.user; ...@@ -13,7 +13,6 @@ package org.jivesoftware.wildfire.user;
import org.jivesoftware.database.DbConnectionManager; import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.util.*; import org.jivesoftware.util.*;
import org.jivesoftware.wildfire.vcard.VCardManager;
import java.sql.*; import java.sql.*;
import java.util.*; import java.util.*;
...@@ -203,13 +202,6 @@ public class DefaultUserProvider implements UserProvider { ...@@ -203,13 +202,6 @@ public class DefaultUserProvider implements UserProvider {
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
boolean abortTransaction = false; boolean abortTransaction = false;
try { try {
// Delete all of the users's vcard properties
try {
VCardManager.getInstance().deleteVCard(username);
}
catch (UnsupportedOperationException e) {
// Ignore.
}
// Delete all of the users's extended properties // Delete all of the users's extended properties
con = DbConnectionManager.getTransactionConnection(); con = DbConnectionManager.getTransactionConnection();
pstmt = con.prepareStatement(DELETE_USER_PROPS); pstmt = con.prepareStatement(DELETE_USER_PROPS);
......
...@@ -13,34 +13,27 @@ package org.jivesoftware.wildfire.vcard; ...@@ -13,34 +13,27 @@ package org.jivesoftware.wildfire.vcard;
import org.dom4j.Element; import org.dom4j.Element;
import org.jivesoftware.util.*; import org.jivesoftware.util.*;
import org.jivesoftware.wildfire.container.BasicModule;
import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.user.User;
import org.jivesoftware.wildfire.event.UserEventDispatcher;
import org.jivesoftware.wildfire.event.UserEventAdapter;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.Map;
/** /**
* Manages VCard information for users. * Manages VCard information for users.
* *
* @author Matt Tucker * @author Matt Tucker
*/ */
public class VCardManager { public class VCardManager extends BasicModule {
private static VCardProvider provider; private VCardProvider provider;
private static VCardManager instance = new VCardManager(); private static VCardManager instance;
private Cache vcardCache; private Cache<String, Element> vcardCache;
private EventHandler eventHandler;
static {
// Load a VCard provider.
String className = JiveGlobals.getXMLProperty("provider.vcard.className",
DefaultVCardProvider.class.getName());
try {
Class c = ClassUtils.forName(className);
provider = (VCardProvider)c.newInstance();
}
catch (Exception e) {
Log.error("Error loading vcard provider: " + className, e);
provider = new DefaultVCardProvider();
}
}
public static VCardManager getInstance() { public static VCardManager getInstance() {
return instance; return instance;
...@@ -55,13 +48,14 @@ public class VCardManager { ...@@ -55,13 +48,14 @@ public class VCardManager {
* @return the current VCardProvider. * @return the current VCardProvider.
*/ */
public static VCardProvider getProvider() { public static VCardProvider getProvider() {
return provider; return instance.provider;
} }
private VCardManager() { public VCardManager() {
super("VCard Manager");
String cacheName = "VCard"; String cacheName = "VCard";
CacheManager.initializeCache(cacheName, "vcardCache", 512 * 1024); vcardCache = CacheManager.initializeCache(cacheName, "vcardCache", 512 * 1024);
vcardCache = CacheManager.getCache(cacheName); this.eventHandler = new EventHandler();
} }
/** /**
...@@ -70,7 +64,6 @@ public class VCardManager { ...@@ -70,7 +64,6 @@ public class VCardManager {
* does not exist then a <tt>null</tt> value will be answered. Advanced user systems can * does not exist then a <tt>null</tt> value will be answered. Advanced user systems can
* use vCard information to link to user directory information or store other relevant * use vCard information to link to user directory information or store other relevant
* user information.</p> * user information.</p>
*
* Note that many elements in the vCard may have the same path so the returned value in that * Note that many elements in the vCard may have the same path so the returned value in that
* case will be the first found element. For instance, "ADR:STREET" may be present in * case will be the first found element. For instance, "ADR:STREET" may be present in
* many addresses of the user. Use {@link #getVCard(String)} to get the whole vCard of * many addresses of the user. Use {@link #getVCard(String)} to get the whole vCard of
...@@ -150,6 +143,8 @@ public class VCardManager { ...@@ -150,6 +143,8 @@ public class VCardManager {
* Deletes the user's vCard from the user account. * Deletes the user's vCard from the user account.
* *
* @param username The username of the user to delete his vCard. * @param username The username of the user to delete his vCard.
* @throws UnsupportedOperationException If the provider is read-only and the data cannot be deleted, this exception
* is thrown
*/ */
public void deleteVCard(String username) { public void deleteVCard(String username) {
if (provider.isReadOnly()) { if (provider.isReadOnly()) {
...@@ -176,7 +171,7 @@ public class VCardManager { ...@@ -176,7 +171,7 @@ public class VCardManager {
} }
private Element getOrLoadVCard(String username) { private Element getOrLoadVCard(String username) {
Element vCardElement = (Element) vcardCache.get(username); Element vCardElement = vcardCache.get(username);
if (vCardElement == null) { if (vCardElement == null) {
vCardElement = provider.loadVCard(username); vCardElement = provider.loadVCard(username);
if (vCardElement != null) { if (vCardElement != null) {
...@@ -185,4 +180,41 @@ public class VCardManager { ...@@ -185,4 +180,41 @@ public class VCardManager {
} }
return vCardElement; return vCardElement;
} }
public void initialize(XMPPServer server) {
instance = this;
// Load a VCard provider.
String className = JiveGlobals.getXMLProperty("provider.vcard.className",
DefaultVCardProvider.class.getName());
try {
Class c = ClassUtils.forName(className);
provider = (VCardProvider) c.newInstance();
}
catch (Exception e) {
Log.error("Error loading vcard provider: " + className, e);
provider = new DefaultVCardProvider();
}
}
public void start() {
// Add this module as a user event listener so we can delete
// all user properties when a user is deleted
if (!provider.isReadOnly()) {
UserEventDispatcher.addListener(eventHandler);
}
}
public void stop() {
// Remove this module as a user event listener
UserEventDispatcher.removeListener(eventHandler);
}
private class EventHandler extends UserEventAdapter {
public void userDeleting(User user, Map params) {
try {
deleteVCard(user.getUsername());
} catch (UnsupportedOperationException ue) { /* Do Nothing */ }
}
}
} }
\ No newline at end of file
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