KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > module > admin > InsTopic


1
2  /*
3  -- GeiNuke --
4 Copyright (c) 2005 by Roberto Sidoti [geinuke@users.sourceforge.net]
5  http://www.hostingjava.it/-geinuke/
6
7 This file is part of GeiNuke.
8
9     GeiNuke is free software; you can redistribute it and/or modify
10     it under the terms of the GNU General Public License as published by
11     the Free Software Foundation; either version 2 of the License, or
12     (at your option) any later version.
13
14     GeiNuke is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17     GNU General Public License for more details.
18
19     You should have received a copy of the GNU General Public License
20     along with GeiNuke; if not, write to the Free Software
21     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */

23 package com.geinuke.module.admin;
24
25 import java.util.ArrayList JavaDoc;
26
27 import javax.servlet.http.HttpServletRequest JavaDoc;
28 import javax.servlet.http.HttpServletResponse JavaDoc;
29
30 import org.apache.velocity.context.Context;
31
32 import com.geinuke.common.GlobalConfigurationI;
33 import com.geinuke.common.ModuleWidgetI;
34 import com.geinuke.common.NukeModuleI;
35 import com.geinuke.common.UserI;
36 import com.geinuke.middle.ITopicBL;
37 import com.geinuke.module.ModuleWriter;
38 import com.geinuke.servlet.GeiServlet;
39 import com.geinuke.util.NukeResource;
40 import com.geinuke.util.Paginator;
41 import com.geinuke.util.TextUtil;
42 import com.geinuke.vo.ModuleDBVO;
43 import com.geinuke.vo.TopicVO;
44
45
46 public class InsTopic implements ModuleWidgetI{
47
48     protected String JavaDoc checkForm(HttpServletRequest JavaDoc req) throws Exception JavaDoc{
49         String JavaDoc error=null;
50         String JavaDoc name= req.getParameter("topicname");
51         String JavaDoc image= req.getParameter("topicimage");
52         ITopicBL bl=(ITopicBL)GeiServlet.getBL("ITopicBL");
53         
54         if( TextUtil.isEmpty(name )){
55             error="TOPIC_NAME_EMPTY_ERROR";
56         }else if( TextUtil.isEmpty( req.getParameter("topictext")) ){
57             error="TOPICTEXTEMPTY_ERROR";
58         }else if( bl.getTopicByName(name)!=null ){
59             error="TOPIC_NAME_ALREADY_PRESENT_ERROR";
60         }else if( bl.getTopicByImage(image)!=null ){
61             error="TOPIC_IMAGE_ALREADY_PRESENT_ERROR";
62         }
63         
64         return error;
65     }
66     
67     public NukeModuleI handleAction(ModuleDBVO module, Context ctx,HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res, UserI user, GlobalConfigurationI gConf) throws Exception JavaDoc {
68         
69         String JavaDoc moduleTempName=null,error=null;
70         ArrayList JavaDoc files=null,topics=null;
71         String JavaDoc path=GeiServlet.getNukePath()+"/images/topics/";
72         String JavaDoc name=null,text=null,image=null;
73                 
74         error=checkForm(req);
75         ITopicBL tbl=(ITopicBL)GeiServlet.getBL("ITopicBL");
76         if(error==null){
77             name= TextUtil.normString( req.getParameter("topicname") );
78             text= TextUtil.normString( req.getParameter("topictext") );
79             image=TextUtil.normString( req.getParameter("topicimage") );
80             TopicVO t=new TopicVO();
81             t.setName(name);
82             t.setText(text);
83             t.setImage(image);
84             t.setTopicType(TopicVO.TOPIC_NEWS);
85             tbl.insTopic(t);
86         }else{
87             name= TextUtil.normString( req.getParameter("topicname") );
88             text= TextUtil.normString( req.getParameter("topictext") );
89             image=TextUtil.normString( req.getParameter("topicimage") );
90             TopicVO t=new TopicVO();
91             t.setName(name);
92             t.setText(text);
93             t.setImage(image);
94             ctx.put("topic",t);
95             ctx.put("errors",ctx);
96             ctx.put("error",error);
97         }
98         
99         files=NukeResource.getFiles(path);
100         topics=tbl.getAllTopics(TopicVO.TOPIC_NEWS);
101         
102         String JavaDoc pag=req.getParameter("wp");
103         Paginator pager=new Paginator(topics,5,"Admin.jhtm?"+req.getQueryString());
104         if(pag!=null){
105             topics=pager.getPage(Integer.parseInt(pag));
106         }else{
107             topics=pager.getPage(1);
108         }
109         ctx.put("pag",pager);
110         
111         ctx.put("topics",topics);
112         ctx.put("images",files);
113         
114         moduleTempName=gConf.getModulePage(module.getName(),req);
115         return ModuleWriter.fill(ctx,module,moduleTempName);
116         
117     }
118
119 }
Popular Tags