KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 2003, 2004 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  * This file creation date: Mar 31, 2005 / 11:21:41 AM
40  * The JForum Project
41  * http://www.jforum.net
42  */

43 package net.jforum.view.admin;
44
45 import net.jforum.dao.BannerDAO;
46 import net.jforum.dao.DataAccessDriver;
47 import net.jforum.entities.Banner;
48 import net.jforum.util.I18n;
49 import net.jforum.util.preferences.TemplateKeys;
50
51 /**
52  * ViewHelper class for banner administration.
53  *
54  * @author Samuel Yung
55  * @version $Id: BannerAction.java,v 1.4 2005/07/26 03:05:41 rafaelsteil Exp $
56  */

57 public class BannerAction extends AdminCommand
58 {
59     // Listing
60
public void list() throws Exception JavaDoc
61     {
62         this.context.put("banners",
63             DataAccessDriver.getInstance().newBannerDAO().selectAll());
64         this.setTemplateName(TemplateKeys.BANNER_LIST);
65     }
66
67     // Insert
68
public void insert() throws Exception JavaDoc
69     {
70         this.context.put("action", "insertSave");
71         this.setTemplateName(TemplateKeys.BANNER_INSERT);
72     }
73
74     // Saves a new banner
75
public void insertSave() throws Exception JavaDoc
76     {
77         BannerDAO dao = DataAccessDriver.getInstance().newBannerDAO();
78
79         dao.addNew(getBanner());
80
81         this.list();
82     }
83
84     // Edit a banner
85
public void edit() throws Exception JavaDoc
86     {
87         int bannerId = this.request.getIntParameter("banner_id");
88         BannerDAO dao = DataAccessDriver.getInstance().newBannerDAO();
89
90         this.context.put("banner", dao.selectById(bannerId));
91         this.setTemplateName(TemplateKeys.BANNER_EDIT);
92         this.context.put("action", "editSave");
93     }
94
95     // Save information for an existing banner
96
public void editSave() throws Exception JavaDoc
97     {
98         int bannerId = this.request.getIntParameter("banner_id");
99
100         Banner banner = getBanner();
101         banner.setId(bannerId);
102
103         DataAccessDriver.getInstance().newBannerDAO().update(banner);
104
105         this.list();
106     }
107
108     // Delete a banner
109
public void delete() throws Exception JavaDoc
110     {
111         String JavaDoc bannerId = this.request.getParameter("banner_id");
112         if(bannerId == null)
113         {
114             this.list();
115             return;
116         }
117
118         BannerDAO dao = DataAccessDriver.getInstance().newBannerDAO();
119
120         int id = Integer.parseInt(bannerId);
121         if(dao.canDelete(id))
122         {
123             dao.delete(id);
124         }
125         else
126         {
127             this.context.put("errorMessage",
128                 I18n.getMessage(I18n.CANNOT_DELETE_BANNER));
129         }
130
131         this.list();
132     }
133
134     protected Banner getBanner()
135     {
136         Banner b = new Banner();
137         b.setComment(request.getParameter("comment"));
138         b.setActive(request.getIntParameter("active") == 1);
139         b.setType(Integer.parseInt(request.getParameter("type")));
140         b.setName(request.getParameter("name"));
141         b.setDescription(request.getParameter("description"));
142         b.setWidth(Integer.parseInt(request.getParameter("width")));
143         b.setHeight(Integer.parseInt(request.getParameter("height")));
144         b.setUrl(request.getParameter("url"));
145         b.setPlacement(Integer.parseInt(request.getParameter(
146             "placement")));
147         b.setWeight(Integer.parseInt(request.getParameter("weight")));
148         b.setViews(Integer.parseInt(request.getParameter("views")));
149         b.setClicks(Integer.parseInt(request.getParameter("clicks")));
150
151         return b;
152     }
153 }
154
Popular Tags