1 16 package org.apache.cocoon.portal.pluto.om; 17 18 import java.util.ArrayList ; 19 import java.util.Collection ; 20 import java.util.Iterator ; 21 import java.util.Locale ; 22 import java.util.StringTokenizer ; 23 24 import org.apache.cocoon.portal.pluto.om.common.ContentTypeSetImpl; 25 import org.apache.cocoon.portal.pluto.om.common.DescriptionSetImpl; 26 import org.apache.cocoon.portal.pluto.om.common.DisplayNameSetImpl; 27 import org.apache.cocoon.portal.pluto.om.common.LanguageSetImpl; 28 import org.apache.cocoon.portal.pluto.om.common.ParameterSetImpl; 29 import org.apache.cocoon.portal.pluto.om.common.PreferenceSetImpl; 30 import org.apache.cocoon.portal.pluto.om.common.SecurityRoleRefSetImpl; 31 import org.apache.cocoon.portal.pluto.om.common.Support; 32 import org.apache.pluto.invoker.PortletInvoker; 33 import org.apache.pluto.om.common.Description; 34 import org.apache.pluto.om.common.DescriptionSet; 35 import org.apache.pluto.om.common.DisplayName; 36 import org.apache.pluto.om.common.DisplayNameSet; 37 import org.apache.pluto.om.common.LanguageSet; 38 import org.apache.pluto.om.common.ObjectID; 39 import org.apache.pluto.om.common.ParameterSet; 40 import org.apache.pluto.om.common.PreferenceSet; 41 import org.apache.pluto.om.common.SecurityRoleRefSet; 42 import org.apache.pluto.om.portlet.ContentTypeSet; 43 import org.apache.pluto.om.portlet.PortletApplicationDefinition; 44 import org.apache.pluto.om.portlet.PortletDefinition; 45 import org.apache.pluto.om.portlet.PortletDefinitionCtrl; 46 import org.apache.pluto.om.servlet.ServletDefinition; 47 48 55 public class PortletDefinitionImpl 56 implements PortletDefinition, PortletDefinitionCtrl, java.io.Serializable , Support { 57 58 59 private PortletApplicationDefinition application = null; 60 private LanguageSet castorResources = null; 61 62 private ArrayList castorSupportedLocales = new ArrayList (); 64 private ClassLoader classLoader; 65 private String className; 66 private ContentTypeSet contentTypes = new ContentTypeSetImpl(); 67 private DescriptionSet descriptions = new DescriptionSetImpl(); 68 69 private DisplayNameSet displayNames = new DisplayNameSetImpl(); 70 private String expirationCache; 71 public String id = ""; 72 private ParameterSet initParams = new ParameterSetImpl(); 73 private SecurityRoleRefSet initSecurityRoleRefs = new SecurityRoleRefSetImpl(); 74 private String name; 75 76 private ObjectID objectId; 77 private PreferenceSet preferences = new PreferenceSetImpl(); 78 79 private String resourceBundle; 81 private ServletDefinition servlet; 82 83 private ArrayList supportedLocales = new ArrayList (); 85 86 87 protected boolean localPortlet = false; 88 89 90 protected PortletInvoker localPortletInvoker; 91 92 94 public ObjectID getId() { 95 if (objectId==null) { 96 objectId = org.apache.cocoon.portal.pluto.om.common.ObjectIDImpl.createFromString(getGUID()); 97 } 98 99 return objectId; 100 } 101 102 public String getClassName() { 103 return className; 104 } 105 106 public String getName() { 107 return name; 108 } 109 110 113 public Description getDescription(Locale locale) { 114 return descriptions.get(locale); 115 } 116 117 public LanguageSet getLanguageSet() { 118 ((LanguageSetImpl)castorResources).setClassLoader(this.getPortletClassLoader()); 119 return castorResources; 120 } 121 122 public ParameterSet getInitParameterSet() { 123 return initParams; 124 } 125 126 public SecurityRoleRefSet getInitSecurityRoleRefSet() { 127 return initSecurityRoleRefs; 128 } 129 130 public PreferenceSet getPreferenceSet() { 131 ((PreferenceSetImpl)preferences).setClassLoader(this.getPortletClassLoader()); 132 return preferences; 133 } 134 135 public ContentTypeSet getContentTypeSet() { 136 return contentTypes; 137 } 138 139 public PortletApplicationDefinition getPortletApplicationDefinition() { 140 return application; 141 } 142 143 public ServletDefinition getServletDefinition() { 144 return servlet; 145 } 146 147 public DisplayName getDisplayName(Locale locale) { 148 return displayNames.get(locale); 149 } 150 151 public String getExpirationCache() { 152 return expirationCache; 153 } 154 155 157 public void setId(String id) { 158 } 160 161 public void setClassName(String className) { 162 this.className = className; 163 } 164 165 public void setName(String name) { 166 this.name = name; 167 } 168 169 172 public void setDescriptions(DescriptionSet descriptions) { 173 this.descriptions = descriptions; 174 } 175 176 public void setDisplayNames(DisplayNameSet displayNames) { 177 this.displayNames = displayNames; 178 } 179 180 public void setPortletClassLoader(ClassLoader loader) { 181 this.classLoader = loader; 182 } 183 184 public void store() throws java.io.IOException { 185 } 187 188 189 public void postBuild(Object parameter) throws Exception { 190 setServletDefinition((ServletDefinition)parameter); 191 ((Support)contentTypes).postBuild(this); 192 if (castorResources!=null) { 193 ((Support)castorResources).postBuild(this); 194 } 195 } 196 197 public void postLoad(Object parameter) throws Exception { 198 ((Support)contentTypes).postLoad(this); 199 200 Iterator iterator = castorSupportedLocales.iterator(); 202 while (iterator.hasNext()) { 203 204 String locale = (String )iterator.next(); 205 206 StringTokenizer tokenizer = new StringTokenizer (locale,"_"); 208 String [] localeDef = new String [3]; 209 for (int i=0; i<3 ;i++) { 210 if (tokenizer.hasMoreTokens()) { 211 localeDef[i] = tokenizer.nextToken(); 212 } else { 213 localeDef[i] = ""; 214 } 215 } 216 supportedLocales.add(new java.util.Locale (localeDef[0], localeDef[1], localeDef[2])); 217 218 } 219 220 if (castorResources==null) { 221 castorResources = new LanguageSetImpl(); 222 } 223 if (resourceBundle!=null) { 224 ((LanguageSetImpl)castorResources).setResources(resourceBundle); 225 } 226 ((Support)castorResources).postLoad(this.supportedLocales); 227 ((Support)descriptions).postLoad(parameter); 228 ((Support)displayNames).postLoad(parameter); 229 230 } 231 public void postStore(Object parameter) throws Exception { 232 ((Support)contentTypes).postStore(this); 233 if (castorResources!=null) { 234 ((Support)castorResources).postStore(this); 235 } 236 } 237 public void preBuild(Object parameter) throws Exception { 238 setPortletApplicationDefinition((PortletApplicationDefinition)parameter); 239 ((Support)contentTypes).preBuild(this); 240 if (castorResources!=null) { 241 ((Support)castorResources).preBuild(this); 242 } 243 } 244 public void preStore(Object parameter) throws Exception { 245 ((Support)contentTypes).preStore(this); 246 if (castorResources!=null) { 247 ((Support)castorResources).preStore(this); 248 } 249 } 250 251 253 public Collection getCastorContentTypes() { 254 return(ContentTypeSetImpl)contentTypes; 255 } 256 257 public Collection getCastorDisplayNames() { 258 return(DisplayNameSetImpl)displayNames; 259 } 260 261 public Collection getCastorDescriptions() { 262 return(DescriptionSetImpl)descriptions; 263 } 264 265 public Collection getDescriptions() { 266 return(DescriptionSetImpl)descriptions; 267 } 268 269 public Collection getCastorInitParams() { 270 return(ParameterSetImpl)initParams; 271 } 272 273 public SecurityRoleRefSet getCastorInitSecurityRoleRefs() { 274 return initSecurityRoleRefs; 275 } 276 277 public PreferenceSet getCastorPreferences() { 278 return preferences; 279 } 280 281 public LanguageSet getCastorResources() { 282 return castorResources; 283 } 284 285 291 296 298 public Collection getCastorSupportedLocales() { 299 return castorSupportedLocales; 300 } 301 302 303 private String getGUID() { 304 String portletID = ""; 305 if (getName()!=null) portletID += getName(); 306 307 portletID = application.getId().toString() + "."+portletID; 308 return portletID; 309 } 310 311 public ClassLoader getPortletClassLoader() { 312 return classLoader; 313 } 314 315 public String getResourceBundle() { 316 return this.resourceBundle; 317 } 318 319 public Collection getSupportedLocales() { 320 return supportedLocales; 321 } 322 323 public void setCastorContentTypes(ContentTypeSet castorContentTypes) { 324 this.contentTypes = castorContentTypes; 325 } 326 327 public void setCastorInitParams(ParameterSet castorInitParams) { 328 this.initParams = castorInitParams; 329 } 330 331 public void setCastorInitSecurityRoleRefs(SecurityRoleRefSet castorInitSecurityRoleRefs) { 332 this.initSecurityRoleRefs = castorInitSecurityRoleRefs; 333 } 334 335 public void setCastorDisplayNames(DisplayNameSet castorDisplayNames) { 336 this.displayNames = castorDisplayNames; 337 } 338 339 public void setCastorDescriptions(DescriptionSet castorDescriptions) { 340 this.descriptions = castorDescriptions; 341 } 342 343 public void setCastorPreferences(PreferenceSet castorPreferences) { 344 this.preferences = castorPreferences; 345 } 346 347 public void setCastorResources(LanguageSet resources) { 348 this.castorResources = resources; 349 } 350 351 public void setCastorSupportedLocales(Collection castorSupportedLocales) { 352 this.castorSupportedLocales = (ArrayList )castorSupportedLocales; 353 } 354 355 public void setExpirationCache(String expirationCache) { 356 this.expirationCache = expirationCache; 357 } 358 359 protected void setPortletApplicationDefinition(PortletApplicationDefinition application) { 360 this.application = application; 361 } 362 363 public void setResourceBundle(String resourceBundle) { 364 this.resourceBundle = resourceBundle; 365 } 366 367 protected void setServletDefinition(ServletDefinition servlet) { 368 this.servlet = servlet; 369 } 370 371 374 public boolean isLocalPortlet() { 375 return this.localPortlet; 376 } 377 378 381 public void setLocalPortlet(boolean localPortlet) { 382 this.localPortlet = localPortlet; 383 } 384 385 388 public PortletInvoker getLocalPortletInvoker() { 389 return this.localPortletInvoker; 390 } 391 392 396 public void setLocalPortletInvoker(PortletInvoker localPortletInvoker) { 397 this.localPortletInvoker = localPortletInvoker; 398 } 399 } 400 | Popular Tags |