1 16 17 package org.apache.jetspeed.portal.controls; 18 19 import java.util.Enumeration ; 20 import java.util.Iterator ; 21 import java.util.Vector ; 22 23 import org.apache.jetspeed.om.registry.PortletControlEntry; 25 import org.apache.jetspeed.om.registry.MediaTypeEntry; 26 import org.apache.jetspeed.om.security.JetspeedUser; 27 import org.apache.jetspeed.portal.Portlet; 28 import org.apache.jetspeed.portal.PortletState; 29 import org.apache.jetspeed.portal.PortletConfig; 30 import org.apache.jetspeed.portal.PortletSet; 31 import org.apache.jetspeed.portal.PortletControl; 32 import org.apache.jetspeed.portal.PortletControlConfig; 33 import org.apache.jetspeed.portal.PortletController; 34 import org.apache.jetspeed.portal.PortletException; 35 import org.apache.jetspeed.portal.portlets.AbstractPortlet; 36 import org.apache.jetspeed.portal.security.portlets.PortletWrapper; 37 import org.apache.jetspeed.services.Registry; 38 import org.apache.jetspeed.services.JetspeedSecurity; 39 import org.apache.jetspeed.util.MimeType; 40 import org.apache.jetspeed.services.resources.JetspeedResources; 41 42 import org.apache.turbine.util.RunData; 44 45 import org.apache.ecs.ElementContainer; 47 import org.apache.ecs.ConcreteElement; 48 import org.apache.ecs.StringElement; 49 50 63 public abstract class AbstractPortletControl extends AbstractPortlet 64 implements PortletControl 65 { 66 67 public static final String COLOR = "#CCCCCC"; 68 public static final String BACKGROUND_COLOR = "#FFFFFF"; 69 public static final String TITLE_COLOR = "#DDDDDD"; 70 public static final String WIDTH = "100%"; 71 72 private Portlet portlet = null; 73 private PortletControlConfig conf = null; 74 75 77 80 public PortletControlConfig getConfig() 81 { 82 return this.conf; 83 } 84 85 89 public void setConfig(PortletControlConfig conf) 90 { 91 this.conf=conf; 92 } 93 94 99 public void setPortlet(Portlet portlet) 100 { 101 this.portlet=portlet; 102 } 103 104 108 public Portlet getPortlet() 109 { 110 return this.portlet; 111 } 112 113 118 public void init( Portlet portlet ) 119 { 120 this.setPortlet( portlet ); 121 } 122 123 131 public String getColor() 132 { 133 return getPortlet().getPortletConfig().getPortletSkin().getTextColor(); 134 } 135 136 144 public void setColor(String color) 145 { 146 getPortlet().getPortletConfig().getPortletSkin().setTextColor( color ); 147 } 148 149 157 public String getBackgroundColor() 158 { 159 return getPortlet().getPortletConfig().getPortletSkin().getBackgroundColor(); 160 } 161 162 170 public void setBackgroundColor(String backgroundColor) 171 { 172 getPortlet().getPortletConfig().getPortletSkin().setBackgroundColor( backgroundColor ); 173 } 174 175 183 public String getTitleColor() 184 { 185 return getPortlet().getPortletConfig().getPortletSkin().getTitleBackgroundColor(); 186 } 187 188 196 public void setTitleColor(String titleColor) 197 { 198 getPortlet().getPortletConfig().getPortletSkin().setTitleBackgroundColor( titleColor ); 199 } 200 201 209 public String getWidth() { 210 return getPortlet().getPortletConfig().getSkin( "width", WIDTH ); 211 } 212 213 222 public void setWidth(int width) 223 { 224 getPortlet().getPortletConfig().setSkin( "width", String.valueOf(width) ); 225 } 226 227 237 public void setWidth(String width) 238 { 239 getPortlet().getPortletConfig().setSkin( "width", width ); 240 } 241 242 243 246 249 public PortletConfig getPortletConfig() 250 { 251 if (getPortlet()==null) return null; 252 return getPortlet().getPortletConfig(); 253 } 254 255 260 public void setPortletConfig(PortletConfig portletConfig) 261 { 262 if (getPortlet()==null) return; 263 getPortlet().setPortletConfig(portletConfig); 264 } 265 266 269 public String getName() 270 { 271 if (getPortlet()==null) return null; 272 return getPortlet().getName(); 273 } 274 275 280 public void setName(String name) 281 { 282 if (getPortlet()!=null) getPortlet().setName(name); 283 } 284 285 288 public String getTitle() 289 { 290 if (getPortlet()==null) return null; 291 return getPortlet().getTitle(); 292 } 293 294 299 public void setTitle( String title ) 300 { 301 if (getPortlet()!=null) getPortlet().setTitle(title); 302 } 303 304 307 public String getDescription() 308 { 309 if (getPortlet()==null) return null; 310 return getPortlet().getDescription(); 311 } 312 313 318 public void setDescription( String description ) 319 { 320 if (getPortlet()!=null) getPortlet().setDescription(description); 321 } 322 323 326 public void init() throws PortletException 327 { 328 if (getPortlet()!=null) getPortlet().init(); 329 } 330 331 336 public ConcreteElement getContent(RunData rundata) 337 { 338 Portlet portlet = getPortlet(); 339 if (portlet == null) 340 { 341 return new ElementContainer(); 342 } 343 344 if (portlet instanceof PortletWrapper) 348 { 349 PortletWrapper wrapper = (PortletWrapper)portlet; 350 if (!wrapper.getAllowView(rundata)) 351 { 352 if (JetspeedResources.getBoolean("defaultportletcontrol.hide.decorator", true)) 353 { 354 return new StringElement(""); 355 } 356 } 357 } 358 359 return portlet.getContent( rundata ); 360 } 361 362 365 public boolean supportsType( MimeType mimeType ) 366 { 367 boolean allowed = true; 368 369 if (getPortlet()!=null) 370 { 371 allowed = getPortlet().supportsType( mimeType ); 372 } 373 374 if (allowed) 376 { 377 PortletControlEntry entry = 379 (PortletControlEntry)Registry.getEntry(Registry.PORTLET_CONTROL, 380 getConfig().getName() ); 381 String baseType = mimeType.toString(); 382 383 if (entry!=null) 384 { 385 Iterator i = entry.listMediaTypes(); 386 387 while(i.hasNext()) 388 { 389 String name = (String )i.next(); 390 MediaTypeEntry media = (MediaTypeEntry)Registry.getEntry(Registry.MEDIA_TYPE, name); 391 392 if (media != null) 393 { 394 if (baseType.equals(media.getMimeType())) 395 { 396 allowed = true; 397 break; 398 } 399 } 400 } 401 } 402 } 403 404 return allowed; 405 } 406 407 410 414 public int size() 415 { 416 if (getPortlet() instanceof PortletSet) 417 return ((PortletSet)getPortlet()).size(); 418 419 return ((getPortlet()==null)?0:1); 420 } 421 422 426 public Portlet[] toArray() 427 { 428 if (getPortlet() instanceof PortletSet) 429 return ((PortletSet)getPortlet()).toArray(); 430 431 Portlet[] p = new Portlet[1]; 432 p[0]=getPortlet(); 433 434 return p; 435 } 436 437 445 public Portlet getPortletAt(int pos) 446 { 447 if (getPortlet() instanceof PortletSet) 448 return ((PortletSet)getPortlet()).getPortletAt(pos); 449 450 if (pos==0) 451 return getPortlet(); 452 else 453 return null; 454 } 455 456 462 public Enumeration getPortlets() 463 { 464 if (getPortlet() instanceof PortletSet) 465 return ((PortletSet)getPortlet()).getPortlets(); 466 467 Vector v = new Vector (); 468 if (getPortlet()!=null) v.addElement(getPortlet()); 469 470 return v.elements(); 471 } 472 473 478 public synchronized void addPortlet(Portlet portlet) 479 { 480 if (getPortlet() instanceof PortletSet) 481 ((PortletSet)getPortlet()).addPortlet(portlet); 482 } 483 484 490 public synchronized void addPortlet(Portlet portlet, int position) 491 { 492 if (getPortlet() instanceof PortletSet) 493 ((PortletSet)getPortlet()).addPortlet(portlet,position); 494 } 495 496 502 public synchronized void addPortlet(Portlet portlet, PortletSet.Constraints constraints) 503 { 504 if (getPortlet() instanceof PortletSet) 505 ((PortletSet)getPortlet()).addPortlet(portlet,constraints); 506 } 507 508 516 public synchronized void addPortlet(Portlet portlet, PortletSet.Constraints constraint, int position) 517 { 518 if (getPortlet() instanceof PortletSet) 519 ((PortletSet)getPortlet()).addPortlet(portlet,constraint,position); 520 } 521 522 525 public PortletController getController() 526 { 527 if (getPortlet() instanceof PortletSet) 528 return ((PortletSet)getPortlet()).getController(); 529 530 return null; 531 } 532 533 539 public synchronized void setController(PortletController controller) 540 { 541 if (getPortlet() instanceof PortletSet) 542 ((PortletSet)getPortlet()).setController(controller); 543 } 544 545 547 553 public boolean allowClose( RunData rundata ) 554 { 555 Portlet p = getPortlet(); 556 557 if (p==null) return false; 558 559 if ((p instanceof PortletSet) 560 ||(JetspeedSecurity.checkPermission((JetspeedUser) rundata.getUser(), 561 p, 562 JetspeedSecurity.PERMISSION_CLOSE))) 563 { 564 if (p instanceof PortletState) 565 { 566 return ((PortletState)p).allowClose(rundata); 567 } 568 } 569 570 return false; 571 } 572 573 576 public boolean isClosed(RunData rundata) 577 { 578 Portlet p = getPortlet(); 579 580 if ( (p!=null) && (p instanceof PortletState) ) 581 { 582 return ((PortletState)p).isClosed(rundata); 583 } 584 585 return false; 586 } 587 588 594 public void setClosed(boolean close, RunData rundata) 595 { 596 Portlet p = getPortlet(); 597 598 if ( (p!=null) && (p instanceof PortletState) ) 599 { 600 ((PortletState)p).setClosed(close, rundata); 601 } 602 } 603 604 610 public boolean allowInfo( RunData rundata ) 611 { 612 Portlet p = getPortlet(); 613 614 if (p==null) return false; 615 616 if ((p instanceof PortletSet) 617 ||(JetspeedSecurity.checkPermission((JetspeedUser) rundata.getUser(), 618 p, 619 JetspeedSecurity.PERMISSION_INFO))) 620 { 621 if (p instanceof PortletState) 622 { 623 return ((PortletState)p).allowInfo(rundata); 624 } 625 } 626 627 return false; 628 } 629 630 636 public boolean allowCustomize( RunData rundata ) 637 { 638 Portlet p = getPortlet(); 639 640 if (p==null) return false; 641 642 if ((p instanceof PortletSet) 643 ||(JetspeedSecurity.checkPermission((JetspeedUser) rundata.getUser(), 644 p, 645 JetspeedSecurity.PERMISSION_CUSTOMIZE))) 646 { 647 if (p instanceof PortletState) 648 { 649 return ((PortletState)p).allowCustomize(rundata); 650 } 651 } 652 653 return false; 654 } 655 656 662 public boolean allowMaximize( RunData rundata ) 663 { 664 Portlet p = getPortlet(); 665 666 if (p==null) return false; 667 668 if ((p instanceof PortletSet) 669 ||(JetspeedSecurity.checkPermission((JetspeedUser) rundata.getUser(), 670 p, 671 JetspeedSecurity.PERMISSION_MAXIMIZE))) 672 { 673 if (p instanceof PortletState) 674 { 675 return ((PortletState)p).allowMaximize(rundata); 676 } 677 } 678 679 return false; 680 } 681 682 688 public boolean allowMinimize( RunData rundata ) 689 { 690 Portlet p = getPortlet(); 691 692 if (p==null) return false; 693 694 if ((p instanceof PortletSet) 695 ||(JetspeedSecurity.checkPermission((JetspeedUser) rundata.getUser(), 696 p, 697 JetspeedSecurity.PERMISSION_MINIMIZE))) 698 { 699 if (p instanceof PortletState) 700 { 701 return ((PortletState)p).allowMinimize(rundata); 702 } 703 } 704 705 return false; 706 } 707 708 714 public boolean allowPrintFriendly( RunData rundata ) 715 { 716 Portlet p = getPortlet(); 717 718 if (p==null) return false; 719 720 if ((p instanceof PortletSet) 721 ||(JetspeedSecurity.checkPermission((JetspeedUser) rundata.getUser(), 722 p, 723 JetspeedSecurity.PERMISSION_PRINT_FRIENDLY))) 724 { 725 if (p instanceof PortletState) 726 { 727 return ((PortletState)p).allowPrintFriendly(rundata); 728 } 729 } 730 731 return false; 732 } 733 734 737 public boolean isMinimized(RunData rundata) 738 { 739 Portlet p = getPortlet(); 740 741 if ( (p!=null) && (p instanceof PortletState) ) 742 { 743 return ((PortletState)p).isMinimized(rundata); 744 } 745 746 return false; 747 } 748 749 755 public void setMinimized( boolean minimize, RunData rundata ) 756 { 757 Portlet p = getPortlet(); 758 759 if ( (p!=null) && (p instanceof PortletState) ) 760 { 761 ((PortletState)p).setMinimized( minimize, rundata); 762 } 763 } 764 765 public String getID() 766 { 767 return this.portlet.getID(); 768 } 769 770 public void setID(String id) 771 { 772 this.portlet.setID(id); 773 } 774 775 778 public Portlet getPortletByID(String id) 779 { 780 Portlet p = getPortlet(); 781 if (null == p) 782 return null; 783 784 if (p instanceof PortletSet) 785 { 786 Enumeration e = ((PortletSet)p).getPortlets(); 787 Portlet portlet = null; 788 while ( e.hasMoreElements() ) 789 { 790 portlet = (Portlet)e.nextElement(); 791 if (portlet.getID().equals(id)) 792 return portlet; 793 } 794 return portlet; 795 } 796 return null; 797 } 798 799 802 public Portlet getPortletByName(String name) 803 { 804 Portlet p = getPortlet(); 805 if (null == p) 806 return null; 807 808 if (p instanceof PortletSet) 809 { 810 Enumeration e = ((PortletSet)p).getPortlets(); 811 Portlet portlet = null; 812 while ( e.hasMoreElements() ) 813 { 814 portlet = (Portlet)e.nextElement(); 815 if (portlet.getName().equals(name)) 816 return portlet; 817 } 818 return portlet; 819 } 820 return null; 821 } 822 823 824 } 825 | Popular Tags |