KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > killingar > forum > actions > EditOptions


1 /* Copyright 2000-2005 Anders Hovmöller
2  *
3  * The person or persons who have associated their work with
4  * this document (the "Dedicator") hereby dedicate the entire
5  * copyright in the work of authorship identified below (the
6  * "Work") to the public domain.
7  *
8  * Dedicator makes this dedication for the benefit of the
9  * public at large and to the detriment of Dedicator's heirs
10  * and successors. Dedicator intends this dedication to be an
11  * overt act of relinquishment in perpetuity of all present
12  * and future rights under copyright law, whether vested or
13  * contingent, in the Work. Dedicator understands that such
14  * relinquishment of all rights includes the relinquishment of
15  * all rights to enforce (by lawsuit or otherwise) those
16  * copyrights in the Work.
17  *
18  * Dedicator recognizes that, once placed in the public
19  * domain, the Work may be freely reproduced, distributed,
20  * transmitted, used, modified, built upon, or otherwise
21  * exploited by anyone for any purpose, commercial or non-
22  * commercial, and in any way, including by methods that have
23  * not yet been invented or conceived.
24  */

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 JavaDoc;
32 import java.util.List JavaDoc;
33 import java.util.Map JavaDoc;
34
35 public class EditOptions
36     extends net.killingar.forum.actions.area.ActionAreaSupport
37     implements ParameterAware
38 {
39     OptionsManager optionmgr;
40     List JavaDoc stringOptions;
41     List JavaDoc booleanOptions;
42     String JavaDoc customHtml;
43     String JavaDoc defaultPostMode;
44     String JavaDoc messagesPerPage;
45     String JavaDoc userDisplayMode;
46     String JavaDoc locale = "browser";
47     Map JavaDoc parameters;
48
49     static final String JavaDoc stringOptionsData[][] =
50     {
51         //{"arrow down url", "URL for down arrow picture", "/_common/img/arrowdown.gif"},
52
//{"arrow up url", "URL for up arrow picture", "/_common/img/arrowup.gif"},
53
//{"bar image", "default bar image for polls", "servlet/Pixel?722899"},
54
//{"hr", "horizontal ruler", "<img SRC=\"/_common/img/color.gif\" width=\"100%\" height=\"13\" alt=\"horizontal ruler\"/><br />"},
55
//{"logo url", "contents logo url", "/_common/img/logo_small.gif"},
56
{"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 JavaDoc 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 statistics", "hide_statistics"},
79
{"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         //{"hide manage", "hide_manage"},
85
{"show custom contents html", "show_custom_contents_html"},
86     };
87
88     public void setParameters(Map JavaDoc map) { parameters = map; }
89     public void setSession(Map JavaDoc 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 JavaDoc exception)
102         {
103             addErrorMessage("failed to initialize options manager, exception thrown (" + exception.toString() + ")");
104             exception.printStackTrace();
105         }
106     }
107
108     public void setLoc(String JavaDoc in) { locale = in; }
109
110     public List JavaDoc getStringOptions() { return stringOptions; }
111     public List JavaDoc getBooleanOptions() { return booleanOptions; }
112     public String JavaDoc getCustomHtml() { return customHtml; }
113     public String JavaDoc getDefaultPostMode() { return defaultPostMode; }
114     public String JavaDoc getMessagesPerPage() { return messagesPerPage; }
115     public String JavaDoc getUserDisplayMode() { return userDisplayMode; }
116     public String JavaDoc getLoc() { return locale; }
117
118     protected String JavaDoc 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 JavaDoc s = ((String JavaDoc[])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 JavaDoc s1 = ((String JavaDoc[])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 JavaDoc[])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 JavaDoc[])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 JavaDoc[])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 JavaDoc();
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 JavaDoc();
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 JavaDoc exception)
198         {
199             addErrorMessage("edit options failed, exception thrown (" + exception.toString() + ")");
200             exception.printStackTrace();
201             return ERROR;
202         }
203     }
204 }
Popular Tags