1 43 package net.jforum.repository; 44 45 import java.util.Iterator ; 46 import java.util.List ; 47 48 import net.jforum.JForumExecutionContext; 49 import net.jforum.cache.CacheEngine; 50 import net.jforum.cache.Cacheable; 51 import net.jforum.dao.DataAccessDriver; 52 import net.jforum.entities.Smilie; 53 import net.jforum.exceptions.SmiliesLoadException; 54 55 59 public class SmiliesRepository implements Cacheable 60 { 61 private static CacheEngine cache; 62 private static final String FQN = "smilies"; 63 private static final String ENTRIES = "entries"; 64 private static boolean contexted = false; 65 66 69 public void setCacheEngine(CacheEngine engine) 70 { 71 cache = engine; 72 } 73 74 public static void loadSmilies() 75 { 76 try { 77 cache.add(FQN, ENTRIES, DataAccessDriver.getInstance().newSmilieDAO().selectAll()); 78 contexted = false; 79 } 80 catch (Exception e) { 81 throw new SmiliesLoadException("Error while loading smilies: " + e); 82 } 83 } 84 85 public static List getSmilies() 86 { 87 List list = (List )cache.get(FQN, ENTRIES); 88 if (!contexted) { 89 String context = JForumExecutionContext.getRequest().getContextPath(); 90 91 for (Iterator iter = list.iterator(); iter.hasNext(); ) { 92 Smilie s = (Smilie)iter.next(); 93 s.setUrl(s.getUrl().replaceAll("#CONTEXT#", context) 94 .replaceAll("\\\\", "")); 95 } 96 97 cache.add(FQN, ENTRIES, list); 98 contexted = true; 99 } 100 101 return list; 102 } 103 } 104 | Popular Tags |