KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > navigation > WrappedFavoriteItem


1 package com.sslexplorer.navigation;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4 import javax.servlet.jsp.PageContext JavaDoc;
5
6 import org.apache.struts.taglib.TagUtils;
7 import org.apache.struts.util.MessageResources;
8
9 import com.sslexplorer.policyframework.ResourceType;
10 import com.sslexplorer.table.TableItem;
11
12 /**
13  * Implementation of a {@link com.sslexplorer.table.TableItem} that wraps an
14  * {@link AbstractFavoriteItem}. This is used for the <i>Favorites</i> page
15  * that lists the favorites of all resource types.
16  *
17  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
18  */

19 public class WrappedFavoriteItem implements TableItem {
20
21     // Private instance variables
22
private AbstractFavoriteItem favoriteItem;
23     private String JavaDoc type;
24
25     /**
26      * Constructor.
27      *
28      * @param favoriteItem item
29      * @param type will be one of {@link AbstractFavoriteItem#GLOBAL_FAVORITE} or
30      * {@link AbstractFavoriteItem#USER_FAVORITE}.
31      */

32     public WrappedFavoriteItem(AbstractFavoriteItem favoriteItem, String JavaDoc type) {
33         this.favoriteItem = favoriteItem;
34         this.type = type;
35     }
36
37     /**
38      * Get the favorite type. Will be one of {@link AbstractFavoriteItem#GLOBAL_FAVORITE} or
39      * {@link AbstractFavoriteItem#USER_FAVORITE}.
40      *
41      * @return favorite type
42      */

43     public String JavaDoc getFavoriteType() {
44         return type;
45     }
46
47     /**
48      * Get the favorite item this table item is wrapping
49      *
50      * @return favorite item
51      */

52     public AbstractFavoriteItem getFavoriteItem() {
53         return favoriteItem;
54     }
55
56     /**
57      * Get the resource type as a string
58      *
59      * @param pageContext page context from which to get the message resources
60      * @return resource type string
61      * @throws JspException on error retrieving message resources
62      */

63     public String JavaDoc getResourceTypeName(PageContext JavaDoc pageContext) throws JspException JavaDoc {
64         ResourceType rt = getFavoriteItem().getResource() == null ? null : getFavoriteItem().getResource().getResourceType();
65         if (rt == null) {
66             return "?";
67         } else {
68             MessageResources mr = TagUtils.getInstance().retrieveMessageResources(pageContext, rt.getBundle(), false);
69             rt.getBundle();
70             if (mr == null) {
71                 return "!Invalid bundle!";
72             } else {
73                 String JavaDoc msg = mr.getMessage("resourceType." + rt.getResourceTypeId() + ".title");
74                 return msg == null || msg.equals("") ? "!No message!" : msg;
75             }
76         }
77
78     }
79
80     /*
81      * (non-Javadoc)
82      *
83      * @see com.sslexplorer.table.TableItem#getColumnValue(int)
84      */

85     public Object JavaDoc getColumnValue(int col) {
86         return favoriteItem.getResource().getResourceName();
87     }
88
89     /* (non-Javadoc)
90      * @see java.lang.Object#equals(java.lang.Object)
91      */

92     public boolean equals(Object JavaDoc obj) {
93         try {
94             return getFavoriteItem().getResource().getResourceId() == ((WrappedFavoriteItem) obj).getFavoriteItem().getResource()
95                 .getResourceId()
96                             && getFavoriteItem().getResource().getResourceType() == ((WrappedFavoriteItem) obj).getFavoriteItem()
97                                 .getResource().getResourceType();
98         } catch (ClassCastException JavaDoc cse) {
99             return false;
100         }
101     }
102
103 }
Popular Tags