KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > module > admin > disablednews > AdminEditDisabledNews


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.disablednews;
24
25 import java.util.ArrayList JavaDoc;
26 import java.util.Locale JavaDoc;
27
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29 import javax.servlet.http.HttpServletResponse JavaDoc;
30
31 import org.apache.velocity.context.Context;
32
33 import com.geinuke.common.EditorFactory;
34 import com.geinuke.common.GlobalConfigurationI;
35 import com.geinuke.common.ModuleWidgetI;
36 import com.geinuke.common.NukeModuleI;
37 import com.geinuke.common.PageTool;
38 import com.geinuke.common.UserI;
39 import com.geinuke.middle.ICategoryBL;
40 import com.geinuke.middle.INewsBL;
41 import com.geinuke.middle.ITopicBL;
42 import com.geinuke.middle.IUserBL;
43 import com.geinuke.module.ModuleWriter;
44 import com.geinuke.servlet.GeiServlet;
45 import com.geinuke.util.NukeResource;
46 import com.geinuke.util.TextUtil;
47 import com.geinuke.vo.CategoryVO;
48 import com.geinuke.vo.ModuleDBVO;
49 import com.geinuke.vo.NewsVO;
50 import com.geinuke.vo.TopicVO;
51
52
53 public class AdminEditDisabledNews implements ModuleWidgetI{
54
55     
56     
57     protected String JavaDoc checkErrors(HttpServletRequest JavaDoc req){
58         String JavaDoc error=null;
59         if( TextUtil.isEmpty(req.getParameter("title")) ){
60             error="EMPTY_TITLE_ERROR";
61         }else if( TextUtil.isEmpty(req.getParameter("bodytext")) ){
62             error="EMPTY_BODYTEXT_ERROR";
63         }else if( TextUtil.isEmpty(req.getParameter("headtext")) ){
64             error="EMPTY_HEADTEXT_ERROR";
65         }
66         return error;
67     }
68     
69     protected NewsVO getNewsVO(HttpServletRequest JavaDoc req) throws Exception JavaDoc{
70         NewsVO ne=null;
71         String JavaDoc topic=null;
72         String JavaDoc cat=null;
73         ne=new NewsVO();
74         ne.setTitle( req.getParameter("title") );
75         ne.setBodyText( req.getParameter("bodytext") );
76         ne.setHeadText( req.getParameter("headtext") );
77         ne.setTime( System.currentTimeMillis());
78         topic=req.getParameter("topic");
79         cat=req.getParameter("cat");
80         if(!topic.equals("")){
81             TopicVO t=null;
82             ITopicBL tbl=(ITopicBL)GeiServlet.getBL("ITopicBL");
83             t=tbl.getTopic( Integer.parseInt(topic) );
84             ne.getTopics().add(t);
85         }
86         if(cat!=null && !cat.equals("")){
87             CategoryVO ca=null;
88             ca=new CategoryVO();
89             ca.setCatType(CategoryVO.CAT_NEWS);
90             ca.setCatId( Integer.parseInt(cat) );
91             ICategoryBL cbl=(ICategoryBL)GeiServlet.getBL("ICategoryBL");
92             ca=cbl.getCategoryById(ca);
93             ne.getCategories().add(ca);
94         }
95         return ne;
96     }
97     
98     protected void singleActivation(HttpServletResponse JavaDoc res,HttpServletRequest JavaDoc req) throws Exception JavaDoc{
99         //String actNews=req.getParameter("actNews");
100
String JavaDoc nid=req.getParameter("nid");
101         int uid= Integer.parseInt( req.getParameter("uid") );
102         int id=Integer.parseInt(nid);
103         INewsBL bl=(INewsBL)GeiServlet.getBL("INewsBL");
104         NewsVO n=getNewsVO(req);
105         n.setNId(id);
106         n.setUId( uid);
107         n.setEnabled(true);
108         //GeiServlet.intLog("@@AdminEditDisabledNews.singleActivation(...), n.title="+n.getTitle()+" n.id="+n.getNId());
109
bl.updateNews(n);
110         //GeiServlet.intLog("@@AdminEditDisabledNews.singleActivation(...), AFTER");
111
res.sendRedirect("Admin.jhtm?op=admindisnews");
112         
113     }
114     
115     
116     protected NewsVO checkAndGetNewsVO(HttpServletResponse JavaDoc res,HttpServletRequest JavaDoc req,Context ctx) throws Exception JavaDoc{
117         String JavaDoc op=req.getParameter("op");
118         String JavaDoc nid=req.getParameter("nid");
119         NewsVO n=null;
120         String JavaDoc error=null;
121         error=checkErrors(req);
122         if(op!=null && nid!=null && op.equals("actNews")){
123             
124             if(error!=null){
125                 n=this.getNewsVO(req);
126                 n.setNId( Integer.parseInt(nid) );
127                 ctx.put("errors",ctx);
128                 ctx.put("error",error);
129             }else{
130                 GeiServlet.intLog("AdminEditDisabledNews.checkAndGetNewsVO(...), before this.singleActivation(res,req);");
131                 this.singleActivation(res,req);
132                 GeiServlet.intLog("AdminEditDisabledNews.checkAndGetNewsVO(...), AFTER this.singleActivation(res,req);");
133             
134             }
135             
136         }else{
137             INewsBL bl=(INewsBL)GeiServlet.getBL("INewsBL");
138             n=bl.getNewsByNId(Integer.parseInt(nid));
139         }
140         
141         return n;
142     }
143     
144     
145     
146     
147     
148     public NukeModuleI handleAction(ModuleDBVO module, Context ctx,HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res, UserI user, GlobalConfigurationI gConf) throws Exception JavaDoc {
149         GeiServlet.intLog("AdminEditDisabledNews.handleAction(...), start ");
150         
151         NukeModuleI mod=null;
152         String JavaDoc moduleTempName=null;
153         NewsVO n=null;
154         ArrayList JavaDoc list=null;
155         int nid=-1;
156         moduleTempName=gConf.getModulePage(module.getName(),req);
157         //nid= Integer.parseInt( req.getParameter("nid") );
158
//n=NewsBL.singleton().getNewsByNId(nid);
159
//GeiServlet.intLog("AdminEditDisabledNews.handleAction(...), before checkAndGetNewsVO(...)");
160
n=this.checkAndGetNewsVO(res,req,ctx);
161         //GeiServlet.intLog("AdminEditDisabledNews.handleAction(...), after checkAndGetNewsVO(...)");
162

163         try{
164             IUserBL ubl=(IUserBL)GeiServlet.getBL("IUserBL");
165             int uid=n.getUId();
166             UserI wr=ubl.getUserByID(uid);
167             //GeiServlet.intLog("AdminEditDisabledNews.handleAction(...), after UserBL.singleton().getUserByID(n.getUId())");
168
ArrayList JavaDoc topics=null,categories=null;
169             ITopicBL tbl=(ITopicBL)GeiServlet.getBL("ITopicBL");
170             topics=tbl.getAllTopics(TopicVO.TOPIC_NEWS);
171             ICategoryBL cbl=(ICategoryBL)GeiServlet.getBL("ICategoryBL");
172             categories=cbl.getCategoriesByCatType(CategoryVO.CAT_NEWS);
173                     
174             
175             EditorFactory ef=new EditorFactory(req,n);
176             ctx.put("categories",categories);
177             ctx.put("topics",topics);
178             ctx.put("writer",wr);
179             ctx.put("factory",ef);
180             Locale JavaDoc lo=NukeResource.getLocale(req,res);
181             
182             ctx.put("pageTool",new PageTool(lo));
183             
184             ctx.put("news",n);
185             mod=ModuleWriter.fill(ctx,module,moduleTempName);
186         }catch(Throwable JavaDoc t){
187             
188         }
189         return mod;
190     }
191
192 }
193
Popular Tags