1 package org.roller.pojos; 2 3 import java.util.Iterator ; 4 import java.util.LinkedList ; 5 import java.util.List ; 6 7 import org.roller.RollerException; 8 import org.roller.model.Roller; 9 import org.roller.model.RollerFactory; 10 import org.roller.model.WeblogManager; 11 import org.roller.util.PojoUtil; 12 13 22 public class WeblogCategoryData extends HierarchicalPersistentObject 23 { 24 static final long serialVersionUID = 1435782148712018954L; 25 26 protected java.lang.String id = null; 27 protected java.lang.String name; 28 protected java.lang.String description; 29 protected java.lang.String image; 30 31 protected String cachedPath = null; 32 33 protected WebsiteData mWebsite; 34 protected List mWeblogCategories; 35 36 public WeblogCategoryData() 37 { 38 } 39 40 public WeblogCategoryData( 41 java.lang.String id, 42 WebsiteData website, 43 WeblogCategoryData parent, 44 java.lang.String name, 45 java.lang.String description, 46 java.lang.String image) 47 { 48 this.id = id; 49 this.mWebsite = website; 50 this.mNewParent = parent; 51 this.name = name; 52 this.description = description; 53 this.image = image; 54 } 55 56 public WeblogCategoryData(WeblogCategoryData otherData) 57 { 58 this.id = otherData.id; 59 this.mWebsite = otherData.mWebsite; 60 this.mNewParent = otherData.mNewParent; 61 this.name = otherData.name; 62 this.description = otherData.description; 63 this.image = otherData.image; 64 } 65 66 67 public void setData(org.roller.pojos.PersistentObject otherData) 68 { 69 this.id = ((WeblogCategoryData) otherData).id; 70 this.mWebsite = ((WeblogCategoryData) otherData).mWebsite; 71 this.mNewParent = ((WeblogCategoryData) otherData).mNewParent; 72 this.name = ((WeblogCategoryData) otherData).name; 73 this.description = ((WeblogCategoryData) otherData).description; 74 this.image = ((WeblogCategoryData) otherData).image; 75 } 76 77 public void save() throws RollerException 78 { 79 if (RollerFactory.getRoller().getWeblogManager().isDuplicateWeblogCategoryName(this)) 80 { 81 throw new RollerException("Duplicate category name"); 82 } 83 super.save(); 84 } 85 86 91 public void remove(WeblogCategoryData destCat) throws RollerException 92 { 93 WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager(); 94 95 if (destCat != null) 97 { 98 wmgr.moveWeblogCategoryContents(getId(), destCat.getId()); 99 } 100 super.remove(); 102 103 if (getWebsite().getBloggerCategory().equals(this)) 104 { 105 WeblogCategoryData rootCat = wmgr.getRootWeblogCategory(getWebsite()); 106 getWebsite().setBloggerCategory(rootCat); 107 } 108 109 if (getWebsite().getDefaultCategory().equals(this)) 110 { 111 WeblogCategoryData rootCat = wmgr.getRootWeblogCategory(getWebsite()); 112 getWebsite().setDefaultCategory(rootCat); 113 } 114 115 getWebsite().save(); 116 } 117 118 121 public Class getAssocClass() 122 { 123 return WeblogCategoryAssoc.class; 124 } 125 126 129 public String getObjectPropertyName() 130 { 131 return "category"; 132 } 133 134 137 public String getAncestorPropertyName() 138 { 139 return "ancestorCategory"; 140 } 141 142 144 149 public java.lang.String getId() 150 { 151 return this.id; 152 } 153 154 public void setId(java.lang.String id) 155 { 156 this.id = id; 157 } 158 159 163 public java.lang.String getName() 164 { 165 return this.name; 166 } 167 168 public void setName(java.lang.String name) 169 { 170 this.name = name; 171 } 172 173 178 public java.lang.String getDescription() 179 { 180 return this.description; 181 } 182 183 public void setDescription(java.lang.String description) 184 { 185 this.description = description; 186 } 187 188 192 public java.lang.String getImage() 193 { 194 return this.image; 195 } 196 197 public void setImage(java.lang.String image) 198 { 199 this.image = image; 200 } 201 202 205 public String getPath() 206 { 207 if (null == cachedPath) 208 { 209 try 210 { 211 cachedPath = RollerFactory.getRoller().getWeblogManager().getPath(this); 212 } 213 catch (RollerException e) 214 { 215 throw new RuntimeException (e); 216 } 217 } 218 return cachedPath; 219 } 220 221 223 228 public WebsiteData getWebsite() 229 { 230 return mWebsite; 231 } 232 233 public void setWebsite(WebsiteData website) 234 { 235 mWebsite = website; 236 } 237 238 253 254 public WeblogCategoryData getParent() throws RollerException 255 { 256 if (mNewParent != null) 257 { 258 return (WeblogCategoryData)mNewParent; 260 } 261 else if (getParentAssoc() != null) 262 { 263 return ((WeblogCategoryAssoc)getParentAssoc()).getAncestorCategory(); 265 } 266 else 267 { 268 return null; 269 } 270 } 271 272 273 public void setParent(HierarchicalPersistentObject parent) 274 { 275 mNewParent = parent; 276 } 277 278 279 public List getWeblogCategories() throws RollerException 280 { 281 if (mWeblogCategories == null) 282 { 283 mWeblogCategories = new LinkedList (); 284 List childAssocs = getChildAssocs(); 285 Iterator childIter = childAssocs.iterator(); 286 while (childIter.hasNext()) 287 { 288 WeblogCategoryAssoc assoc = 289 (WeblogCategoryAssoc) childIter.next(); 290 mWeblogCategories.add(assoc.getCategory()); 291 } 292 } 293 return mWeblogCategories; 294 } 295 296 public boolean descendentOf(WeblogCategoryData ancestor) 297 throws RollerException 298 { 299 return RollerFactory.getRoller().getWeblogManager().isDescendentOf(this, ancestor); 300 } 301 302 306 public boolean isInUse() 307 { 308 try 309 { 310 return RollerFactory.getRoller().getWeblogManager().isWeblogCategoryInUse(this); 311 } 312 catch (RollerException e) 313 { 314 throw new RuntimeException (e); 315 } 316 } 317 318 319 public void setInUse(boolean dummy) {} 320 321 323 328 public Assoc createAssoc( 329 HierarchicalPersistentObject object, 330 HierarchicalPersistentObject associatedObject, 331 String relation) throws RollerException 332 { 333 WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager(); 334 return wmgr.createWeblogCategoryAssoc( 335 (WeblogCategoryData)object, 336 (WeblogCategoryData)associatedObject, 337 relation); 338 } 339 340 342 346 public void moveContents(WeblogCategoryData dest) throws RollerException 347 { 348 Iterator entries = retrieveWeblogEntries(true).iterator(); 349 while (entries.hasNext()) 350 { 351 WeblogEntryData entry = (WeblogEntryData) entries.next(); 352 entry.setCategory(dest); 353 entry.save(); 354 } 355 } 356 357 364 public List retrieveWeblogEntries(boolean subcats) 365 throws RollerException 366 { 367 WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager(); 368 return wmgr.retrieveWeblogEntries(this, subcats); 369 } 370 371 373 public String toString() 374 { 375 StringBuffer str = new StringBuffer ("{"); 376 377 str.append( 378 "id=" 379 + id 380 + " " 381 + "name=" 382 + name 383 + " " 384 + "description=" 385 + description 386 + " " 387 + "image=" 388 + image); 389 str.append('}'); 390 391 return (str.toString()); 392 } 393 394 public boolean equals(Object pOther) 395 { 396 if (pOther == null) return false; 397 if (pOther instanceof WeblogCategoryData) 398 { 399 WeblogCategoryData lTest = (WeblogCategoryData) pOther; 400 boolean lEquals = true; 401 lEquals = PojoUtil.equals(lEquals, this.id, lTest.id); 402 lEquals = PojoUtil.equals(lEquals, this.mWebsite.getId(), lTest.mWebsite.getId()); 403 lEquals = PojoUtil.equals(lEquals, this.name, lTest.name); 404 lEquals = PojoUtil.equals(lEquals, this.description, lTest.description); 405 lEquals = PojoUtil.equals(lEquals, this.image, lTest.image); 406 return lEquals; 407 } 408 else 409 { 410 return false; 411 } 412 } 413 414 public int hashCode() 415 { 416 int result = 17; 417 result = 37 * result + ((this.id != null) ? this.id.hashCode() : 0); 418 result = 419 37 * result 420 + ((this.mWebsite != null) ? this.mWebsite.hashCode() : 0); 421 result = 37 * result + ((this.name != null) ? this.name.hashCode() : 0); 422 result = 423 37 * result 424 + ((this.description != null) ? this.description.hashCode() : 0); 425 result = 426 37 * result + ((this.image != null) ? this.image.hashCode() : 0); 427 return result; 428 } 429 430 431 public void setAssocClassName(String dummy) {}; 432 433 434 public void setObjectPropertyName(String dummy) {}; 435 436 437 public void setAncestorPropertyName(String dummy) {}; 438 439 440 public void setPath(String string) {} 441 442 445 protected Assoc getParentAssoc() throws RollerException 446 { 447 return RollerFactory.getRoller().getWeblogManager().getWeblogCategoryParentAssoc(this); 448 } 449 450 453 protected List getChildAssocs() throws RollerException 454 { 455 return RollerFactory.getRoller().getWeblogManager().getWeblogCategoryChildAssocs(this); 456 } 457 458 461 public List getAllDescendentAssocs() throws RollerException 462 { 463 return RollerFactory.getRoller().getWeblogManager().getAllWeblogCategoryDecscendentAssocs(this); 464 } 465 466 469 public List getAncestorAssocs() throws RollerException 470 { 471 return RollerFactory.getRoller().getWeblogManager().getWeblogCategoryAncestorAssocs(this); 472 } 473 474 public boolean canSave() throws RollerException 475 { 476 Roller roller = RollerFactory.getRoller(); 477 if (roller.getUser().equals(UserData.SYSTEM_USER)) 478 { 479 return true; 480 } 481 if (roller.getUser().equals(getWebsite().getUser())) 482 { 483 return true; 484 } 485 return false; 486 } 487 488 } 489 | Popular Tags |