KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > module > admin > dbblock > EditDBBlock


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.dbblock;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.Locale 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.EditorFactory;
33 import com.geinuke.common.GlobalConfigurationI;
34 import com.geinuke.common.NukeModuleI;
35 import com.geinuke.common.PageTool;
36 import com.geinuke.common.UserI;
37 import com.geinuke.middle.IBlockBL;
38 import com.geinuke.middle.IUserBL;
39 import com.geinuke.module.StaticModule;
40 import com.geinuke.servlet.GeiServlet;
41 import com.geinuke.util.NukeResource;
42 import com.geinuke.util.TextUtil;
43 import com.geinuke.vo.BlockDBVO;
44 import com.geinuke.vo.ModuleDBVO;
45 import com.geinuke.vo.RoleVO;
46 import com.geinuke.vo.UserVO;
47
48 public class EditDBBlock extends StaticModule{
49     
50     
51     protected String JavaDoc check(HttpServletRequest JavaDoc req,IBlockBL bbl,boolean flag) throws Exception JavaDoc{
52         String JavaDoc error=null;
53         String JavaDoc text=req.getParameter("text");
54         String JavaDoc nameAndTitle=req.getParameter("name");
55         if(TextUtil.isEmpty(text)){
56             error="NO_EMPTY_TEXT_LABEL";
57         }else if(TextUtil.isEmpty(nameAndTitle)){
58             error="NO_EMPTY_NAME_LABEL";
59         }else if(flag && (bbl.getBlockByName(nameAndTitle)!=null) ){
60             error="NAME_ALREADY_EXISTS";
61         }
62         return error;
63     }
64     
65     protected BlockDBVO get(HttpServletRequest JavaDoc req){
66         String JavaDoc text=req.getParameter("text");
67         String JavaDoc name=req.getParameter("name");
68         BlockDBVO bl=null;
69         bl=new BlockDBVO();
70         bl.setTitle(name);
71         bl.setName(name);
72         bl.setContent(text);
73         bl.setDbStored(true);
74         bl.setActive(true);
75         bl.setPos(0);
76         bl.setRoleLevel(1000);
77         bl.setSkin(0);
78         bl.setWeight(0);
79         return bl;
80     }
81     
82     public NukeModuleI handleAction(ModuleDBVO module, Context ctx,HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res, UserI user, GlobalConfigurationI gConf) throws Exception JavaDoc {
83         IBlockBL bbl=(IBlockBL)GeiServlet.getBL("IBlockBL");
84         GeiServlet.intLog("EditDBBlock.handleAction(...), A");
85         if(req.getParameter("op").equals("insDBBlock")){
86             String JavaDoc error=null;
87             BlockDBVO bl=this.get(req);
88             if( (error=this.check(req,bbl,true) )==null){
89                 bbl.insertDBStoredBlock(bl);
90                 
91                 ctx.put("block",bl);
92                 ctx.put("msgOK","y");
93                 ctx.put("action","updDBBlock");
94                 
95             }else{
96                 ctx.put("action","insDBBlock");
97                 ctx.put("block",bl);
98                 ctx.put("errors",ctx);
99                 ctx.put("error",error);
100             }
101             
102         }else if(req.getParameter("op").equals("updDBBlock")){
103             String JavaDoc error=null;
104             int bid=Integer.parseInt(req.getParameter("bid")) ;
105             BlockDBVO bl1=bbl.getBlock(bid);
106             if(! bl1.isDbStored()){
107                 res.sendRedirect("Error.jhtm");
108             }
109             BlockDBVO bl=this.get(req);
110             bl1.setName(bl.getName());
111             bl1.setTitle(bl.getName());
112             bl1.setContent(bl.getContent());
113             GeiServlet.intLog("EditDBBlock.handleAction(...), B");
114             if( (error=this.check(req,bbl,false) )==null){
115                 GeiServlet.intLog("EditDBBlock.handleAction(...), C"+bl1.getContent());
116                 bbl.updateDBBlock(bl1);
117                 ctx.put("block",bl1);
118                 ctx.put("msgOK","y");
119             }else{
120                 ctx.put("block",bl1);
121                 ctx.put("errors",ctx);
122                 ctx.put("error",error);
123             }
124             GeiServlet.intLog("EditDBBlock.handleAction(...), D"+error);
125             ctx.put("action","updDBBlock");
126         }else if(req.getParameter("op").equals("updDBBlockStart")){
127             
128             int bid=Integer.parseInt(req.getParameter("bid")) ;
129             BlockDBVO bl1=bbl.getBlock(bid);
130             ctx.put("block",bl1);
131             ctx.put("action","updDBBlock");
132             
133         }else {
134             BlockDBVO bl=this.get(req);
135             bl.setContent("");
136             bl.setName("");
137             bl.setTitle("");
138             ctx.put("block",bl);
139             ctx.put("action","insDBBlock");
140         }
141         EditorFactory ef=new EditorFactory(req,new Object JavaDoc());
142         ctx.put("factory",ef);
143         
144         
145         return super.handleAction(module,ctx,req,res,user,gConf);
146     }
147     
148     
149
150 }
151
152
Popular Tags