public EmailTemplate getEmailTemplate(String key, Locale locale) { if (key == null || "".equals(key)) { throw new IllegalArgumentException("key cannot be null or empty"); } if (log.isDebugEnabled()) { log.debug("getEmailTemplate(key=" + key + ", locale=" + locale + ")"); } EmailTemplate et = null; // TODO make this more efficient if (locale != null) { Search search = new Search("key", key); search.addRestriction(new Restriction("locale", locale.toString())); et = dao.findOneBySearch(EmailTemplate.class, search); if (et == null) { search.addRestriction(new Restriction("locale", locale.getLanguage())); et = dao.findOneBySearch(EmailTemplate.class, search); } } if (et == null) { Search search = new Search("key", key); search.addRestriction(new Restriction("locale", EmailTemplate.DEFAULT_LOCALE)); et = dao.findOneBySearch(EmailTemplate.class, search); } if (et == null) { log.warn("no template found for: " + key + " in locale " + locale); } return et; }
private EmailTemplate getEmailTemplateNoDefault(String key, Locale locale) { log.debug("getEmailTemplateNoDefault( " + key + "," + locale); if (key == null || "".equals(key)) { throw new IllegalArgumentException("key cannot be null or empty"); } EmailTemplate et = null; if (locale != null) { Search search = new Search("key", key); search.addRestriction(new Restriction("locale", locale.toString())); et = dao.findOneBySearch(EmailTemplate.class, search); } else { Search search = new Search("key", key); search.addRestriction(new Restriction("locale", EmailTemplate.DEFAULT_LOCALE)); et = dao.findOneBySearch(EmailTemplate.class, search); } return et; }