1 25 26 package net.killingar.forum.actions; 27 28 import net.killingar.forum.internal.managers.OptionsManager; 29 import webwork.action.ParameterAware; 30 31 import java.util.ArrayList ; 32 import java.util.List ; 33 import java.util.Map ; 34 35 public class EditOptions 36 extends net.killingar.forum.actions.area.ActionAreaSupport 37 implements ParameterAware 38 { 39 OptionsManager optionmgr; 40 List stringOptions; 41 List booleanOptions; 42 String customHtml; 43 String defaultPostMode; 44 String messagesPerPage; 45 String userDisplayMode; 46 String locale = "browser"; 47 Map parameters; 48 49 static final String stringOptionsData[][] = 50 { 51 {"area indent size", "area_indent_size", "20"}, 57 {"contents frame width", "contents_frame_width", "140"}, 58 {"contents frame refresh interval", "contents_frame_refresh_interval", "30"}, 59 {"user hide threshold", "user_hide_threshold", "182"}, 60 }; 61 62 static final String booleanOptionsData[][] = 63 { 64 {"icq user display mode", "icq_user_display_mode"}, 65 {"disable cached comics", "disable_cached_comics"}, 66 {"dynamic areas", "dynamic_areas"}, 67 {"hide logo", "hide_logo"}, 68 {"hide address book", "hide_address_book"}, 69 {"hide archive", "hide_archive"}, 70 {"hide birthdays", "hide_birthdays"}, 71 {"hide comics", "hide_comics"}, 72 {"hide FAQ", "hide_FAQ"}, 73 {"hide areas", "hide_areas"}, 74 {"hide planning", "hide_planning"}, 75 {"hide polls", "hide_polls"}, 76 {"hide quotes", "hide_quotes"}, 77 {"hide tasks", "hide_tasks"}, 78 {"hide timekeeper", "hide_timekeeper"}, 80 {"hide todo", "hide_todo"}, 81 {"hide users", "hide_users"}, 82 {"hide wiki", "hide_wiki"}, 83 {"hide my wiki", "hide_my_wiki"}, 84 {"show custom contents html", "show_custom_contents_html"}, 86 }; 87 88 public void setParameters(Map map) { parameters = map; } 89 public void setSession(Map map) 90 { 91 super.setSession(map); 92 try 93 { 94 synchronized (map) 95 { 96 optionmgr = (OptionsManager)manager.getManager(OptionsManager.class.getName()); 97 if (optionmgr == null) 98 addErrorMessage("failed to initialize options manager, null returned"); 99 } 100 } 101 catch (Exception exception) 102 { 103 addErrorMessage("failed to initialize options manager, exception thrown (" + exception.toString() + ")"); 104 exception.printStackTrace(); 105 } 106 } 107 108 public void setLoc(String in) { locale = in; } 109 110 public List getStringOptions() { return stringOptions; } 111 public List getBooleanOptions() { return booleanOptions; } 112 public String getCustomHtml() { return customHtml; } 113 public String getDefaultPostMode() { return defaultPostMode; } 114 public String getMessagesPerPage() { return messagesPerPage; } 115 public String getUserDisplayMode() { return userDisplayMode; } 116 public String getLoc() { return locale; } 117 118 protected String doExecute() 119 { 120 try 121 { 122 if (parameters.containsKey("change")) 123 { 124 for (int k = 0; k < stringOptionsData.length; k++) 125 { 126 if (parameters.containsKey(stringOptionsData[k][0])) 127 { 128 String s = ((String [])parameters.get(stringOptionsData[k][0]))[0]; 129 if (s != null && s.equals(stringOptionsData[k][2])) 130 s = null; 131 optionmgr.set(stringOptionsData[k][0], s); 132 } 133 } 134 135 for (int l = 0; l < booleanOptionsData.length; l++) 136 { 137 if (parameters.get(booleanOptionsData[l][0]) != null) 138 optionmgr.set(booleanOptionsData[l][0], "yes"); 139 else 140 optionmgr.set(booleanOptionsData[l][0], null); 141 } 142 143 String s1 = ((String [])parameters.get("custom contents html"))[0]; 144 if (s1.length() == 0) 145 s1 = null; 146 optionmgr.set("custom contents html", s1); 147 148 s1 = ((String [])parameters.get("number of messages per page"))[0]; 149 if (s1.equals("32")) 150 s1 = null; 151 152 optionmgr.set("number of messages per page", s1); 153 if (s1 != null) 154 areamgr.setMessagesPerPage(Integer.parseInt(s1)); 155 else 156 areamgr.setMessagesPerPage(32); 157 158 s1 = ((String [])parameters.get("default post mode"))[0]; 159 if (s1.equals("HTML")) 160 s1 = null; 161 optionmgr.set("default post mode", s1); 162 163 s1 = ((String [])parameters.get("user display mode"))[0]; 164 if (s1.equals("username")) 165 s1 = null; 166 167 optionmgr.set("user display mode", s1); 168 169 if ("browser".equals(locale)) 170 locale = null; 171 optionmgr.set("locale", locale); 172 } 173 stringOptions = new ArrayList (); 174 for (int i = 0; i < stringOptionsData.length; i++) 175 stringOptions.add(new StringOption(stringOptionsData[i][0], stringOptionsData[i][1], optionmgr.get(stringOptionsData[i][0]), stringOptionsData[i][2])); 176 177 booleanOptions = new ArrayList (); 178 for (int j = 0; j < booleanOptionsData.length; j++) 179 booleanOptions.add(new BooleanOption(booleanOptionsData[j][0], booleanOptionsData[j][1], optionmgr.get(booleanOptionsData[j][0]) != null)); 180 181 messagesPerPage = optionmgr.get("number of messages per page"); 182 if (messagesPerPage == null) 183 messagesPerPage = "32"; 184 customHtml = optionmgr.get("custom contents html"); 185 186 userDisplayMode = optionmgr.get("user display mode"); 187 locale = optionmgr.get("locale"); 188 defaultPostMode = optionmgr.get("default post mode"); 189 190 synchronized(session) 191 { 192 session.remove("localeObject"); 193 } 194 195 return SUCCESS; 196 } 197 catch (Exception exception) 198 { 199 addErrorMessage("edit options failed, exception thrown (" + exception.toString() + ")"); 200 exception.printStackTrace(); 201 return ERROR; 202 } 203 } 204 } | Popular Tags |