public RenderedTemplate getRenderedTemplateForUser(
     String key, String userReference, Map<String, String> replacementValues) {
   log.debug("getRenderedTemplateForUser(" + key + ", " + userReference);
   String userId = developerHelperService.getUserIdFromRef(userReference);
   Locale loc = getUserLocale(userId);
   return getRenderedTemplate(key, loc, replacementValues);
 }
  private List<User> getUsersEmail(List<String> userIds) {
    // we have a group of references
    List<String> ids = new ArrayList<String>();

    for (int i = 0; i < userIds.size(); i++) {
      String userReference = userIds.get(i);
      String userId = developerHelperService.getUserIdFromRef(userReference);
      ids.add(userId);
    }
    return userDirectoryService.getUsers(ids);
  }
  public Map<EmailTemplateLocaleUsers, RenderedTemplate> getRenderedTemplates(
      String key, List<String> userReferences, Map<String, String> replacementValues) {

    List<Locale> foundLocales = new ArrayList<Locale>();
    Map<Locale, EmailTemplateLocaleUsers> mapStore =
        new HashMap<Locale, EmailTemplateLocaleUsers>();

    for (int i = 0; i < userReferences.size(); i++) {
      String userReference = userReferences.get(i);
      String userId = developerHelperService.getUserIdFromRef(userReference);
      Locale loc = getUserLocale(userId);
      // have we found this locale?
      if (!foundLocales.contains(loc)) {
        // create a new EmailTemplateLocalUser
        EmailTemplateLocaleUsers etlu = new EmailTemplateLocaleUsers();
        log.debug("adding users " + userReference + " to new object");
        etlu.setLocale(loc);
        etlu.addUser(userReference);
        mapStore.put(loc, etlu);
        foundLocales.add(loc);
      } else {
        EmailTemplateLocaleUsers etlu = mapStore.get(loc);
        log.debug("adding users " + userReference + " to existing object");
        etlu.addUser(userReference);
        mapStore.remove(loc);
        mapStore.put(loc, etlu);
      }
    }

    Map<EmailTemplateLocaleUsers, RenderedTemplate> ret =
        new HashMap<EmailTemplateLocaleUsers, RenderedTemplate>();

    // now for each locale we need a rendered template
    Set<Entry<Locale, EmailTemplateLocaleUsers>> es = mapStore.entrySet();
    Iterator<Entry<Locale, EmailTemplateLocaleUsers>> it = es.iterator();
    while (it.hasNext()) {
      Entry<Locale, EmailTemplateLocaleUsers> entry = it.next();
      Locale loc = entry.getKey();
      RenderedTemplate rt = this.getRenderedTemplate(key, loc, replacementValues);
      if (rt != null) {
        ret.put(entry.getValue(), rt);
      } else {
        log.error("No template found for key: " + key + " in locale: " + loc);
      }
    }
    return ret;
  }