1 16 17 package org.apache.jetspeed.om.profile; 18 19 import org.apache.jetspeed.om.profile.Portlets; 20 import org.apache.jetspeed.om.profile.Entry; 21 import java.util.Iterator ; 22 23 31 public class BasePSMLDocument implements PSMLDocument 32 { 33 37 private String name = null; 38 39 42 private Portlets portlets = null; 43 44 47 public BasePSMLDocument() 48 { 49 } 51 52 59 public BasePSMLDocument( String name, Portlets portlets ) 60 { 61 this.name = name; 62 this.portlets = portlets; 63 } 64 65 68 public final String getName() 69 { 70 return this.name; 71 } 72 73 78 public final void setName(String name) 79 { 80 this.name = name; 81 } 82 83 89 public final Portlets getPortlets() 90 { 91 return this.portlets; 92 } 93 94 99 public final void setPortlets(Portlets portlets) 100 { 101 this.portlets = portlets; 102 } 103 104 110 public Entry getEntry(String name) 111 { 112 return getEntry(this.portlets, name); 113 } 114 115 121 public Entry getEntryById(String entryId) 122 { 123 return getEntryById(this.portlets, entryId); 124 } 125 126 132 public Portlets getPortlets(String name) 133 { 134 Portlets p = getPortlets(this.portlets, name); 135 136 if (p == null) 137 { 138 try 140 { 141 p = getPortlets(Integer.parseInt(name)); 142 } 143 catch (NumberFormatException e) 144 { 145 } 147 } 148 149 return p; 150 } 151 152 158 public Portlets getPortletsById(String portletId) 159 { 160 Portlets p = getPortletsById(this.portlets, portletId); 161 return p; 162 } 163 164 173 public Portlets getPortlets(int position) 174 { 175 return getPortlets(this.portlets, position, 0); 176 } 177 178 185 public static Entry getEntry(Portlets portlets, String name) 186 { 187 Entry entry = null; 188 189 for (Iterator it1 = portlets.getEntriesIterator(); it1.hasNext(); ) 190 { 191 entry = (Entry) it1.next(); 192 if (entry.getParent().equals (name)) 193 return (entry); 194 } 195 196 entry = null; 197 198 for (Iterator it2 = portlets.getPortletsIterator(); it2.hasNext(); ) 199 { 200 Portlets p = (Portlets) it2.next(); 201 202 entry = getEntry(p, name); 203 204 if (entry != null) 205 break; 206 } 207 208 return (entry); 209 } 210 211 218 public static Entry getEntryById(Portlets portlets, String entryId) 219 { 220 Entry entry = null; 221 222 for (Iterator it1 = portlets.getEntriesIterator(); it1.hasNext(); ) 223 { 224 entry = (Entry) it1.next(); 225 if ((entry.getId()!=null) && entry.getId().equals (entryId)) 226 return (entry); 227 } 228 229 entry = null; 230 231 for (Iterator it2 = portlets.getPortletsIterator(); it2.hasNext(); ) 232 { 233 Portlets p = (Portlets) it2.next(); 234 235 entry = getEntryById(p, entryId); 236 237 if (entry != null) 238 break; 239 } 240 241 return (entry); 242 } 243 244 251 public static Portlets getPortletsById(Portlets portlets, String portletId) 252 { 253 Portlets entry = portlets; 254 255 if ( (entry.getId()!=null) && entry.getId().equals(portletId) ) 256 { 257 return entry; 258 } 259 260 entry = null; 261 262 for (Iterator it2 = portlets.getPortletsIterator(); it2.hasNext(); ) 263 { 264 Portlets p = (Portlets) it2.next(); 265 266 entry = getPortletsById(p, portletId); 267 268 if (entry != null) break; 269 } 270 271 return (entry); 272 } 273 274 281 public static Portlets getPortlets(Portlets portlets, String name) 282 { 283 Portlets entry = portlets; 284 285 if ( (entry.getName()!=null) && entry.getName().equals(name) ) 286 { 287 return entry; 288 } 289 290 entry = null; 291 292 for (Iterator it2 = portlets.getPortletsIterator(); it2.hasNext(); ) 293 { 294 Portlets p = (Portlets) it2.next(); 295 296 entry = getPortlets(p, name); 297 298 if (entry != null) break; 299 } 300 301 return (entry); 302 } 303 311 public static Portlets getPortlets(Portlets portlets, int position, int count) 312 { 313 if (position < count) 315 { 316 return null; 317 } 318 319 if (position == count) 321 { 322 return portlets; 323 } 324 325 Portlets result = null; 327 328 for (Iterator it2 = portlets.getPortletsIterator(); it2.hasNext(); ) 329 { 330 Portlets p = (Portlets) it2.next(); 331 count++; 332 result = getPortlets(p, position, count); 333 334 if (result != null) break; 335 } 336 337 return result; 338 } 339 345 public boolean removeEntryById(String entryId) 346 { 347 return removeEntryById(this.portlets, entryId); 348 } 349 350 357 public static boolean removeEntryById(Portlets portlets, String entryId) 358 { 359 for (int i=0; i < portlets.getEntryCount(); i++) 360 { 361 if ( entryId.equals(portlets.getEntry(i).getId()) ) 362 { 363 portlets.removeEntry(i); 364 return true; 365 } 366 } 367 368 for (Iterator it2 = portlets.getPortletsIterator(); it2.hasNext(); ) 369 { 370 Portlets p = (Portlets) it2.next(); 371 372 if (removeEntryById(p, entryId) == true) 373 return true; 374 } 375 376 return false; 377 } 378 379 382 public Object clone() 383 throws java.lang.CloneNotSupportedException 384 { 385 Object cloned = super.clone(); 386 387 ((BasePSMLDocument)cloned).portlets = ((this.portlets == null) ? null : (Portlets) this.portlets.clone()); 389 390 return cloned; 391 } 392 } 393 394 | Popular Tags |