KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > jforum > view > admin > AttachmentsAction


1 /*
2  * Copyright (c) Rafael Steil
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms,
6  * with or without modification, are permitted provided
7  * that the following conditions are met:
8  *
9  * 1) Redistributions of source code must retain the above
10  * copyright notice, this list of conditions and the
11  * following disclaimer.
12  * 2) Redistributions in binary form must reproduce the
13  * above copyright notice, this list of conditions and
14  * the following disclaimer in the documentation and/or
15  * other materials provided with the distribution.
16  * 3) Neither the name of "Rafael Steil" nor
17  * the names of its contributors may be used to endorse
18  * or promote products derived from this software without
19  * specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
22  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
23  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
24  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
27  * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
32  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
34  * IN CONTRACT, STRICT LIABILITY, OR TORT
35  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
37  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
38  *
39  * Created on Jan 17, 2005 2:46:30 PM
40  * The JForum Project
41  * http://www.jforum.net
42  */

43 package net.jforum.view.admin;
44
45 import java.util.ArrayList JavaDoc;
46 import java.util.Arrays JavaDoc;
47 import java.util.List JavaDoc;
48
49 import net.jforum.dao.AttachmentDAO;
50 import net.jforum.dao.DataAccessDriver;
51 import net.jforum.entities.AttachmentExtension;
52 import net.jforum.entities.AttachmentExtensionGroup;
53 import net.jforum.entities.QuotaLimit;
54 import net.jforum.util.TreeGroup;
55 import net.jforum.util.preferences.ConfigKeys;
56 import net.jforum.util.preferences.SystemGlobals;
57 import net.jforum.util.preferences.TemplateKeys;
58
59 /**
60  * @author Rafael Steil
61  * @version $Id: AttachmentsAction.java,v 1.13 2006/01/20 15:02:20 rafaelsteil Exp $
62  */

63 public class AttachmentsAction extends AdminCommand
64 {
65     public void configurations() throws Exception JavaDoc
66     {
67         this.context.put("icon", SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_ICON));
68         this.context.put("createThumb", SystemGlobals.getBoolValue(ConfigKeys.ATTACHMENTS_IMAGES_CREATE_THUMB));
69         this.context.put("thumbH", SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_IMAGES_MAX_THUMB_H));
70         this.context.put("thumbW", SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_IMAGES_MAX_THUMB_W));
71         this.context.put("maxPost", SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_MAX_POST));
72         this.context.put("thumbBorder", SystemGlobals.getBoolValue(ConfigKeys.ATTACHMENTS_IMAGES_THUMB_BOX_SHOW));
73
74         this.setTemplateName(TemplateKeys.ATTACHMENTS_CONFIG);
75     }
76     
77     public void configurationsSave() throws Exception JavaDoc
78     {
79         ConfigAction ca = new ConfigAction(this.request, this.response, this.context);
80         ca.updateData(ca.getConfig());
81         
82         this.configurations();
83     }
84     
85     public void quotaLimit() throws Exception JavaDoc
86     {
87         AttachmentDAO am = DataAccessDriver.getInstance().newAttachmentDAO();
88         
89         this.context.put("quotas", am.selectQuotaLimit());
90         this.setTemplateName(TemplateKeys.ATTACHMENTS_QUOTA_LIMIT);
91         this.context.put("groups", new TreeGroup().getNodes());
92         this.context.put("selectedList", new ArrayList JavaDoc());
93         this.context.put("groupQuotas", am.selectGroupsQuotaLimits());
94     }
95     
96     public void quotaLimitSave() throws Exception JavaDoc
97     {
98         QuotaLimit ql = new QuotaLimit();
99         ql.setDescription(this.request.getParameter("quota_description"));
100         ql.setSize(this.request.getIntParameter("max_filesize"));
101         ql.setType(this.request.getIntParameter("type"));
102         
103         DataAccessDriver.getInstance().newAttachmentDAO().addQuotaLimit(ql);
104         this.quotaLimit();
105     }
106     
107     public void quotaLimitUpdate() throws Exception JavaDoc
108     {
109         AttachmentDAO am = DataAccessDriver.getInstance().newAttachmentDAO();
110         
111         // First check if we should delete some entry
112
String JavaDoc[] delete = this.request.getParameterValues("delete");
113         List JavaDoc deleteList = new ArrayList JavaDoc();
114         if (delete != null) {
115             deleteList = Arrays.asList(delete);
116             am.removeQuotaLimit(delete);
117         }
118         
119         // Now update the remaining
120
int total = this.request.getIntParameter("total_records");
121         for (int i = 0; i < total; i++) {
122             if (deleteList.contains(this.request.getParameter("id_" + i))) {
123                 continue;
124             }
125             
126             QuotaLimit ql = new QuotaLimit();
127             ql.setId(this.request.getIntParameter("id_" + i));
128             ql.setDescription(this.request.getParameter("quota_desc_" + i));
129             ql.setSize(this.request.getIntParameter("max_filesize_" + i));
130             ql.setType(this.request.getIntParameter("type_" + i));
131             
132             am.updateQuotaLimit(ql);
133         }
134         
135         this.quotaLimit();
136     }
137     
138     public void extensionGroups() throws Exception JavaDoc
139     {
140         this.setTemplateName(TemplateKeys.ATTACHMENTS_EXTENSION_GROUPS);
141         this.context.put("groups", DataAccessDriver.getInstance().newAttachmentDAO().selectExtensionGroups());
142     }
143     
144     public void extensionGroupsSave() throws Exception JavaDoc
145     {
146         AttachmentExtensionGroup g = new AttachmentExtensionGroup();
147         g.setAllow(this.request.getParameter("allow") != null);
148         g.setDownloadMode(this.request.getIntParameter("download_mode"));
149         g.setName(this.request.getParameter("name"));
150         g.setUploadIcon(this.request.getParameter("upload_icon"));
151         
152         DataAccessDriver.getInstance().newAttachmentDAO().addExtensionGroup(g);
153         this.extensionGroups();
154     }
155     
156     public void extensionGroupsUpdate() throws Exception JavaDoc
157     {
158         AttachmentDAO am = DataAccessDriver.getInstance().newAttachmentDAO();
159         
160         // Check if there are records to remove
161
String JavaDoc[] delete = this.request.getParameterValues("delete");
162         List JavaDoc deleteList = new ArrayList JavaDoc();
163         if (delete != null) {
164             deleteList = Arrays.asList(delete);
165             am.removeExtensionGroups(delete);
166         }
167         
168         // Update
169
int total = this.request.getIntParameter("total_records");
170         for (int i = 0; i < total; i++) {
171             if (deleteList.contains(this.request.getParameter("id_" + i))) {
172                 continue;
173             }
174             
175             AttachmentExtensionGroup g = new AttachmentExtensionGroup();
176             g.setId(this.request.getIntParameter("id_" + i));
177             g.setAllow(this.request.getParameter("allow_" + i) != null);
178             g.setDownloadMode(this.request.getIntParameter("download_mode_" + i));
179             g.setName(this.request.getParameter("name_" + i));
180             g.setUploadIcon(this.request.getParameter("upload_icon_" + i));
181             
182             am.updateExtensionGroup(g);
183         }
184         
185         this.extensionGroups();
186     }
187     
188     public void extensions() throws Exception JavaDoc
189     {
190         AttachmentDAO am = DataAccessDriver.getInstance().newAttachmentDAO();
191         
192         this.setTemplateName(TemplateKeys.ATTACHMENTS_EXTENSIONS);
193         this.context.put("extensions", am.selectExtensions());
194         this.context.put("groups", am.selectExtensionGroups());
195     }
196     
197     public void extensionsSave() throws Exception JavaDoc
198     {
199         AttachmentExtension e = new AttachmentExtension();
200         e.setAllow(this.request.getParameter("allow") != null);
201         e.setComment(this.request.getParameter("comment"));
202         e.setExtension(this.request.getParameter("extension"));
203         e.setUploadIcon(this.request.getParameter("upload_icon"));
204         e.setExtensionGroupId(this.request.getIntParameter("extension_group"));
205         
206         if (e.getExtension().startsWith(".")) {
207             e.setExtension(e.getExtension().substring(1));
208         }
209         
210         DataAccessDriver.getInstance().newAttachmentDAO().addExtension(e);
211         this.extensions();
212     }
213     
214     public void extensionsUpdate() throws Exception JavaDoc
215     {
216         AttachmentDAO am = DataAccessDriver.getInstance().newAttachmentDAO();
217         
218         // Check for records to delete
219
String JavaDoc[] delete = this.request.getParameterValues("delete");
220         List JavaDoc deleteList = new ArrayList JavaDoc();
221         if (delete != null) {
222             deleteList = Arrays.asList(delete);
223             am.removeExtensions(delete);
224         }
225         
226         int total = this.request.getIntParameter("total_records");
227         for (int i = 0; i < total; i++) {
228             if (deleteList.contains(this.request.getParameter("id_" + i))) {
229                 continue;
230             }
231             
232             AttachmentExtension e = new AttachmentExtension();
233             e.setAllow(this.request.getParameter("allow_" + i) != null);
234             e.setComment(this.request.getParameter("comment_" + i));
235             e.setExtension(this.request.getParameter("extension_" + i));
236             e.setExtensionGroupId(this.request.getIntParameter("extension_group_" + i));
237             e.setId(this.request.getIntParameter("id_" + i));
238             e.setUploadIcon(this.request.getParameter("upload_icon_" + i));
239             
240             am.updateExtension(e);
241         }
242         
243         this.extensions();
244     }
245     
246     public void quotaGroupsSave() throws Exception JavaDoc
247     {
248         int total = this.request.getIntParameter("total_groups");
249         AttachmentDAO am = DataAccessDriver.getInstance().newAttachmentDAO();
250         am.cleanGroupQuota();
251         
252         for (int i = 0; i < total; i++) {
253             String JavaDoc l = this.request.getParameter("limit_" + i);
254             if (l == null || l.equals("")) {
255                 continue;
256             }
257             
258             int limitId = Integer.parseInt(l);
259             int groupId = this.request.getIntParameter("group_" + i);
260             
261             if (groupId > 0) {
262                 am.setGroupQuota(groupId, limitId);
263             }
264         }
265         
266         this.quotaLimit();
267     }
268     
269     /**
270      * @see net.jforum.Command#list()
271      */

272     public void list() throws Exception JavaDoc
273     {
274         this.configurations();
275     }
276 }
277
Popular Tags