KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > action > NukeAction


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.action;
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.VelocityContext;
32 import org.apache.velocity.context.Context;
33
34 import com.geinuke.block.BlockContainer;
35 import com.geinuke.block.BlockWriter;
36 import com.geinuke.block.StaticBlock;
37 import com.geinuke.common.BlockWidgetI;
38 import com.geinuke.common.GlobalConfigurationI;
39 import com.geinuke.common.ModuleWidgetI;
40 import com.geinuke.common.NukeBlockI;
41 import com.geinuke.common.PluginHandler;
42 import com.geinuke.common.UserI;
43 import com.geinuke.middle.IBlockBL;
44 import com.geinuke.middle.IModuleBL;
45 import com.geinuke.module.DBStoredModule;
46 import com.geinuke.module.StaticModule;
47 import com.geinuke.servlet.GeiServlet;
48 import com.geinuke.util.NukeResource;
49 import com.geinuke.util.TextUtil;
50 import com.geinuke.util.servlet.GeiHttpServletRequest;
51 import com.geinuke.vo.BlockDBVO;
52 import com.geinuke.vo.ModuleDBVO;
53 import com.geinuke.vo.NukeBlockVO;
54 import com.geinuke.vo.NukeModuleVO;
55 import com.geinuke.vo.PortalCFGVO;
56 import com.magic.servlet.action.MagicAction;
57
58
59
60
61 public class NukeAction extends MagicAction {
62     /**
63      *
64      * @return
65      */

66     protected GeiServlet getGeiServlet(){
67         return (GeiServlet)this.ser;
68     }
69     
70     
71     /**
72      * @param ctx
73      * @param req
74      * @param res
75      * @return String to retreive template file name
76      */

77     protected String JavaDoc getTemplateString(Context ctx, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) throws Exception JavaDoc {
78         String JavaDoc resp=null;
79         
80         GeiServlet servlet=getGeiServlet();
81         UserI user=GeiServlet.getUser(req);
82         GlobalConfigurationI gConf=servlet.getGConfiguration(req);
83         resp=this.exeAction(ctx,req,res,user,gConf);
84         int i=1;
85         
86         return resp;
87     }
88     
89     protected ArrayList JavaDoc getModuleDBVO(HttpServletRequest JavaDoc req,IModuleBL mbl)throws Exception JavaDoc{
90         //GeiServlet.intLog("NukeAction.getModuleDBVO(...), START");
91
ArrayList JavaDoc list=null;
92         
93         list=new ArrayList JavaDoc();
94         ModuleDBVO currentModule=null;
95         //try{
96
//String moduleName=req.getParameter("module");
97
String JavaDoc moduleName=this.getGeiServlet().getModule(req);
98             
99             GeiServlet.intLog("NukeAction.getModuleDBVO(...), First moduleName "+moduleName);
100             //GeiServlet.intLog("NukeAction.getModuleDBVO(...), mbl "+mbl);
101
UserI us=(UserI)req.getSession(true).getAttribute("user");
102             if(moduleName==null || moduleName.equalsIgnoreCase("geinuke")){
103                 //GeiServlet.intLog("NukeAction.getModuleDBVO(...), A");
104
//currentModule=gConf.getDefaultModule();
105
//currentModule=mbl.getDefModule();
106
list=mbl.getModulesInHomePage(us);
107                 currentModule=(ModuleDBVO)list.get(list.size()-1);
108                 
109             }else{
110                 //GeiServlet.intLog("NukeAction.getModuleDBVO(...), B");
111
currentModule=mbl.getModule(moduleName);
112                 list.add(currentModule);
113             }
114             
115             
116             if( us.getRole().getLevela()< currentModule.getRoleLevel() ){
117                 GeiServlet.intLog("NukeAction.getModuleDBVO(...), adding NotAuth Module instead of "+currentModule.getName());
118                 currentModule.setName("NotAuth");
119                 currentModule.setActive(true);
120                 currentModule.setDbStored(false);
121                 currentModule.setWidth(0);
122                 //list.add(currentModule);
123

124             }
125             
126             
127             if(!currentModule.isActive() ){
128                 GeiServlet.intLog("NukeAction.getModuleDBVO(...), adding NotActive Module instead of "+currentModule.getName());
129                 currentModule.setName("NotActive");
130                 currentModule.setActive(true);
131                 currentModule.setDbStored(false);
132                 //list.add(currentModule);
133

134             }
135             
136             
137             GeiServlet.intLog("NukeAction.getModuleDBVO(...), Before moduleName "+moduleName);
138         /*}catch(Exception e){
139             GeiServlet.intLog("NukeAction.getModuleDBVO(...), error "+e.toString());
140             currentModule=new ModuleDBVO();
141             currentModule.setName("Error");
142             currentModule.setActive(true);
143             e.printStackTrace();
144         }*/

145         
146         
147         return list;
148     }
149     
150     protected ArrayList JavaDoc buildModule(Context ctx,HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res, UserI user,
151             GlobalConfigurationI gConf)throws Exception JavaDoc{
152         ModuleWidgetI moduleW=null;
153         NukeModuleVO nk=null;
154         ModuleDBVO currentModule=null;
155         IModuleBL mbl=null;
156         Locale JavaDoc lo=NukeResource.getLocale(req,res);
157         ArrayList JavaDoc list=null,NMVList=null;
158         list=new ArrayList JavaDoc();
159         NMVList=new ArrayList JavaDoc();
160         //GeiServlet.intLog("NukeAction.buildModule(...), locale "+lo.getLanguage());
161
ctx.put("LOCALE",lo);
162         try{
163             
164             mbl=(IModuleBL)GeiServlet.getBL("IModuleBL");
165             String JavaDoc op=req.getParameter("op");
166             
167         
168             //GeiServlet.intLog("$$$$$$$$$$$$$$ op="+op);
169
list=this.getModuleDBVO(req,mbl);
170             for(int i=0;i<list.size();i++){
171                 currentModule=(ModuleDBVO)list.get(i);
172                 if(currentModule.isLink()){
173                     String JavaDoc mn=TextUtil.getModuleNameByLinkModule(currentModule.getContent());
174                     GeiHttpServletRequest req1=new GeiHttpServletRequest(req,currentModule.getContent(),true);
175                     currentModule=mbl.getModule(mn);
176                     op=req1.getParameter("op");
177                     moduleW=gConf.getModuleWidget(currentModule.getName(),op);
178                     req=req1;
179                     op="";
180                 }else if(currentModule.isDbStored()){
181                     moduleW=new DBStoredModule();
182                 }else{
183                     if(req instanceof GeiHttpServletRequest)
184                         req=((GeiHttpServletRequest)req).req;
185                     moduleW=gConf.getModuleWidget(currentModule.getName(),op);
186                 }
187                 nk=(NukeModuleVO)moduleW.handleAction(currentModule,ctx,req,res,user,gConf);
188                 NMVList.add(nk);
189             }
190         }catch(Exception JavaDoc e){
191             
192             if(1==1) {
193                 GeiServlet.errLog(e.toString(),e);
194                 //throw e;
195

196             }
197             GeiServlet.intLog("NukeAction.getModuleDBVO(...), error "+e.toString());
198             currentModule=new ModuleDBVO();
199             currentModule.setName("Error");
200             currentModule.setActive(true);
201             moduleW=gConf.getModuleWidget(currentModule.getName(),"");
202             
203             try{
204                 nk=(NukeModuleVO)moduleW.handleAction(currentModule,ctx,req,res,user,gConf);
205                 NMVList.add(nk);
206             }catch(Exception JavaDoc ee){}
207             e.printStackTrace();
208         }
209         return NMVList;
210     }
211     
212     
213     
214     
215     protected String JavaDoc exeAction(Context ctx, HttpServletRequest JavaDoc req,
216             HttpServletResponse JavaDoc res,UserI user,GlobalConfigurationI gConf) throws Exception JavaDoc {
217         //GeiServlet.intLog("NukeAction.exeAction(...), START");
218
PortalCFGVO po=null;
219         BlockDBVO tmpBlock=null;
220         NukeBlockI block=null;
221         BlockWidgetI blockW=null;
222         ArrayList JavaDoc blocksDB=null,blocksPL=null;
223         BlockContainer cont=null;
224         NukeBlockVO blockPL=null;
225         NukeModuleVO modulePL=null;
226         ArrayList JavaDoc modList=null;
227         VelocityContext vc=null;
228         IBlockBL bbl=null;
229         String JavaDoc op=null;
230         op=req.getParameter("op");
231         bbl=(IBlockBL)GeiServlet.getBL("IBlockBL");
232         blocksPL=new ArrayList JavaDoc();
233                 
234         vc=new VelocityContext();
235         vc.put("req",req);
236         
237         modList=this.buildModule(vc,req,res,user,gConf);
238         ctx.put("NOTEMPLATE",vc.get("NOTEMPLATE"));
239         
240         Locale JavaDoc lo=(Locale JavaDoc)vc.get("LOCALE");
241         //lo user puo essere cambiato nel module
242
user=GeiServlet.getUser(req);
243         PluginHandler.exec(req,res,gConf);
244         blocksDB=bbl.getBlocksForUser(user);
245         GeiServlet.fixStyle(req,ctx);
246         for(int i=0;i<blocksDB.size();i++){
247             vc=new VelocityContext();
248             vc.put("LOCALE",lo);
249             tmpBlock=(BlockDBVO)blocksDB.get(i);
250             if(tmpBlock.isDbStored()){
251                 blockW=new StaticBlock();
252             }else{
253                 blockW=gConf.getBlockWidget(tmpBlock.getName());
254             }
255             blockW.fillBlock(tmpBlock,vc,req,res,user,gConf);
256             blockPL=(NukeBlockVO)BlockWriter.fill(vc,tmpBlock);
257             blocksPL.add(blockPL);
258         }
259         cont=new BlockContainer();
260         cont.addBlocks(blocksPL);
261         
262         
263         
264         ctx.put("portalCFG",req.getSession(true).getAttribute("portalCFG"));
265         ctx.put("allBlocks",cont);
266         ctx.put("modulePL",modList.get(0));
267         ctx.put("modulesPL",modList);
268         
269         return this.getGeiServlet().getModuleTemplateFile(req);
270     }
271     
272     
273 }
274
Popular Tags