KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > raptus > owxv3 > modules > categories > EACategoryEditAction


1 /*
2  * eAdmin/OWX
3  * Copyright (C) 1996-2003 OWX-Project Team <owx-team@gmx.net>
4  */

5
6 package com.raptus.owxv3.modules.categories;
7
8 import java.sql.SQLException JavaDoc;
9 import java.util.Locale JavaDoc;
10
11 import javax.servlet.http.HttpServletRequest JavaDoc;
12
13 import org.apache.struts.action.*;
14
15 import com.raptus.owxv3.*;
16 import com.raptus.owxv3.api.*;
17
18 /**
19  *
20  * <hr>
21  * <table width="100%" border="0">
22  * <tr>
23  * <td width="24%"><b>Filename</b></td><td width="76%">EACategoryEditAction.java</td>
24  * </tr>
25  * <tr>
26  * <td width="24%"><b>Author</b></td><td width="76%">REEA</td>
27  * </tr>
28  * <tr>
29  * <td width="24%"><b>Date</b></td><td width="76%">10th of December 2001</td>
30  * </tr>
31  * </table>
32  * <hr>
33  * <table width="100%" border="0">
34  * <tr>
35  * <td width="24%"><b>Date / Author</b></td><td width="76%"><b>Changes</b></td>
36  * </tr>
37  * </table>
38  * <table width="100%" border="0">
39  * <tr>
40  * <td>This class is the action class of the edit category screen.</td>
41  * </tr>
42  * </table>
43  * <hr>
44  */

45
46 //public class EACategoryEditAction extends VModuleAuthAction
47
public class EACategoryEditAction extends VModuleRoleAction
48 {
49     /**
50      *Method for populating the corresponding EACategoryEditBean fields.
51      *This method can be called:
52      * 1. with action save to save a category <br>
53      * 2. with paramater catid to edit an existing category <br>
54      * 3. with parameter parentid to create a new category with parent parentid <br>
55      */

56     public String JavaDoc dispatchVModuleElement(HttpServletRequest JavaDoc request,
57                                          String JavaDoc element,
58                                          org.apache.struts.action.ActionForm form,
59                                          VModule vm,
60                                          com.raptus.owxv3.api.usermgr.User user)
61     {
62
63         XMLConfigManager cm = XMLConfigManager.getInstance();
64         
65         if(element.compareToIgnoreCase(CategoryConstants.ELEMENT_EDIT) == 0)
66         {
67             EACategoryEditBean editbean=(EACategoryEditBean) form;
68
69             if(!editbean.isInitialized())
70             {
71                 //setting list of vmodules
72
//editbean.setVmodules( vm.getStringArrayProperty(CategoryConstants.VMODULE_PROPERTY_VMLIST) );
73
editbean.setVmodules(cm.getStringArrayByTree("virtualhost/vmodules/vmodule?name="+vm.getIdentification()+"/properties/property?name=vmodulelist", "value"));
74
75                 //setting locales
76
editbean.setCurrLocale( user.getLocale() );
77                 String JavaDoc[] locales=vm.getLocales();
78                 Locale JavaDoc[] availLocales = new Locale JavaDoc[locales.length];
79
80                 for(int i = 0; i < locales.length; i ++)
81                 {
82                     PairOfObjects po = LocaleManager.stripLocaleString(locales[i]);
83                     if(po != null && po.isValid())
84                     availLocales[i] = new Locale JavaDoc((String JavaDoc) po.getObjectOne(), (String JavaDoc) po.getObjectTwo());
85                 }
86
87
88                 editbean.setLocales(availLocales);
89
90             }//end if
91

92
93             String JavaDoc action="";
94
95
96              //Checking what kind of action should perform
97

98
99             if(request.getParameter(CategoryConstants.HTTPGET_PARAM_ACTION)!=null)
100                 action=request.getParameter(CategoryConstants.HTTPGET_PARAM_ACTION);
101
102             if(action.compareToIgnoreCase(CategoryConstants.VMODULE_ACTION_SAVE)==0)
103             {
104                 /**
105                  *Action is save
106                  */

107                 ActionErrors acterrors=editbean.validateSave();
108
109                 if(acterrors!=null)
110                 if(acterrors.size()>0)
111                 {
112                     /**
113                      *We have some errors, the form fields are not filled correctly
114                      */

115                     saveErrors(request,acterrors);
116                     return Constants.SECTION_EADMIN + Constants.DEFAULT_SPACER + element;
117                 }
118
119                 CategoriesObject catobj=new CategoriesObject();
120                 try
121                 {
122
123                     int saved=catobj.saveCategory(editbean);
124
125                     ActionErrors errors=new ActionErrors();
126
127                     /*
128                      *Checking for logical errors returned by save
129                      */

130                     if(saved==CategoryConstants.RESPONSE_INCOMPATIBLE_OWNER_ERROR)
131                     {
132                         errors.add(ActionErrors.GLOBAL_ERROR,new ActionError("module.categories.error.incompatibleowner"));
133                     }
134                     else if(saved==CategoryConstants.RESPONSE_SQLERROR)
135                     {
136                         errors.add(ActionErrors.GLOBAL_ERROR,new ActionError("module.categories.error.sqlerror"));
137                     }
138                     else if(saved==CategoryConstants.RESPONSE_NESTING_LEVEL_ERROR)
139                     {
140                         errors.add(ActionErrors.GLOBAL_ERROR,new ActionError("module.categories.error.nestinglevelerror"));
141                     }
142                     else if(saved==CategoryConstants.RESPONSE_DUPLICATE_ID_ERROR)
143                     {
144                         errors.add(ActionErrors.GLOBAL_ERROR,new ActionError("module.categories.error.duplicateiderror"));
145                     }
146
147                     if(errors.size()>0)
148                     {
149                         saveErrors(request,errors);
150                         return Constants.SECTION_EADMIN + Constants.DEFAULT_SPACER + element;
151                     }
152                     else
153                     {
154                         editbean.reset();
155                         return Constants.SECTION_EADMIN + Constants.DEFAULT_SPACER + CategoryConstants.ELEMENT_LIST;
156                     }
157
158
159                 }catch(SQLException JavaDoc sqle)
160                 {
161                     LoggingManager.log("Error while saving category!",this);
162                 }
163
164                editbean.reset();
165             }//end if action==save
166

167
168             //the category list should be reloaded all the time
169
try
170             {
171
172                 editbean.setCategorySelector( new CategorySelector(vm.getLocales(),user.getLocale()) );
173             }catch(Exception JavaDoc e)
174             {
175                 LoggingManager.log("Error while adding the CategorySelector!"+e,this);
176             }
177
178
179             boolean beanreset=false;
180             //checking for a parentidparameter
181

182             int parentid=0;
183
184             try
185             {
186                 if(request.getParameter(CategoryConstants.HTTPGET_PARAM_PARENTID)!=null)
187                   parentid=Integer.parseInt( request.getParameter(CategoryConstants.HTTPGET_PARAM_PARENTID) );
188             }catch(NumberFormatException JavaDoc nfe){}
189
190             if(parentid!=0)
191             {
192                 /*
193                  *We have a parentid, fill the parent and owner fields
194                  */

195                 GlobalResources gres=new GlobalResources();
196
197                 GResCategory grCat=null;
198                 try{
199                     grCat=gres.loadCategory(parentid);
200                 }catch(SQLException JavaDoc e){}
201                 if(grCat!=null)
202                 {
203                     editbean.reset();
204                     beanreset=true;
205                     editbean.setParentCategory(parentid);
206                     editbean.setOwner(grCat.getOwner());
207
208                 }
209             }//end if
210

211             //checking for a catidparameter
212
int catid=0;
213
214             try
215             {
216                 if(request.getParameter(CategoryConstants.HTTPGET_PARAM_CATID)!=null)
217                   catid=Integer.parseInt( request.getParameter(CategoryConstants.HTTPGET_PARAM_CATID) );
218             }catch(NumberFormatException JavaDoc nfe){}
219
220             if(catid!=0)
221             {
222                 /*
223                  *An old category, load its data and prefill the form
224                  */

225                 GlobalResources gres=new GlobalResources();
226
227                 GResCategory grCat=null;
228                 try{
229                     grCat=gres.loadCategory(catid);
230                 }catch(SQLException JavaDoc e){}
231                 if(grCat!=null && grCat.getStatic()!=1)
232                 {
233                     editbean.reset();
234                     beanreset=true;
235                     editbean.setRowId(grCat.getRowID());
236                     editbean.setParentCategory(grCat.getParent());
237                     editbean.setOwner(grCat.getOwner());
238                     editbean.setCatId(grCat.getCategoryID());
239                     Locale JavaDoc[] availLocales=editbean.getLocales();
240
241                     if(availLocales!=null)
242                     {
243                       String JavaDoc[] catnames=new String JavaDoc[availLocales.length];
244                       for(int i=0;i<availLocales.length;i++)
245                       {
246                           try
247                           {
248                               catnames[i]=gres.loadMessage(gres.getCategoryTableName(),grCat.getRowID(), CategoryConstants.RESCATFIELD_NAME,availLocales[i]);
249                           }catch(SQLException JavaDoc e)
250                           {
251                               LoggingManager.log("Error while loding locale sensitive data for category:"+grCat.getCategoryID(),this);
252                           }
253                           if(catnames[i]==null) catnames[i]="";
254                       }
255                       editbean.setName(catnames);
256                     }
257
258                 }
259             }//end if
260

261             if(!beanreset) editbean.reset();
262
263         }
264         else
265             return null; // display unknown element screen
266

267         return Constants.SECTION_EADMIN + Constants.DEFAULT_SPACER + element;
268
269     }
270
271 }
272
273 // eof
274
Popular Tags