1 16 17 package org.apache.jetspeed.portal.controllers; 18 19 import org.apache.jetspeed.portal.BasePortletSetConstraints; 21 import org.apache.jetspeed.portal.PortletConfig; 22 import org.apache.jetspeed.portal.PortletController; 23 import org.apache.jetspeed.portal.PortletControllerConfig; 24 import org.apache.jetspeed.portal.PortletSet; 25 26 import org.apache.jetspeed.capability.CapabilityMap; 27 import org.apache.jetspeed.services.rundata.JetspeedRunData; 28 import org.apache.jetspeed.services.Registry; 29 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 30 import org.apache.jetspeed.services.logging.JetspeedLogger; 31 import org.apache.jetspeed.om.registry.PortletControllerEntry; 32 import org.apache.jetspeed.om.registry.MediaTypeEntry; 33 import org.apache.jetspeed.util.MimeType; 34 35 import org.apache.turbine.util.RunData; 37 38 import org.apache.ecs.ConcreteElement; 40 import org.apache.ecs.ElementContainer; 41 42 import java.util.Map ; 43 import java.util.Iterator ; 44 45 49 public abstract class AbstractPortletController implements PortletController 50 { 51 52 55 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(AbstractPortletController.class.getName()); 56 57 60 public int DEFAULT_PADDING = 3; 61 62 private String width="100%"; 63 private PortletSet portlets = null; 64 private PortletControllerConfig conf = null; 65 66 67 70 public final void setConfig(PortletControllerConfig conf) 71 { 72 this.conf = conf; 73 } 74 75 76 78 public final PortletControllerConfig getConfig() 79 { 80 return this.conf; 81 } 82 83 86 public final void setPortlets(PortletSet portlets) 87 { 88 this.portlets = portlets; 89 } 90 91 92 94 public final PortletSet getPortlets() 95 { 96 return this.portlets; 97 } 98 99 101 public String getWidth() { 102 return this.width; 103 } 104 105 107 public void setWidth(String width) { 108 this.width = width; 109 } 110 111 114 public int getPadding() { 115 int padding = 0; 116 117 try { 118 PortletConfig conf = getPortlets().getPortletConfig(); 119 padding = Integer.parseInt( conf.getSkin( "padding" , String.valueOf( DEFAULT_PADDING ) ) ); 120 } catch ( RuntimeException e ) { 121 logger.error("Exception getting padding value", e); 122 padding = DEFAULT_PADDING; 123 } 124 125 return padding; 126 } 127 128 131 public void setPadding(int padding) { 132 try { 133 PortletConfig conf = getPortlets().getPortletConfig(); 134 conf.setSkin( "padding" , String.valueOf( padding ) ); 135 } catch ( RuntimeException e ) { 136 logger.error("Exception setting padding value", e); 137 } 139 140 } 141 142 145 public void setPadding(String padding) { 146 try { 147 PortletConfig conf = getPortlets().getPortletConfig(); 148 conf.setSkin( "padding" , padding ); 149 } catch ( RuntimeException e ) { 150 logger.error("Exception setting padding value", e); 151 } 153 } 154 155 157 public void init() 158 { 159 } 161 162 163 166 public boolean supportsType( MimeType mimeType ) 167 { 168 PortletControllerEntry entry = 170 (PortletControllerEntry)Registry.getEntry(Registry.PORTLET_CONTROLLER, 171 getConfig().getName() ); 172 String baseType = mimeType.toString(); 173 174 if (entry!=null) 175 { 176 Iterator i = entry.listMediaTypes(); 177 178 while(i.hasNext()) 179 { 180 String name = (String )i.next(); 181 MediaTypeEntry media = (MediaTypeEntry)Registry.getEntry(Registry.MEDIA_TYPE, name); 182 183 if (media != null) 184 { 185 if (baseType.equals(media.getMimeType())) 186 { 187 return true; 188 } 189 } 190 } 191 } 192 193 return false; 194 } 195 196 198 public ConcreteElement getContent( RunData rundata ) 199 { 200 201 CapabilityMap map = ((JetspeedRunData)rundata).getCapability(); 202 ConcreteElement content = null; 203 204 if ( MimeType.WML.equals( map.getPreferredType() ) ) 205 { 206 content = getWMLContent( portlets, rundata ); 207 } 208 else if ( MimeType.HTML.equals( map.getPreferredType() ) ) 209 { 210 content = getHTMLContent( portlets, rundata ); 211 } 212 else 213 { 214 content = getContent( portlets, rundata ); 216 } 217 218 return content; 219 } 220 221 223 protected ConcreteElement getContent( PortletSet set, RunData data ) 224 { 225 return new ElementContainer(); 226 } 227 228 230 protected ConcreteElement getWMLContent( PortletSet set, RunData data ) 231 { 232 return new ElementContainer(); 233 } 234 235 237 protected ConcreteElement getHTMLContent( PortletSet set, RunData data ) 238 { 239 return new ElementContainer(); 240 } 241 242 248 public PortletSet.Constraints getConstraints( Map original ) 249 { 250 PortletSet.Constraints constraints = new BasePortletSetConstraints(); 251 if (original != null) constraints.putAll(original); 252 return constraints; 253 } 254 255 } 256 | Popular Tags |