1 5 6 package com.raptus.owxv3.modules.categories; 7 8 import java.sql.SQLException ; 9 import java.util.Locale ; 10 11 import javax.servlet.http.HttpServletRequest ; 12 13 import org.apache.struts.action.*; 14 15 import com.raptus.owxv3.*; 16 import com.raptus.owxv3.api.*; 17 18 45 46 public class EACategoryEditAction extends VModuleRoleAction 48 { 49 56 public String dispatchVModuleElement(HttpServletRequest request, 57 String 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 editbean.setVmodules(cm.getStringArrayByTree("virtualhost/vmodules/vmodule?name="+vm.getIdentification()+"/properties/property?name=vmodulelist", "value")); 74 75 editbean.setCurrLocale( user.getLocale() ); 77 String [] locales=vm.getLocales(); 78 Locale [] availLocales = new Locale [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 ((String ) po.getObjectOne(), (String ) po.getObjectTwo()); 85 } 86 87 88 editbean.setLocales(availLocales); 89 90 } 92 93 String action=""; 94 95 96 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 107 ActionErrors acterrors=editbean.validateSave(); 108 109 if(acterrors!=null) 110 if(acterrors.size()>0) 111 { 112 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 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 sqle) 160 { 161 LoggingManager.log("Error while saving category!",this); 162 } 163 164 editbean.reset(); 165 } 167 168 try 170 { 171 172 editbean.setCategorySelector( new CategorySelector(vm.getLocales(),user.getLocale()) ); 173 }catch(Exception e) 174 { 175 LoggingManager.log("Error while adding the CategorySelector!"+e,this); 176 } 177 178 179 boolean beanreset=false; 180 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 nfe){} 189 190 if(parentid!=0) 191 { 192 195 GlobalResources gres=new GlobalResources(); 196 197 GResCategory grCat=null; 198 try{ 199 grCat=gres.loadCategory(parentid); 200 }catch(SQLException e){} 201 if(grCat!=null) 202 { 203 editbean.reset(); 204 beanreset=true; 205 editbean.setParentCategory(parentid); 206 editbean.setOwner(grCat.getOwner()); 207 208 } 209 } 211 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 nfe){} 219 220 if(catid!=0) 221 { 222 225 GlobalResources gres=new GlobalResources(); 226 227 GResCategory grCat=null; 228 try{ 229 grCat=gres.loadCategory(catid); 230 }catch(SQLException 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 [] availLocales=editbean.getLocales(); 240 241 if(availLocales!=null) 242 { 243 String [] catnames=new String [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 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 } 261 if(!beanreset) editbean.reset(); 262 263 } 264 else 265 return null; 267 return Constants.SECTION_EADMIN + Constants.DEFAULT_SPACER + element; 268 269 } 270 271 } 272 273 | Popular Tags |