1 18 package org.apache.roller.pojos; 19 20 import java.util.Iterator ; 21 import java.util.LinkedList ; 22 import java.util.List ; 23 24 import org.apache.roller.RollerException; 25 import org.apache.roller.model.Roller; 26 import org.apache.roller.model.RollerFactory; 27 import org.apache.roller.model.WeblogManager; 28 import org.apache.roller.util.PojoUtil; 29 30 39 public class WeblogCategoryData extends HierarchicalPersistentObject { 40 public static final long serialVersionUID = 1435782148712018954L; 41 42 private String id = null; 43 private String name = null; 44 private String description = null; 45 private String image = null; 46 47 private String cachedPath = null; 48 49 private WebsiteData website = null; 50 private List weblogCategories = null; 51 52 53 public WeblogCategoryData() { 54 } 55 56 public WeblogCategoryData( 57 java.lang.String id, 58 WebsiteData website, 59 WeblogCategoryData parent, 60 java.lang.String name, 61 java.lang.String description, 62 java.lang.String image) { 63 this.id = id; 64 this.website = website; 65 this.mNewParent = parent; 66 this.name = name; 67 this.description = description; 68 this.image = image; 69 } 70 71 public WeblogCategoryData(WeblogCategoryData otherData) { 72 this.setData(otherData); 73 } 74 75 76 public void setData(org.apache.roller.pojos.PersistentObject otherData) { 77 WeblogCategoryData other = (WeblogCategoryData) otherData; 78 79 this.id = other.getId(); 80 this.website = other.getWebsite(); 81 this.name = other.getName(); 82 this.description = other.getDescription(); 83 this.image = other.getImage(); 84 85 try { 86 this.mNewParent = other.getParent(); 87 } catch(RollerException re) { 88 } 90 } 91 92 93 96 public Class getAssocClass() { 97 return WeblogCategoryAssoc.class; 98 } 99 100 105 public String getObjectPropertyName() { 106 return "category"; 107 } 108 109 114 public String getAncestorPropertyName() { 115 return "ancestorCategory"; 116 } 117 118 120 126 public java.lang.String getId() { 127 return this.id; 128 } 129 130 public void setId(java.lang.String id) { 131 this.id = id; 132 } 133 134 139 public java.lang.String getName() { 140 return this.name; 141 } 142 143 public void setName(java.lang.String name) { 144 this.name = name; 145 } 146 147 154 public java.lang.String getDescription() { 155 return this.description; 156 } 157 158 public void setDescription(java.lang.String description) { 159 this.description = description; 160 } 161 162 167 public java.lang.String getImage() { 168 return this.image; 169 } 170 171 public void setImage(java.lang.String image) { 172 this.image = image; 173 } 174 175 180 public String getPath() { 181 if (null == cachedPath) { 182 try { 183 cachedPath = RollerFactory.getRoller().getWeblogManager().getPath(this); 184 } catch (RollerException e) { 185 throw new RuntimeException (e); 186 } 187 } 188 return cachedPath; 189 } 190 191 193 199 public WebsiteData getWebsite() { 200 return website; 201 } 202 203 public void setWebsite(WebsiteData website) { 204 this.website = website; 205 } 206 207 208 213 public WeblogCategoryData getParent() throws RollerException { 214 if (mNewParent != null) { 215 return (WeblogCategoryData)mNewParent; 217 } else if (getParentAssoc() != null) { 218 return ((WeblogCategoryAssoc)getParentAssoc()).getAncestorCategory(); 220 } else { 221 return null; 222 } 223 } 224 225 226 public void setParent(HierarchicalPersistentObject parent) { 227 mNewParent = parent; 228 } 229 230 235 public List getWeblogCategories() throws RollerException { 236 if (weblogCategories == null) { 237 weblogCategories = new LinkedList (); 238 List childAssocs = getChildAssocs(); 239 Iterator childIter = childAssocs.iterator(); 240 while (childIter.hasNext()) { 241 WeblogCategoryAssoc assoc = 242 (WeblogCategoryAssoc) childIter.next(); 243 weblogCategories.add(assoc.getCategory()); 244 } 245 } 246 return weblogCategories; 247 } 248 249 252 public boolean descendentOf(WeblogCategoryData ancestor) 253 throws RollerException { 254 return RollerFactory.getRoller().getWeblogManager().isDescendentOf(this, ancestor); 255 } 256 257 263 public boolean isInUse() { 264 try { 265 return RollerFactory.getRoller().getWeblogManager().isWeblogCategoryInUse(this); 266 } catch (RollerException e) { 267 throw new RuntimeException (e); 268 } 269 } 270 271 272 public void setInUse(boolean dummy) {} 273 274 276 281 public Assoc createAssoc( 282 HierarchicalPersistentObject object, 283 HierarchicalPersistentObject associatedObject, 284 String relation) throws RollerException { 285 return new WeblogCategoryAssoc(null, 286 (WeblogCategoryData)object, 287 (WeblogCategoryData)associatedObject, 288 relation); 289 } 290 291 292 302 public List retrieveWeblogEntries(boolean subcats) 303 throws RollerException { 304 WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager(); 305 return wmgr.getWeblogEntries(this, subcats); 306 } 307 308 310 public String toString() { 311 StringBuffer str = new StringBuffer ("{"); 312 313 str.append( 314 "id=" 315 + id 316 + " " 317 + "name=" 318 + name 319 + " " 320 + "description=" 321 + description 322 + " " 323 + "image=" 324 + image); 325 str.append('}'); 326 327 return (str.toString()); 328 } 329 330 public boolean equals(Object pOther) { 331 if (pOther == null) return false; 332 if (pOther instanceof WeblogCategoryData) { 333 WeblogCategoryData lTest = (WeblogCategoryData) pOther; 334 boolean lEquals = true; 335 lEquals = PojoUtil.equals(lEquals, this.getId(), lTest.getId()); 336 lEquals = PojoUtil.equals(lEquals, this.getName(), lTest.getName()); 337 lEquals = PojoUtil.equals(lEquals, this.getDescription(), lTest.getDescription()); 338 lEquals = PojoUtil.equals(lEquals, this.getImage(), lTest.getImage()); 339 return lEquals; 340 } else { 341 return false; 342 } 343 } 344 345 public int hashCode() { 346 int result = 17; 347 result = 37 * result + ((this.id != null) ? this.id.hashCode() : 0); 348 result = 349 37 * result 350 + ((this.website != null) ? this.website.hashCode() : 0); 351 result = 37 * result + ((this.name != null) ? this.name.hashCode() : 0); 352 result = 353 37 * result 354 + ((this.description != null) ? this.description.hashCode() : 0); 355 result = 356 37 * result + ((this.image != null) ? this.image.hashCode() : 0); 357 return result; 358 } 359 360 361 public void setAssocClassName(String dummy) {}; 362 363 364 public void setObjectPropertyName(String dummy) {}; 365 366 367 public void setAncestorPropertyName(String dummy) {}; 368 369 370 public void setPath(String string) {} 371 372 375 public Assoc getParentAssoc() throws RollerException { 376 return RollerFactory.getRoller().getWeblogManager().getWeblogCategoryParentAssoc(this); 377 } 378 379 382 public List getChildAssocs() throws RollerException { 383 return RollerFactory.getRoller().getWeblogManager().getWeblogCategoryChildAssocs(this); 384 } 385 386 389 public List getAllDescendentAssocs() throws RollerException { 390 return RollerFactory.getRoller().getWeblogManager().getAllWeblogCategoryDecscendentAssocs(this); 391 } 392 393 396 public List getAncestorAssocs() throws RollerException { 397 return RollerFactory.getRoller().getWeblogManager().getWeblogCategoryAncestorAssocs(this); 398 } 399 400 } 401 | Popular Tags |