KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > module > admin > dbmodule > EditLinkModule


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

22 package com.geinuke.module.admin.dbmodule;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26
27 import org.apache.velocity.context.Context;
28
29 import com.geinuke.common.EditorFactory;
30 import com.geinuke.common.GlobalConfigurationI;
31 import com.geinuke.common.NukeModuleI;
32 import com.geinuke.common.UserI;
33 import com.geinuke.middle.IModuleBL;
34 import com.geinuke.module.StaticModule;
35 import com.geinuke.servlet.GeiServlet;
36 import com.geinuke.util.TextUtil;
37 import com.geinuke.vo.ModuleDBVO;
38
39
40 public class EditLinkModule extends StaticModule{
41     
42     
43     protected String JavaDoc check(HttpServletRequest JavaDoc req,IModuleBL mbl,boolean flag) throws Exception JavaDoc{
44         String JavaDoc error=null;
45         String JavaDoc text=req.getParameter("text");
46         String JavaDoc nameAndTitle=req.getParameter("name");
47         if(TextUtil.isEmpty(text)){
48             error="MNO_EMPTY_TEXT_LABEL";
49         }else if(TextUtil.isEmpty(nameAndTitle)){
50             error="MNO_EMPTY_NAME_LABEL";
51         }else if(flag && (mbl.getModule(nameAndTitle)!=null) ){
52             error="MNAME_ALREADY_EXISTS";
53         }
54         return error;
55     }
56     
57     protected ModuleDBVO get(HttpServletRequest JavaDoc req){
58         String JavaDoc text=req.getParameter("text");
59         String JavaDoc name=req.getParameter("name");
60         ModuleDBVO md=new ModuleDBVO();
61         if(name!=null)
62             md.setName(name.trim().replace(' ','_'));
63         md.setTitle(name);
64         String JavaDoc op=req.getParameter("op");
65         if(op!=null && op.lastIndexOf("Link")>=0)
66             text=ModuleDBVO.LINK_MODULE+text;
67         
68         md.setContent(text);
69         md.setDbStored(true);
70         md.setActive(true);
71         md.setPos(0);
72         md.setRoleLevel(1000);
73         md.setSkin(0);
74         md.setWeight(0);
75         return md;
76     }
77     
78     public NukeModuleI handleAction(ModuleDBVO module, Context ctx,HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res, UserI user, GlobalConfigurationI gConf) throws Exception JavaDoc {
79         IModuleBL mbl=(IModuleBL)GeiServlet.getBL("IModuleBL");
80         GeiServlet.intLog("EditDBModule.handleAction(...), A");
81         if(req.getParameter("op").equals("insLinkModule")){
82             String JavaDoc error=null;
83             ModuleDBVO bl=this.get(req);
84             if( (error=this.check(req,mbl,true) )==null){
85                 mbl.insertDBStoredModule(bl);
86                 //bl=mbl.getModule(bl.getTitle());
87
bl=mbl.getModule(bl.getName());
88                 bl.setContent(bl.getContent().substring(ModuleDBVO.LINK_MODULE.length()));
89                 ctx.put("moduleY",bl);
90                 ctx.put("msgOK","y");
91                 ctx.put("action","updLinkModule");
92                 
93             }else{
94                 ctx.put("action","insLinkModule");
95                 bl.setContent(bl.getContent().substring(ModuleDBVO.LINK_MODULE.length()));
96                 ctx.put("moduleY",bl);
97                 ctx.put("errors",ctx);
98                 ctx.put("error",error);
99             }
100             
101         }else if( req.getParameter("op").equals("updLinkModule") ){
102             String JavaDoc error=null;
103             int mid=Integer.parseInt(req.getParameter("mid")) ;
104             ModuleDBVO bl1=mbl.getModuleByID(mid);
105             if(! bl1.isDbStored()){
106                 res.sendRedirect("Error.jhtm");
107             }
108             ModuleDBVO bl=this.get(req);
109             bl1.setName(bl.getName());
110             bl1.setTitle(bl.getName());
111             //if(req.getParameter("op").equals("updLinkModule"))
112
//bl1.setContent(ModuleDBVO.LINK_MODULE+bl.getContent());
113
//else
114
bl1.setContent(bl.getContent());
115             GeiServlet.intLog("EditDBModule.handleAction(...), B");
116             if( (error=this.check(req,mbl,false) )==null){
117                 GeiServlet.intLog("EditDBModule.handleAction(...), C"+bl1.getContent());
118                 mbl.updateDBModule(bl1);
119                 bl1.setContent(bl1.getContent().substring(ModuleDBVO.LINK_MODULE.length()));
120                 ctx.put("moduleY",bl1);
121                 ctx.put("msgOK","y");
122             }else{
123                 ctx.put("moduleY",bl1);
124                 ctx.put("errors",ctx);
125                 ctx.put("error",error);
126             }
127             GeiServlet.intLog("EditDBModule.handleAction(...), D"+error);
128             ctx.put("action","updLinkModule");
129         }else if(req.getParameter("op").equals("updLinkModuleStart")){
130             
131             int mid=Integer.parseInt(req.getParameter("mid")) ;
132             ModuleDBVO bl1=mbl.getModuleByID(mid);
133             GeiServlet.intLog("EditDBModule.handleAction(...), E "+bl1.getName());
134             GeiServlet.intLog("EditDBModule.handleAction(...), E "+bl1.getTitle());
135             GeiServlet.intLog("EditDBModule.handleAction(...), E "+bl1.getContent());
136             bl1.setContent(bl1.getContent().substring(ModuleDBVO.LINK_MODULE.length()));
137             ctx.put("moduleY",bl1);
138             ctx.put("action","updLinkModule");
139             
140         }else {
141             ModuleDBVO bl=this.get(req);
142             bl.setContent("");
143             bl.setName("");
144             bl.setTitle("");
145             ctx.put("moduleY",bl);
146             ctx.put("action","insLinkModule");
147         }
148         EditorFactory ef=new EditorFactory(req,new Object JavaDoc());
149         ctx.put("factory",ef);
150         
151         
152         return super.handleAction(module,ctx,req,res,user,gConf);
153     }
154     
155     
156
157 }
158
159
Popular Tags