1 43 package net.jforum.view.admin; 44 45 import java.io.FileInputStream ; 46 import java.util.ArrayList ; 47 import java.util.Enumeration ; 48 import java.util.Iterator ; 49 import java.util.List ; 50 import java.util.Map ; 51 import java.util.Properties ; 52 53 import javax.servlet.http.HttpServletResponse ; 54 55 import net.jforum.ActionServletRequest; 56 import net.jforum.entities.Category; 57 import net.jforum.entities.Forum; 58 import net.jforum.repository.ForumRepository; 59 import net.jforum.repository.TopicRepository; 60 import net.jforum.util.I18n; 61 import net.jforum.util.preferences.ConfigKeys; 62 import net.jforum.util.preferences.SystemGlobals; 63 import net.jforum.util.preferences.TemplateKeys; 64 import freemarker.template.SimpleHash; 65 66 70 public class ConfigAction extends AdminCommand 71 { 72 public ConfigAction() {} 73 74 public ConfigAction(ActionServletRequest request, 75 HttpServletResponse response, 76 SimpleHash context) 77 { 78 this.request = request; 79 this.response = response; 80 this.context = context; 81 } 82 83 public void list() throws Exception { 84 Properties p = new Properties (); 85 Iterator iter = SystemGlobals.fetchConfigKeyIterator(); 86 87 while (iter.hasNext()) { 88 String key = (String ) iter.next(); 89 String value = SystemGlobals.getValue(key); 90 p.put(key, value); 91 } 92 93 Properties locales = new Properties (); 94 locales.load(new FileInputStream (SystemGlobals.getValue(ConfigKeys.CONFIG_DIR) 95 + "/languages/locales.properties")); 96 List localesList = new ArrayList (); 97 98 for (Enumeration e = locales.keys(); e.hasMoreElements();) { 99 localesList.add(e.nextElement()); 100 } 101 102 this.context.put("config", p); 103 this.context.put("locales", localesList); 104 this.setTemplateName(TemplateKeys.CONFIG_LIST); 105 } 106 107 public void editSave() throws Exception 108 { 109 this.updateData(this.getConfig()); 110 this.list(); 111 } 112 113 Properties getConfig() 114 { 115 Properties p = new Properties (); 116 117 Enumeration e = this.request.getParameterNames(); 118 while (e.hasMoreElements()) { 119 String name = (String ) e.nextElement(); 120 121 if (name.startsWith("p_")) { 122 p.setProperty(name.substring(name.indexOf('_') + 1), this.request.getParameter(name)); 123 } 124 } 125 126 return p; 127 } 128 129 void updateData(Properties p) throws Exception 130 { 131 int oldTopicsPerPage = SystemGlobals.getIntValue(ConfigKeys.TOPICS_PER_PAGE); 132 133 for (Iterator iter = p.entrySet().iterator(); iter.hasNext(); ) { 134 Map.Entry entry = (Map.Entry )iter.next(); 135 136 SystemGlobals.setValue((String )entry.getKey(), (String )entry.getValue()); 137 } 138 139 SystemGlobals.saveInstallation(); 140 I18n.changeBoardDefault(SystemGlobals.getValue(ConfigKeys.I18N_DEFAULT)); 141 142 if (oldTopicsPerPage != SystemGlobals.getIntValue(ConfigKeys.TOPICS_PER_PAGE)) { 144 List categories = ForumRepository.getAllCategories(); 145 146 for (Iterator iter = categories.iterator(); iter.hasNext(); ) { 147 Category c = (Category)iter.next(); 148 149 for (Iterator iter2 = c.getForums().iterator(); iter2.hasNext(); ) { 150 Forum f = (Forum)iter2.next(); 151 TopicRepository.clearCache(f.getId()); 152 } 153 } 154 } 155 } 156 } | Popular Tags |