1 package org.apache.jetspeed.portal.controls; 2 3 18 19 20 import org.apache.ecs.html.IMG; 22 import org.apache.ecs.html.B; 23 import org.apache.ecs.html.Table; 24 import org.apache.ecs.html.TD; 25 import org.apache.ecs.html.TR; 26 import org.apache.ecs.ConcreteElement; 27 import org.apache.ecs.ElementContainer; 28 29 30 import org.apache.jetspeed.util.JetspeedException; 32 import org.apache.jetspeed.util.MimeType; 33 import org.apache.jetspeed.util.URILookup; 34 import org.apache.jetspeed.capability.CapabilityMap; 35 import org.apache.jetspeed.capability.CapabilityMapFactory; 36 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 37 import org.apache.jetspeed.services.logging.JetspeedLogger; 38 import org.apache.jetspeed.services.resources.JetspeedResources; 39 40 import org.apache.turbine.util.ContentURI; 42 import org.apache.turbine.util.RunData; 43 44 import java.util.Vector ; 46 47 59 public class TitleControl extends AbstractPortletControl { 60 61 64 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(TitleControl.class.getName()); 65 66 73 public ConcreteElement getContent( RunData rundata ) { 74 CapabilityMap cm = CapabilityMapFactory.getCapabilityMap( rundata ); 75 if ( cm.getPreferredType().equals( MimeType.HTML ) ) { 76 return getHTMLContent( rundata ); 77 } 78 if ( cm.getPreferredType().equals( MimeType.WML ) ) { 79 return getWMLContent( rundata ); 80 } 81 logger.error("The Given MIME-Type is not supportet for this control"); 82 return null; 83 } 84 85 86 92 public ConcreteElement getHTMLContent( RunData rundata ) { 93 ElementContainer base = new ElementContainer(); 95 96 Table t = new Table() 98 .setBgColor( this.getColor() ) 99 .setBorder(0) 100 .setCellPadding(1) 101 .setCellSpacing(0) 102 .setWidth( getWidth() ) 103 .setAlign( "center" ); 104 105 106 ConcreteElement[] options = this.getPortletOptions( rundata ); 107 108 TR finalTitle = new TR() 109 .setBgColor( this.getTitleColor() ) 110 .addElement( new TD() 111 .setBgColor( this.getTitleColor() ) 112 .setNoWrap( true ) 113 .setWidth("100%") 114 .setVAlign("middle") 115 .addElement( new B() 116 .addElement( getPortlet().getTitle() ) 117 .addElement(" ") ) ); 118 119 if ( options.length > 0 ) { 120 121 ElementContainer alloptions = new ElementContainer(); 122 for (int i = 0; i < options.length; ++i) { 123 alloptions.addElement( options[i] ); 124 } 125 126 finalTitle.addElement( new TD() 127 .setBgColor( this.getTitleColor() ) 128 .setNoWrap( true ) 129 .setAlign("right") 130 .setVAlign("middle") 131 .addElement( alloptions ) ); 132 133 } 134 135 136 137 t.addElement( finalTitle ); 138 139 base.addElement( t ); 140 141 return base; 142 } 143 144 150 public ConcreteElement getWMLContent( RunData rundata ) { 151 ElementContainer ec = new ElementContainer(); 152 try { 153 ec.addElement(new org.apache.ecs.wml.P() 154 .addElement( 155 new org.apache.ecs.wml.A( 156 URILookup.getURI( URILookup.TYPE_HOME, 157 URILookup.SUBTYPE_MAXIMIZE, 158 getName(), 159 rundata ) ) 160 .addElement( getTitle() ) ) ); 161 } 162 catch (JetspeedException e) { 163 logger.error("Exception", e); 164 } 165 return ec; 166 } 167 168 169 173 public String getTitle(){ 174 return getPortlet().getTitle(); 175 } 176 177 185 public boolean supportsType( MimeType mimeType ) { 186 if ( (!MimeType.HTML.equals( mimeType )) && 187 (!MimeType.WML.equals( mimeType )) ){ 188 return false; 189 } 190 return getPortlet().supportsType( mimeType ); 192 } 193 194 197 private ConcreteElement[] getPortletOptions( RunData rundata ) { 198 199 Vector v = new Vector (); 200 ContentURI content = new ContentURI( rundata ); 201 202 int type = URILookup.getURIType(this.getPortlet(), 203 rundata); 204 int subtype = URILookup.SUBTYPE_NONE; 205 try { 206 subtype = URILookup.getURISubType(this.getPortlet(), 207 rundata); 208 } 209 catch (JetspeedException e) { 210 logger.error("Exception", e); 211 } 212 213 if ( type != URILookup.TYPE_EDIT_ACCOUNT) { 214 if ( ( rundata.getUser() != null ) && 215 ( rundata.getUser().hasLoggedIn()) ) { 216 if ( this.getPortlet().getAllowEdit( rundata ) ) { 217 if (type!=URILookup.TYPE_INFO) { 218 try { 219 org.apache.ecs.html.A edit = 220 new org.apache.ecs.html.A( 221 URILookup.getURI( URILookup.TYPE_INFO, 222 URILookup.SUBTYPE_MARK, 223 this.getPortlet(), 224 rundata ) ) 225 .addElement( new IMG( content.getURI( JetspeedResources.INFO_IMAGE ) ) 226 .setBorder( 0 ) ); 227 228 v.addElement( edit ); 229 } 230 catch (JetspeedException e) { 231 logger.error("Exception", e); 232 } 233 } 234 } 235 236 } 237 238 if ( this.getPortlet().getAllowMaximize( rundata ) ) { 239 try { 240 if ( subtype != URILookup.SUBTYPE_MAXIMIZE ) { 241 org.apache.ecs.html.A max = 242 new org.apache.ecs.html.A( 243 URILookup.getURI( URILookup.TYPE_HOME, 244 URILookup.SUBTYPE_MAXIMIZE, 245 this.getPortlet(), 246 rundata ) ) 247 .addElement( new IMG( content.getURI( JetspeedResources.MAX_IMAGE ) ) 248 .setBorder( 0 ) ); 249 250 v.addElement( max ); 251 } 252 } 253 catch (JetspeedException e) { 254 logger.error("Exception", e); 255 } 256 } 257 } 258 259 ConcreteElement[] elements = new ConcreteElement[v.size()]; 260 v.copyInto(elements); 261 return elements; 262 } 263 264 265 266 } 267 | Popular Tags |