KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > module > forum > InsForumTopic


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

24 package com.geinuke.module.forum;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Locale JavaDoc;
28
29 import javax.servlet.http.HttpServletRequest JavaDoc;
30 import javax.servlet.http.HttpServletResponse JavaDoc;
31
32 import org.apache.velocity.context.Context;
33
34 import com.geinuke.common.EditorFactory;
35 import com.geinuke.common.GlobalConfigurationI;
36 import com.geinuke.common.ModuleWidgetI;
37 import com.geinuke.common.NukeModuleI;
38 import com.geinuke.common.PageTool;
39 import com.geinuke.common.UserI;
40 import com.geinuke.middle.IForumBL;
41 import com.geinuke.middle.ITopicBL;
42 import com.geinuke.module.ModuleWriter;
43 import com.geinuke.servlet.GeiServlet;
44 import com.geinuke.util.NukeResource;
45 import com.geinuke.util.ServletUtil;
46 import com.geinuke.util.TextUtil;
47 import com.geinuke.vo.ForumVO;
48 import com.geinuke.vo.ModuleDBVO;
49 import com.geinuke.vo.TopicVO;
50
51
52 public class InsForumTopic implements ModuleWidgetI{
53
54     protected String JavaDoc checkErrors(HttpServletRequest JavaDoc req){
55         String JavaDoc error=null;
56         if( TextUtil.isEmpty(req.getParameter("subject")) ){
57             error="EMPTY_SUBJECT_ERROR";
58         }else if( TextUtil.isEmpty(req.getParameter("topictext")) ){
59             error="EMPTY_TOPICTEXT_ERROR";
60         }
61         return error;
62     }
63     
64     protected TopicVO getTopicVO(HttpServletRequest JavaDoc req,UserI user){
65         TopicVO to=null;
66         to=new TopicVO();
67         to.setTopicType(TopicVO.TOPIC_FORUMS);
68         to.setName(req.getParameter("subject"));
69         to.setELink(user.getId());
70         to.setText(req.getParameter("topictext"));
71         to.setCreationTime(System.currentTimeMillis());
72         return to;
73     }
74     
75     
76     public NukeModuleI handleAction(ModuleDBVO module, Context ctx,HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res, UserI user, GlobalConfigurationI gConf) throws Exception JavaDoc {
77         String JavaDoc moduleTempName=null,error=null;
78         ArrayList JavaDoc topicsTID=new ArrayList JavaDoc();
79         int fid=Integer.parseInt( req.getParameter("fid") );
80         TopicVO to=null;
81         ForumVO forum=null;
82         IForumBL fbl=(IForumBL)GeiServlet.getBL("IForumBL");
83         forum=fbl.getForumByFId(fid);
84         if(forum.getFState()<3){
85             error=this.checkErrors(req);
86             to=this.getTopicVO(req,user);
87             
88             if(error==null){
89                 ITopicBL tbl=(ITopicBL)GeiServlet.getBL("ITopicBL");
90                 tbl.insForumTopic(to,fid);
91                 res.sendRedirect("Forum.jhtm?op=showSF&fid="+fid);
92                 ServletUtil.setVisitedTopic(req,to.getTId());
93             }else{
94                 
95                 EditorFactory ef=new EditorFactory(req,null);
96                 Locale JavaDoc lo=NukeResource.getLocale(req,res);
97                 ctx.put("topic",to);
98                 ctx.put("errors",ctx);
99                 ctx.put("error",error);
100                 ctx.put("factory",ef);
101                 ctx.put("pageTool",new PageTool(lo));
102                 ctx.put("forum",forum);
103             }
104         }else{
105             res.sendRedirect("ErrorForum.jhtm");
106         }
107         moduleTempName=gConf.getModulePage(module.getName(),req);
108         return ModuleWriter.fill(ctx,module,moduleTempName);
109     }
110
111 }
112
Popular Tags