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; }
public boolean templateExists(String key, Locale locale) { List<EmailTemplate> et = null; Search search = new Search("key", key); if (locale == null) { search.addRestriction(new Restriction("locale", EmailTemplate.DEFAULT_LOCALE)); } else { search.addRestriction(new Restriction("locale", locale.toString())); } et = dao.findBySearch(EmailTemplate.class, search); if (et != null && et.size() > 0) { return true; } return false; }
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; }