1 16 17 package org.apache.jetspeed.om.registry.base; 18 19 import java.util.Iterator ; 20 import java.util.Vector ; 21 import java.util.Map ; 22 import java.util.Hashtable ; 23 import java.util.HashMap ; 24 25 import org.apache.jetspeed.om.registry.*; 26 import org.apache.jetspeed.services.Registry; 27 28 35 public class BasePortletEntry extends BasePortletInfoEntry 36 implements PortletEntry, java.io.Serializable 37 { 38 39 private String parent; 40 41 private ContentURL url = new BaseContentURL(); 42 43 protected Vector categories = new Vector (); 44 45 private boolean application; 46 47 private String type = PortletEntry.TYPE_ABSTRACT; 48 49 private boolean isRef = true; 50 51 55 public boolean equals(Object object) 56 { 57 if (object==null) 58 { 59 return false; 60 } 61 62 BasePortletEntry obj = (BasePortletEntry)object; 63 64 if (application!=obj.isApplication()) 65 { 66 return false; 67 } 68 69 if (parent!=null) 70 { 71 if (!parent.equals(obj.getParent())) 72 { 73 return false; 74 } 75 } 76 else 77 { 78 if (obj.getParent()!=null) 79 { 80 return false; 81 } 82 } 83 84 if (type!=null) 85 { 86 if (!type.equals(obj.getType())) 87 { 88 return false; 89 } 90 } 91 else 92 { 93 if (obj.getType()!=null) 94 { 95 return false; 96 } 97 } 98 99 if (url!=null) 100 { 101 if (!url.equals(obj.getContentURL())) 102 { 103 return false; 104 } 105 } 106 else 107 { 108 if (obj.getContentURL()!=null) 109 { 110 return false; 111 } 112 } 113 114 Iterator i = categories.iterator(); 115 Iterator i2 = obj.getCategories().iterator(); 116 while(i.hasNext()) 117 { 118 BaseCategory c1 = (BaseCategory)i.next(); 119 BaseCategory c2 = null; 120 121 if (i2.hasNext()) 122 { 123 c2 = (BaseCategory)i2.next(); 124 } 125 else 126 { 127 return false; 128 } 129 130 if (!c1.equals(c2)) 131 { 132 return false; 133 } 134 } 135 136 if (i2.hasNext()) 137 { 138 return false; 139 } 140 141 return super.equals(object); 142 } 143 144 145 public String getURL() 146 { 147 return this.url.getURL(); 148 } 149 150 154 public void setURL( String url ) 155 { 156 this.url.setURL(url); 157 } 158 159 public boolean isCachedOnURL() 160 { 161 return url.isCacheKey(); 162 } 163 164 public void setCachedOnURL(boolean cache) 165 { 166 url.setCachedOnURL(cache); 167 } 168 169 public ContentURL getURLEntry() 170 { 171 return url; 172 } 173 174 175 public String getParent() 176 { 177 return this.parent; 178 } 179 180 181 public String getClassname() 182 { 183 if (isRef && (classname == null) ) 184 { 185 return getParentEntry().getClassname(); 186 } 187 188 return classname; 189 } 190 191 192 197 public void setParent( String parent ) 198 { 199 this.parent = parent; 200 } 201 202 205 public boolean isAdmin() 206 { 207 if (getSecurity()!=null) 208 { 209 return "admin".equals(getSecurity().getRole()); 210 } 211 212 return false; 213 } 214 215 216 public boolean isApplication() 217 { 218 return this.application; 219 } 220 221 227 public void setApplication( boolean application ) 228 { 229 this.application = application; 230 } 231 232 233 public String getType() 234 { 235 return this.type; 236 } 237 238 243 public void setType( String type ) 244 { 245 this.isRef = PortletEntry.TYPE_REF.equals(type); 246 this.type = type; 247 } 248 249 255 public boolean getApplication() 256 { 257 return this.application; 258 } 259 260 public String getTitle() 261 { 262 String title = super.getTitle(); 263 if (title != null) 264 return title; 265 if (isRef) 266 { 267 return getParentEntry().getTitle(); 268 } 269 return null; 270 } 271 272 public String getDescription() 273 { 274 String desc = super.getDescription(); 275 if (desc != null) 276 return desc; 277 278 if (isRef) 279 { 280 return getParentEntry().getDescription(); 281 } 282 return null; 283 } 284 285 286 public PortletEntry getParentEntry() 287 { 288 PortletEntry parent = null; 289 parent = (PortletEntry)Registry.getEntry( Registry.PORTLET, getParent() ); 290 if (parent == null) 291 { 292 parent = new BasePortletEntry(); 293 parent.setName(getParent()); 294 parent.setType(PortletEntry.TYPE_ABSTRACT); 295 } 296 return parent; 297 } 298 299 public MetaInfo getMetaInfo() 300 { 301 MetaInfo meta = super.getMetaInfo(); 302 if (meta == null) 303 { 304 return getParentEntry().getMetaInfo(); 305 } 306 return meta; 307 } 308 309 310 public Iterator getParameterNames() 311 { 312 if (isRef) 313 { 314 Hashtable hash = new Hashtable (); 315 Iterator i = super.getParameterNames(); 316 while(i.hasNext()) 317 { 318 hash.put(i.next(),"1"); 319 } 320 i = getParentEntry().getParameterNames(); 321 while(i.hasNext()) 322 { 323 hash.put(i.next(),"1"); 324 } 325 326 return hash.keySet().iterator(); 327 } 328 329 return super.getParameterNames(); 330 } 331 332 338 public Parameter getParameter( String name ) 339 { 340 Parameter p = super.getParameter(name); 341 if (isRef && p == null) 342 { 343 return getParentEntry().getParameter(name); 344 } 345 return p; 346 } 347 348 public CachedParameter getCachedParameter( String name ) 349 { 350 Parameter p = getParameter(name); 351 return (CachedParameter)p; 352 } 353 354 357 public Map getParameterMap() 358 { 359 Hashtable params = (Hashtable )super.getParameterMap(); 360 361 if (isRef) 362 { 363 Map map = getParentEntry().getParameterMap(); 364 map.putAll(params); 365 return map; 366 } 367 368 return params; 369 } 370 371 376 public Iterator listMediaTypes() 377 { 378 if (isRef) 379 { 380 Map types = new HashMap (); 381 382 Iterator i = super.listMediaTypes(); 383 while(i.hasNext()) 384 { 385 types.put(i.next(),"1"); 386 } 387 388 i = getParentEntry().listMediaTypes(); 389 while(i.hasNext()) 390 { 391 types.put(i.next(),"1"); 392 } 393 394 return types.keySet().iterator(); 395 } 396 397 return super.listMediaTypes(); 398 } 399 400 407 public boolean hasMediaType(String name) 408 { 409 if (isRef) 410 { 411 return super.hasMediaType(name) || getParentEntry().hasMediaType(name); 412 } 413 414 return super.hasMediaType(name); 415 } 416 417 418 public BaseContentURL getContentURL() 419 { 420 return (BaseContentURL)this.url; 421 } 422 423 427 public void setContentURL( BaseContentURL url ) 428 { 429 this.url = url; 430 } 431 432 435 public Vector getCategories() 436 { 437 return this.categories; 438 } 439 440 public void setCategories(Vector v) 441 { 442 this.categories = v; 443 } 444 445 450 public Iterator listCategories() 451 { 452 return new PortletIterator(this, "getCategories"); 453 } 454 455 461 public boolean hasCategory(String name) 462 { 463 return hasCategory(name, PortletEntry.DEFAULT_GROUP); 464 } 465 466 473 public boolean hasCategory(String name, String group) 474 { 475 Iterator it = listCategories(); 476 while (it.hasNext()) 477 { 478 Category cat = (Category)it.next(); 479 if (cat.getName().equals(name) && cat.getGroup().equals(group)) 480 return true; 481 } 482 return false; 483 } 484 485 486 491 public void addCategory(String name) 492 { 493 addCategory(name, PortletEntry.DEFAULT_GROUP); 494 } 495 496 502 public void addCategory(String name, String group) 503 { 504 if (!hasCategory(name, group)) 505 { 506 Category cat = new BaseCategory(); 507 cat.setName(name); 508 cat.setGroup(group); 509 categories.add(cat); 510 } 511 } 512 513 518 public void removeCategory(String name) 519 { 520 removeCategory(name, PortletEntry.DEFAULT_GROUP); 521 } 522 523 529 public void removeCategory(String name, String group) 530 { 531 for (int ix = 0; ix < categories.size(); ix++) 532 { 533 Category cat = (Category)categories.elementAt(ix); 534 if (cat.getName().equals(name) && cat.getGroup().equals(group)) 535 { 536 categories.remove(ix); 537 return; 538 } 539 } 540 } 541 } 542 543 544 | Popular Tags |