1 18 package org.apache.roller.pojos; 19 20 import java.io.Serializable ; 21 import java.util.Iterator ; 22 import java.util.LinkedList ; 23 import java.util.List ; 24 import java.util.Set ; 25 import java.util.TreeSet ; 26 27 import org.apache.roller.RollerException; 28 import org.apache.roller.model.BookmarkManager; 29 import org.apache.roller.model.RollerFactory; 30 31 44 public class FolderData extends HierarchicalPersistentObject 45 implements Serializable , Comparable 46 { 47 static final long serialVersionUID = -6272468884763861944L; 48 49 private Set bookmarks = new TreeSet (); 50 private List folders = null; 51 private WebsiteData website; 52 53 private String id; 54 private String name; 55 private String description; 56 private String path; 57 58 60 61 public FolderData() 62 { 63 } 64 65 public FolderData( 66 FolderData parent, 67 String name, 68 String desc, 69 WebsiteData website) 70 { 71 mNewParent = parent; 72 this.name = name; 73 this.description = desc; 74 this.website = website; 75 } 76 77 public void setData(org.apache.roller.pojos.PersistentObject otherData) 78 { 79 mNewParent = ((FolderData) otherData).mNewParent; 80 this.id = ((FolderData) otherData).getId(); 81 this.name = ((FolderData) otherData).getName(); 82 this.description = ((FolderData) otherData).getDescription(); 83 this.website = ((FolderData) otherData).getWebsite(); 84 this.setBookmarks(((FolderData) otherData).getBookmarks()); 85 } 86 87 88 91 public Class getAssocClass() 92 { 93 return FolderAssoc.class; 94 } 95 96 101 public String getObjectPropertyName() 102 { 103 return "folder"; 104 } 105 106 111 public String getAncestorPropertyName() 112 { 113 return "ancestorFolder"; 114 } 115 116 119 public boolean isInUse() 120 { 121 try 122 { 123 return RollerFactory.getRoller().getBookmarkManager().isFolderInUse(this); 124 } 125 catch (RollerException e) 126 { 127 throw new RuntimeException (e); 128 } 129 } 130 131 134 public boolean descendentOf(FolderData ancestor) 135 throws RollerException 136 { 137 return RollerFactory.getRoller().getBookmarkManager().isDescendentOf(this, ancestor); 138 } 139 140 142 150 public String getId() 151 { 152 return this.id; 153 } 154 155 156 public void setId(String id) 157 { 158 this.id = id; 159 } 160 161 173 public String getName() 174 { 175 return this.name; 176 } 177 178 179 public void setName(String name) 180 { 181 this.name = name; 182 } 183 184 193 public String getDescription() 194 { 195 return this.description; 196 } 197 198 199 public void setDescription(String description) 200 { 201 this.description = description; 202 } 203 204 206 211 public String getPath() throws RollerException 212 { 213 if (mNewParent != null) 214 { 215 throw new RollerException( 216 "Folder has a new parent and must be saved before getPath() will work"); 217 } 218 219 if (null == path) 220 { 221 path = RollerFactory.getRoller().getBookmarkManager().getPath(this); 222 } 223 return path; 224 } 225 226 233 public WebsiteData getWebsite() 234 { 235 return website; 236 } 237 238 239 public void setWebsite( WebsiteData website ) 240 { 241 this.website = website; 242 } 243 244 249 public FolderData getParent() throws RollerException 250 { 251 if (mNewParent != null) 252 { 253 return (FolderData)mNewParent; 255 } 256 else if (getParentAssoc() != null) 257 { 258 return ((FolderAssoc)getParentAssoc()).getAncestorFolder(); 260 } 261 else 262 { 263 return null; 264 } 265 } 266 267 268 public void setParent(HierarchicalPersistentObject parent) 269 { 270 mNewParent = parent; 271 } 272 273 278 public List getFolders() throws RollerException 279 { 280 if (folders == null) 281 { 282 folders = new LinkedList (); 283 List childAssocs = getChildAssocs(); 284 Iterator childIter = childAssocs.iterator(); 285 while (childIter.hasNext()) 286 { 287 FolderAssoc assoc = 288 (FolderAssoc) childIter.next(); 289 folders.add(assoc.getFolder()); 290 } 291 } 292 return folders; 293 } 294 295 297 306 public Set getBookmarks() 307 { 308 return this.bookmarks; 309 } 310 311 private void setBookmarks(Set bookmarks) 313 { 314 this.bookmarks = bookmarks; 315 } 316 317 318 public void addBookmark(BookmarkData bookmark) throws RollerException 319 { 320 bookmark.setFolder(this); 321 getBookmarks().add(bookmark); 322 } 323 324 325 public void removeBookmark(BookmarkData bookmark) 326 { 327 getBookmarks().remove(bookmark); 328 } 329 330 335 public List retrieveBookmarks(boolean subfolders) throws RollerException 336 { 337 BookmarkManager bmgr = RollerFactory.getRoller().getBookmarkManager(); 338 return bmgr.getBookmarks(this, subfolders); 339 } 340 341 345 public void moveContents(FolderData dest) throws RollerException 346 { 347 Iterator entries = retrieveBookmarks(true).iterator(); 348 while (entries.hasNext()) 349 { 350 BookmarkData bookmark = (BookmarkData) entries.next(); 351 352 dest.addBookmark(bookmark); 356 } 357 } 358 359 361 366 public Assoc createAssoc( 367 HierarchicalPersistentObject object, 368 HierarchicalPersistentObject associatedObject, 369 String relation) throws RollerException 370 { 371 return new FolderAssoc( 372 null, 373 (FolderData)object, 374 (FolderData)associatedObject, 375 relation); 376 } 377 378 380 public String toString() 381 { 382 StringBuffer str = new StringBuffer ("{"); 383 str.append( 384 "bookmarks=" + bookmarks + " " 385 + "id=" + id + " " 386 + "name=" + name + " " 387 + "description=" + description); 388 str.append('}'); 389 return (str.toString()); 390 } 391 392 public boolean equals(Object pOther) 393 { 394 if (pOther instanceof FolderData) 395 { 396 FolderData lTest = (FolderData) pOther; 397 boolean lEquals = true; 398 399 408 if (this.id == null) 409 { 410 lEquals = lEquals && (lTest.getId() == null); 411 } 412 else 413 { 414 lEquals = lEquals && this.id.equals(lTest.getId()); 415 } 416 417 if (this.name == null) 418 { 419 lEquals = lEquals && (lTest.getName() == null); 420 } 421 else 422 { 423 lEquals = lEquals && this.name.equals(lTest.getName()); 424 } 425 426 if (this.description == null) 427 { 428 lEquals = lEquals && (lTest.getDescription() == null); 429 } 430 else 431 { 432 lEquals = lEquals && 433 this.description.equals(lTest.getDescription()); 434 } 435 436 if (this.website == null) 437 { 438 lEquals = lEquals && (lTest.getWebsite() == null); 439 } 440 else 441 { 442 lEquals = lEquals && this.website.equals(lTest.getWebsite()); 443 } 444 445 return lEquals; 446 } 447 else 448 { 449 return false; 450 } 451 } 452 453 public int hashCode() 454 { 455 int result = 17; 456 457 result = (37 * result) + 458 ((this.id != null) ? this.id.hashCode() : 0); 459 result = (37 * result) + 460 ((this.name != null) ? this.name.hashCode() : 0); 461 result = (37 * result) + 462 ((this.description != null) ? this.description.hashCode() : 0); 463 result = (37 * result) + 464 ((this.website != null) ? this.website.hashCode() : 0); 465 466 return result; 467 } 468 469 472 public int compareTo(Object o) 473 { 474 FolderData other = (FolderData)o; 475 return getName().compareTo(other.getName()); 476 } 477 478 479 public void setAssocClassName(String dummy) {}; 480 481 public void setObjectPropertyName(String dummy) {}; 482 483 public void setAncestorPropertyName(String dummy) {}; 484 485 public void setPath(String string) {} 486 487 public void setInUse(boolean flag) {} 488 489 492 public Assoc getParentAssoc() throws RollerException 493 { 494 return RollerFactory.getRoller().getBookmarkManager().getFolderParentAssoc(this); 495 } 496 497 500 public List getChildAssocs() throws RollerException 501 { 502 return RollerFactory.getRoller().getBookmarkManager().getFolderChildAssocs(this); 503 } 504 505 508 public List getAllDescendentAssocs() throws RollerException 509 { 510 return RollerFactory.getRoller().getBookmarkManager().getAllFolderDecscendentAssocs(this); 511 } 512 513 516 public List getAncestorAssocs() throws RollerException 517 { 518 return RollerFactory.getRoller().getBookmarkManager().getFolderAncestorAssocs(this); 519 } 520 521 } 522 | Popular Tags |