1/*2 * Copyright 2000-2001,2004 The Apache Software Foundation.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.om.registry.base;
1819import java.util.Iterator;
20import java.util.Vector;
21import java.util.Map;
22import java.util.Hashtable;
23import java.util.HashMap;
2425importorg.apache.jetspeed.om.registry.*;
26import org.apache.jetspeed.services.Registry;
2728/***29 * Default bean like implementation of the PortletEntry interface30 * suitable for serialization with Castor31 *32 * @author <a href="mailto:raphael@apache.org">Raphaël Luta</a>33 * @version $Id: BasePortletEntry.java,v 1.5 2004/02/23 03:08:26 jford Exp $34 */35publicclassBasePortletEntryextendsBasePortletInfoEntry36 implements PortletEntry, java.io.Serializable
37 {
3839private String parent;
4041privateContentURL url = newBaseContentURL();
4243protected Vector categories = new Vector();
4445privateboolean application;
4647private String type = PortletEntry.TYPE_ABSTRACT;
4849privateboolean isRef = true;
5051/***52 * Implements the equals operation so that 2 elements are equal if53 * all their member values are equal.54 */55publicboolean equals(Object object)
56 {
57if (object==null)
58 {
59return false;
60 }
6162BasePortletEntry obj = (BasePortletEntry)object;
6364if (application!=obj.isApplication())
65 {
66return false;
67 }
6869if (parent!=null)
70 {
71if (!parent.equals(obj.getParent()))
72 {
73return false;
74 }
75 }
76else77 {
78if (obj.getParent()!=null)
79 {
80return false;
81 }
82 }
8384if (type!=null)
85 {
86if (!type.equals(obj.getType()))
87 {
88return false;
89 }
90 }
91else92 {
93if (obj.getType()!=null)
94 {
95return false;
96 }
97 }
9899if (url!=null)
100 {
101if (!url.equals(obj.getContentURL()))
102 {
103return false;
104 }
105 }
106else107 {
108if (obj.getContentURL()!=null)
109 {
110return false;
111 }
112 }
113114 Iterator i = categories.iterator();
115 Iterator i2 = obj.getCategories().iterator();
116while(i.hasNext())
117 {
118BaseCategory c1 = (BaseCategory)i.next();
119BaseCategory c2 = null;
120121if (i2.hasNext())
122 {
123 c2 = (BaseCategory)i2.next();
124 }
125else126 {
127return false;
128 }
129130if (!c1.equals(c2))
131 {
132return false;
133 }
134 }
135136if (i2.hasNext())
137 {
138return false;
139 }
140141returnsuper.equals(object);
142 }
143144/*** @return the URL associated with this portlet or null */145public String getURL()
146 {
147returnthis.url.getURL();
148 }
149150/***151 * Sets the URL for this PortletEntry152 * @param url the new PortletEntry URL153 */154publicvoid setURL( String url )
155 {
156this.url.setURL(url);
157 }
158159publicboolean isCachedOnURL()
160 {
161return url.isCacheKey();
162 }
163164publicvoid setCachedOnURL(boolean cache)
165 {
166 url.setCachedOnURL(cache);
167 }
168169publicContentURL getURLEntry()
170 {
171return url;
172 }
173174/*** @return the entry name from which this one is derived */175public String getParent()
176 {
177returnthis.parent;
178 }
179180/*** @return the classname associated to this entry */181public String getClassname()
182 {
183if (isRef && (classname == null) )
184 {
185return getParentEntry().getClassname();
186 }
187188return classname;
189 }
190191192/***193 * Sets the ancestor for this PortletEntry.194 * @param parent the new ancestor entry name. This name should195 * be defined in the system registry196 */197publicvoid setParent( String parent )
198 {
199this.parent = parent;
200 }
201202/*** @return true is this entry is only accessible by the203 * portal administrators.204 */205publicboolean isAdmin()
206 {
207if (getSecurity()!=null)
208 {
209return"admin".equals(getSecurity().getRole());
210 }
211212return false;
213 }
214215/*** @return true is the PortletEntry is marked as an application */216publicboolean isApplication()
217 {
218returnthis.application;
219 }
220221/*** Sets the application status of this portlet entry. If an entry222 * is maked as application, the associated portlet will only be displayed223 * in Maximized mode and can be retrieved specifically224 *225 * @param application the new application status226 */227publicvoid setApplication( boolean application )
228 {
229this.application = application;
230 }
231232/*** @return the type of this entry */233public String getType()
234 {
235returnthis.type;
236 }
237238/*** Sets the type of this entry. The type specifies whether it is239 * abstract, instance or ref240 *241 * @param type the new type for the PortletEntry242 */243publicvoid setType( String type )
244 {
245this.isRef = PortletEntry.TYPE_REF.equals(type);
246this.type = type;
247 }
248249/*** This method is used by the Castor persistence system to retrieve250 * the application status251 *252 * @see PortletEntry#isApplication253 * @return the application status of this entry254 */255publicboolean getApplication()
256 {
257returnthis.application;
258 }
259260public String getTitle()
261 {
262 String title = super.getTitle();
263if (title != null)
264return title;
265if (isRef)
266 {
267return getParentEntry().getTitle();
268 }
269returnnull;
270 }
271272public String getDescription()
273 {
274 String desc = super.getDescription();
275if (desc != null)
276return desc;
277278if (isRef)
279 {
280return getParentEntry().getDescription();
281 }
282returnnull;
283 }
284285/*** Looks up in the Registry the parent entry for this real entry */286publicPortletEntry getParentEntry()
287 {
288PortletEntry parent = null;
289 parent = (PortletEntry)Registry.getEntry( Registry.PORTLET, getParent() );
290if (parent == null)
291 {
292 parent = newBasePortletEntry();
293 parent.setName(getParent());
294 parent.setType(PortletEntry.TYPE_ABSTRACT);
295 }
296return parent;
297 }
298299publicMetaInfo getMetaInfo()
300 {
301MetaInfo meta = super.getMetaInfo();
302if (meta == null)
303 {
304return getParentEntry().getMetaInfo();
305 }
306return meta;
307 }
308309/*** @return an enumeration of this entry parameter names */310public Iterator getParameterNames()
311 {
312if (isRef)
313 {
314 Hashtable hash = new Hashtable();
315 Iterator i = super.getParameterNames();
316while(i.hasNext())
317 {
318 hash.put(i.next(),"1");
319 }
320 i = getParentEntry().getParameterNames();
321while(i.hasNext())
322 {
323 hash.put(i.next(),"1");
324 }
325326return hash.keySet().iterator();
327 }
328329returnsuper.getParameterNames();
330 }
331332/*** Search for a named parameter and return the associated333 * parameter object. The search is case sensitive.334 *335 * @return the parameter object for a given parameter name336 * @param name the parameter name to look for337 */338publicParameter getParameter( String name )
339 {
340Parameter p = super.getParameter(name);
341if (isRef && p == null)
342 {
343return getParentEntry().getParameter(name);
344 }
345return p;
346 }
347348publicCachedParameter getCachedParameter( String name )
349 {
350Parameter p = getParameter(name);
351return (CachedParameter)p;
352 }
353354/*** Returns a map of parameter values keyed on the parameter names355 * @return the parameter values map356 */357public Map getParameterMap()
358 {
359 Hashtable params = (Hashtable)super.getParameterMap();
360361if (isRef)
362 {
363 Map map = getParentEntry().getParameterMap();
364 map.putAll(params);
365return map;
366 }
367368return params;
369 }
370371/***372 * Returns a list of the supported media type names373 *374 * @return an iterator on the supported media type names375 */376public Iterator listMediaTypes()
377 {
378if (isRef)
379 {
380 Map types = new HashMap();
381382 Iterator i = super.listMediaTypes();
383while(i.hasNext())
384 {
385 types.put(i.next(),"1");
386 }
387388 i = getParentEntry().listMediaTypes();
389while(i.hasNext())
390 {
391 types.put(i.next(),"1");
392 }
393394return types.keySet().iterator();
395 }
396397returnsuper.listMediaTypes();
398 }
399400/***401 * Test if a given media type is supported by this entry.402 * The test is done by a case sensitive name comparison403 *404 * @param name the media type name to test for.405 * @return true is the media type is supported false otherwise406 */407publicboolean hasMediaType(String name)
408 {
409if (isRef)
410 {
411returnsuper.hasMediaType(name) || getParentEntry().hasMediaType(name);
412 }
413414returnsuper.hasMediaType(name);
415 }
416417/*** @return the URL associated with this portlet or null */418publicBaseContentURL getContentURL()
419 {
420return (BaseContentURL)this.url;
421 }
422423/***424 * Sets the URL for this PortletEntry425 * @param url the new PortletEntry URL426 */427publicvoid setContentURL( BaseContentURL url )
428 {
429this.url = url;
430 }
431432/*433 * Categories434 */435public Vector getCategories()
436 {
437returnthis.categories;
438 }
439440publicvoid setCategories(Vector v)
441 {
442this.categories = v;
443 }
444445/***446 * Returns a list of the supported media type names447 *448 * @return an iterator on the supported media type names449 */450public Iterator listCategories()
451 {
452returnnewPortletIterator(this, "getCategories");
453 }
454455/***456 * Test if a given category exists for this entry457 *458 * @param name the category name459 * @return true is the category exists in the default group460 */461publicboolean hasCategory(String name)
462 {
463return hasCategory(name, PortletEntry.DEFAULT_GROUP);
464 }
465466/***467 * Test if a given category exists for this entry, in the specified group of categories.468 *469 * @param name the category name470 * @param group the category group471 * @return true is the category exists in the specified group472 */473publicboolean hasCategory(String name, String group)
474 {
475 Iterator it = listCategories();
476while (it.hasNext())
477 {
478Category cat = (Category)it.next();
479if (cat.getName().equals(name) && cat.getGroup().equals(group))
480returntrue;
481 }
482return false;
483 }
484485486/***487 * Add a new category to this portlet entry in the default group.488 *489 * @param name the category name490 */491publicvoid addCategory(String name)
492 {
493 addCategory(name, PortletEntry.DEFAULT_GROUP);
494 }
495496/***497 * Add a new category to this portlet entry.498 *499 * @param name the category name500 * @param group the category group name501 */502publicvoid addCategory(String name, String group)
503 {
504if (!hasCategory(name, group))
505 {
506Category cat = newBaseCategory();
507 cat.setName(name);
508 cat.setGroup(group);
509 categories.add(cat);
510 }
511 }
512513/***514 * Remove a category from this portlet entry in the default group.515 *516 * @param name the category name517 */518publicvoid removeCategory(String name)
519 {
520 removeCategory(name, PortletEntry.DEFAULT_GROUP);
521 }
522523/***524 * Remove a category from this portlet entry in the specified group.525 *526 * @param name the media type name to remove.527 * @param group the category group name528 */529publicvoid removeCategory(String name, String group)
530 {
531for (int ix = 0; ix < categories.size(); ix++)
532 {
533Category cat = (Category)categories.elementAt(ix);
534if (cat.getName().equals(name) && cat.getGroup().equals(group))
535 {
536 categories.remove(ix);
537return;
538 }
539 }
540 }
541 }
542543