1 37 package net.sourceforge.cruisecontrol.publishers.email; 38 39 import java.util.Hashtable ; 40 import java.util.Map ; 41 import java.util.Set ; 42 import java.util.Iterator ; 43 44 import net.sourceforge.cruisecontrol.publishers.EmailPublisher; 45 46 import org.apache.log4j.Logger; 47 48 public class EmailMapperHelper { 49 50 private static final Logger LOG = Logger.getLogger(EmailMapperHelper.class); 51 52 55 private static final Map CACHE = new Hashtable (); 56 57 public static void addCacheEntry(Object cache, String user, String mappedUser) { 58 Map map = (Map ) CACHE.get(cache); 59 if (map == null) { 60 map = new Hashtable (); 61 CACHE.put(cache, map); 62 } 63 map.put(user, mappedUser); 64 } 65 66 public static String getCachedUser(Object cache, String user) { 67 String mappedUser = null; 68 Map map = (Map ) CACHE.get(cache); 69 if (map != null) { 70 mappedUser = (String ) map.get(user); 71 } 72 return mappedUser; 73 } 74 75 public void mapUsers(EmailPublisher publisher, Set users, Set mappedUsers) { 76 for (Iterator userIterator = users.iterator(); userIterator.hasNext(); ) { 78 String user = (String ) userIterator.next(); 79 String mappedUser = getCachedUser(publisher, user); 80 if (mappedUser != null) { 81 LOG.debug("User " + user + " found in cache. Mapped to: " + mappedUser); 82 userIterator.remove(); 83 mappedUsers.add(mappedUser); 84 } 85 } 86 87 EmailMapper[] mappers = publisher.getEmailMapper(); 90 for (int i = 0; i < mappers.length; i++) { 91 mappers[i].mapUsers(users, mappedUsers); 92 } 93 94 for (Iterator userIterator = users.iterator(); userIterator.hasNext(); ) { 96 mappedUsers.add(userIterator.next()); 97 userIterator.remove(); 98 } 99 } 100 } 101 | Popular Tags |