001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.portal.pluto.om;
018:
019: import java.util.ArrayList;
020: import java.util.Collection;
021: import java.util.Iterator;
022: import java.util.Locale;
023: import java.util.StringTokenizer;
024:
025: import org.apache.cocoon.portal.pluto.om.common.ContentTypeSetImpl;
026: import org.apache.cocoon.portal.pluto.om.common.DescriptionSetImpl;
027: import org.apache.cocoon.portal.pluto.om.common.DisplayNameSetImpl;
028: import org.apache.cocoon.portal.pluto.om.common.LanguageSetImpl;
029: import org.apache.cocoon.portal.pluto.om.common.ParameterSetImpl;
030: import org.apache.cocoon.portal.pluto.om.common.PreferenceSetImpl;
031: import org.apache.cocoon.portal.pluto.om.common.SecurityRoleRefSetImpl;
032: import org.apache.cocoon.portal.pluto.om.common.Support;
033: import org.apache.pluto.invoker.PortletInvoker;
034: import org.apache.pluto.om.common.Description;
035: import org.apache.pluto.om.common.DescriptionSet;
036: import org.apache.pluto.om.common.DisplayName;
037: import org.apache.pluto.om.common.DisplayNameSet;
038: import org.apache.pluto.om.common.LanguageSet;
039: import org.apache.pluto.om.common.ObjectID;
040: import org.apache.pluto.om.common.ParameterSet;
041: import org.apache.pluto.om.common.PreferenceSet;
042: import org.apache.pluto.om.common.SecurityRoleRefSet;
043: import org.apache.pluto.om.portlet.ContentTypeSet;
044: import org.apache.pluto.om.portlet.PortletApplicationDefinition;
045: import org.apache.pluto.om.portlet.PortletDefinition;
046: import org.apache.pluto.om.portlet.PortletDefinitionCtrl;
047: import org.apache.pluto.om.servlet.ServletDefinition;
048:
049: /**
050: *
051: *
052: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
053: *
054: * @version CVS $Id: PortletDefinitionImpl.java 433543 2006-08-22 06:22:54Z crossley $
055: */
056: public class PortletDefinitionImpl implements PortletDefinition,
057: PortletDefinitionCtrl, java.io.Serializable, Support {
058:
059: private PortletApplicationDefinition application = null;
060: private LanguageSet castorResources = null;
061:
062: // contains String objects
063: private ArrayList castorSupportedLocales = new ArrayList();
064: private ClassLoader classLoader;
065: private String className;
066: private ContentTypeSet contentTypes = new ContentTypeSetImpl();
067: private DescriptionSet descriptions = new DescriptionSetImpl();
068:
069: private DisplayNameSet displayNames = new DisplayNameSetImpl();
070: private String expirationCache;
071: public String id = "";
072: private ParameterSet initParams = new ParameterSetImpl();
073: private SecurityRoleRefSet initSecurityRoleRefs = new SecurityRoleRefSetImpl();
074: private String name;
075:
076: private ObjectID objectId;
077: private PreferenceSet preferences = new PreferenceSetImpl();
078:
079: // private PortletInfoImpl portletInfo = null;
080: private String resourceBundle;
081: private ServletDefinition servlet;
082:
083: // contains Locale objects
084: private ArrayList supportedLocales = new ArrayList();
085:
086: /** is this a local portlet? */
087: protected boolean localPortlet = false;
088:
089: /** The local portlet invoker */
090: protected PortletInvoker localPortletInvoker;
091:
092: // PortletDefinition implementation.
093:
094: public ObjectID getId() {
095: if (objectId == null) {
096: objectId = org.apache.cocoon.portal.pluto.om.common.ObjectIDImpl
097: .createFromString(getGUID());
098: }
099:
100: return objectId;
101: }
102:
103: public String getClassName() {
104: return className;
105: }
106:
107: public String getName() {
108: return name;
109: }
110:
111: /* (non-Javadoc)
112: * @see org.apache.pluto.om.portlet.PortletDefinition#getDescription(Locale)
113: */
114: public Description getDescription(Locale locale) {
115: return descriptions.get(locale);
116: }
117:
118: public LanguageSet getLanguageSet() {
119: ((LanguageSetImpl) castorResources).setClassLoader(this
120: .getPortletClassLoader());
121: return castorResources;
122: }
123:
124: public ParameterSet getInitParameterSet() {
125: return initParams;
126: }
127:
128: public SecurityRoleRefSet getInitSecurityRoleRefSet() {
129: return initSecurityRoleRefs;
130: }
131:
132: public PreferenceSet getPreferenceSet() {
133: ((PreferenceSetImpl) preferences).setClassLoader(this
134: .getPortletClassLoader());
135: return preferences;
136: }
137:
138: public ContentTypeSet getContentTypeSet() {
139: return contentTypes;
140: }
141:
142: public PortletApplicationDefinition getPortletApplicationDefinition() {
143: return application;
144: }
145:
146: public ServletDefinition getServletDefinition() {
147: return servlet;
148: }
149:
150: public DisplayName getDisplayName(Locale locale) {
151: return displayNames.get(locale);
152: }
153:
154: public String getExpirationCache() {
155: return expirationCache;
156: }
157:
158: // PortletDefinitionCtrl implementation.
159:
160: public void setId(String id) {
161: // todo excep
162: }
163:
164: public void setClassName(String className) {
165: this .className = className;
166: }
167:
168: public void setName(String name) {
169: this .name = name;
170: }
171:
172: /* (non-Javadoc)
173: * @see org.apache.pluto.om.portlet.PortletDefinitionCtrl#setDescriptions(DescriptionSet)
174: */
175: public void setDescriptions(DescriptionSet descriptions) {
176: this .descriptions = descriptions;
177: }
178:
179: public void setDisplayNames(DisplayNameSet displayNames) {
180: this .displayNames = displayNames;
181: }
182:
183: public void setPortletClassLoader(ClassLoader loader) {
184: this .classLoader = loader;
185: }
186:
187: public void store() throws java.io.IOException {
188: // not supported
189: }
190:
191: public void postBuild(Object parameter) throws Exception {
192: setServletDefinition((ServletDefinition) parameter);
193: ((Support) contentTypes).postBuild(this );
194: if (castorResources != null) {
195: ((Support) castorResources).postBuild(this );
196: }
197: }
198:
199: public void postLoad(Object parameter) throws Exception {
200: ((Support) contentTypes).postLoad(this );
201:
202: // create Locale objects for given locale entries
203: Iterator iterator = castorSupportedLocales.iterator();
204: while (iterator.hasNext()) {
205:
206: String locale = (String) iterator.next();
207:
208: // parse locale String
209: StringTokenizer tokenizer = new StringTokenizer(locale, "_");
210: String[] localeDef = new String[3];
211: for (int i = 0; i < 3; i++) {
212: if (tokenizer.hasMoreTokens()) {
213: localeDef[i] = tokenizer.nextToken();
214: } else {
215: localeDef[i] = "";
216: }
217: }
218: supportedLocales.add(new java.util.Locale(localeDef[0],
219: localeDef[1], localeDef[2]));
220:
221: }
222:
223: if (castorResources == null) {
224: castorResources = new LanguageSetImpl();
225: }
226: if (resourceBundle != null) {
227: ((LanguageSetImpl) castorResources)
228: .setResources(resourceBundle);
229: }
230: ((Support) castorResources).postLoad(this .supportedLocales);
231: ((Support) descriptions).postLoad(parameter);
232: ((Support) displayNames).postLoad(parameter);
233:
234: }
235:
236: public void postStore(Object parameter) throws Exception {
237: ((Support) contentTypes).postStore(this );
238: if (castorResources != null) {
239: ((Support) castorResources).postStore(this );
240: }
241: }
242:
243: public void preBuild(Object parameter) throws Exception {
244: setPortletApplicationDefinition((PortletApplicationDefinition) parameter);
245: ((Support) contentTypes).preBuild(this );
246: if (castorResources != null) {
247: ((Support) castorResources).preBuild(this );
248: }
249: }
250:
251: public void preStore(Object parameter) throws Exception {
252: ((Support) contentTypes).preStore(this );
253: if (castorResources != null) {
254: ((Support) castorResources).preStore(this );
255: }
256: }
257:
258: // additional methods.
259:
260: public Collection getCastorContentTypes() {
261: return (ContentTypeSetImpl) contentTypes;
262: }
263:
264: public Collection getCastorDisplayNames() {
265: return (DisplayNameSetImpl) displayNames;
266: }
267:
268: public Collection getCastorDescriptions() {
269: return (DescriptionSetImpl) descriptions;
270: }
271:
272: public Collection getDescriptions() {
273: return (DescriptionSetImpl) descriptions;
274: }
275:
276: public Collection getCastorInitParams() {
277: return (ParameterSetImpl) initParams;
278: }
279:
280: public SecurityRoleRefSet getCastorInitSecurityRoleRefs() {
281: return initSecurityRoleRefs;
282: }
283:
284: public PreferenceSet getCastorPreferences() {
285: return preferences;
286: }
287:
288: public LanguageSet getCastorResources() {
289: return castorResources;
290: }
291:
292: // not yet fully supported
293: // public Collection getSecurityRoleRef()
294: // {
295: // return securityRoleRef;
296: // }
297:
298: // public void setSecurityRoleRef(Collection securityRoleRef)
299: // {
300: // this.securityRoleRef = (ArrayList)securityRoleRef;
301: // }
302:
303: // additional internal methods
304:
305: public Collection getCastorSupportedLocales() {
306: return castorSupportedLocales;
307: }
308:
309: private String getGUID() {
310: String portletID = "";
311: if (getName() != null)
312: portletID += getName();
313:
314: portletID = application.getId().toString() + "." + portletID;
315: return portletID;
316: }
317:
318: public ClassLoader getPortletClassLoader() {
319: return classLoader;
320: }
321:
322: public String getResourceBundle() {
323: return this .resourceBundle;
324: }
325:
326: public Collection getSupportedLocales() {
327: return supportedLocales;
328: }
329:
330: public void setCastorContentTypes(ContentTypeSet castorContentTypes) {
331: this .contentTypes = castorContentTypes;
332: }
333:
334: public void setCastorInitParams(ParameterSet castorInitParams) {
335: this .initParams = castorInitParams;
336: }
337:
338: public void setCastorInitSecurityRoleRefs(
339: SecurityRoleRefSet castorInitSecurityRoleRefs) {
340: this .initSecurityRoleRefs = castorInitSecurityRoleRefs;
341: }
342:
343: public void setCastorDisplayNames(DisplayNameSet castorDisplayNames) {
344: this .displayNames = castorDisplayNames;
345: }
346:
347: public void setCastorDescriptions(DescriptionSet castorDescriptions) {
348: this .descriptions = castorDescriptions;
349: }
350:
351: public void setCastorPreferences(PreferenceSet castorPreferences) {
352: this .preferences = castorPreferences;
353: }
354:
355: public void setCastorResources(LanguageSet resources) {
356: this .castorResources = resources;
357: }
358:
359: public void setCastorSupportedLocales(
360: Collection castorSupportedLocales) {
361: this .castorSupportedLocales = (ArrayList) castorSupportedLocales;
362: }
363:
364: public void setExpirationCache(String expirationCache) {
365: this .expirationCache = expirationCache;
366: }
367:
368: protected void setPortletApplicationDefinition(
369: PortletApplicationDefinition application) {
370: this .application = application;
371: }
372:
373: public void setResourceBundle(String resourceBundle) {
374: this .resourceBundle = resourceBundle;
375: }
376:
377: protected void setServletDefinition(ServletDefinition servlet) {
378: this .servlet = servlet;
379: }
380:
381: /**
382: * @return Returns the localPortlet.
383: */
384: public boolean isLocalPortlet() {
385: return this .localPortlet;
386: }
387:
388: /**
389: * @param localPortlet The localPortlet to set.
390: */
391: public void setLocalPortlet(boolean localPortlet) {
392: this .localPortlet = localPortlet;
393: }
394:
395: /**
396: * @return Returns the localPortletInvoker.
397: */
398: public PortletInvoker getLocalPortletInvoker() {
399: return this .localPortletInvoker;
400: }
401:
402: /**
403: * Set a local portlet invoker for caching
404: * @param localPortletInvoker The localPortletInvoker to set.
405: */
406: public void setLocalPortletInvoker(
407: PortletInvoker localPortletInvoker) {
408: this.localPortletInvoker = localPortletInvoker;
409: }
410: }
|