1 5 6 package com.raptus.owxv3.modules.categories; 7 8 import java.sql.SQLException ; 9 import java.util.Locale ; 10 11 import com.raptus.owxv3.*; 12 import com.raptus.owxv3.api.*; 13 14 15 44 public class CategoriesObject extends Object 45 { 47 50 protected GlobalResources gres = null; 51 52 53 56 57 public CategoriesObject() 58 { 59 gres=new GlobalResources(); 60 } 61 62 71 72 public int saveCategory(EACategoryEditBean editbean) throws SQLException 73 { 74 75 76 GResCategory grescat=new GResCategory(); 77 78 if(editbean.getParentCategory()!=0) 79 { 80 GResCategory parent=gres.loadCategory(editbean.getParentCategory()); 81 82 if(! parent.getOwner().equals(editbean.getOwner())) return CategoryConstants.RESPONSE_INCOMPATIBLE_OWNER_ERROR; 84 85 int maxnestlevel=0; 87 try 88 { 89 VModuleManager vmm=VModuleManager.getInstance(); 90 VModule ownervm=vmm.getVModule(editbean.getOwner()); 91 XMLConfigManager xcm=XMLConfigManager.getInstance(); 93 maxnestlevel=xcm.getIntegerByTree("virtualhost/vmodules/vmodule?name="+ownervm.getIdentification()+"/component-properties/component-property?for=fc_categories/property?name=nesting_level","value"); 94 95 }catch(Exception e) 96 { 97 LoggingManager.log("Unable to retrieve category nesting level for vmodule "+editbean.getOwner(),this); 98 } 99 100 101 if(maxnestlevel>0 && parent.getLevel()>=(maxnestlevel-1)) return CategoryConstants.RESPONSE_NESTING_LEVEL_ERROR; 102 103 grescat.setLevel(parent.getLevel()+1); 104 } 105 106 grescat.setOwner(editbean.getOwner()); 107 grescat.setParent(editbean.getParentCategory()); 108 109 grescat.setRowID(editbean.getRowId()); 110 grescat.setCategoryID(editbean.getCatId()); 111 grescat.setStatic(0); 112 int result=gres.saveCategory(grescat); 114 if( result==0) return CategoryConstants.RESPONSE_SQLERROR; 115 if( result==-1) return CategoryConstants.RESPONSE_DUPLICATE_ID_ERROR; 116 117 118 Locale [] l=editbean.getLocales(); 120 String [] catname=editbean.getName(); 121 if(l!=null && catname!=null) 122 { 123 for(int i=0;i<l.length;i++) 124 { 125 if(catname[i]==null) catname[i]=""; 126 127 gres.saveMessage(gres.getCategoryTableName(), grescat.getRowID(),CategoryConstants.RESCATFIELD_NAME, l[i], catname[i]); 128 129 } 130 } 131 132 return CategoryConstants.RESPONSE_OK; 133 } 134 135 143 144 145 146 public int deleteCategory(int id) 147 { 148 try 149 { 150 GResCategory cat=gres.loadCategory(id); 151 if(cat.getUsageCount()>0) return CategoryConstants.RESPONSE_NOTEMTPY_ERROR; 152 153 if(cat.getStatic()==1) return CategoryConstants.RESPONSE_NODELETESTATIC_ERROR; 154 155 gres.deleteCategory(cat); 156 }catch(SQLException e) 157 { 158 LoggingManager.log("SQL error:"+e,this); 159 return CategoryConstants.RESPONSE_SQLERROR; 160 } 161 162 return CategoryConstants.RESPONSE_OK; 163 } 164 165 166 172 public int deleteCatLink(int linkid) 173 { 174 try 175 { 176 gres.deleteCatLink(linkid); 177 178 }catch(SQLException e) 179 { 180 LoggingManager.log("SQL error:"+e,this); 181 return CategoryConstants.RESPONSE_SQLERROR; 182 } 183 184 return CategoryConstants.RESPONSE_OK; 185 186 187 } 188 189 190 191 } 192 | Popular Tags |