KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.navigation;
21
22 import java.util.List JavaDoc;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25
26 import com.sslexplorer.policyframework.Resource;
27 import com.sslexplorer.policyframework.ResourceItem;
28
29 /**
30  * Abstract class to be implemented by resource items that may be added as a
31  * <i>Favorite</i>.
32  *
33  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
34  * @author James D Robinson <a HREF="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
35  * @see com.sslexplorer.navigation.Favorite
36  */

37 public abstract class AbstractFavoriteItem extends ResourceItem implements Comparable JavaDoc {
38
39     /**
40      * Constant for {@link #getFavoriteType()} and {@link #setFavoriteType(String)}
41      * that indiciates the item does not have any type of favorite.
42      */

43     public final static String JavaDoc NO_FAVORITE = "none";
44
45     /**
46      * Constant for {@link #getFavoriteType()} and {@link #setFavoriteType(String)}
47      * that indiciates the item has a <i>User Favorite</i>
48      */

49     public final static String JavaDoc USER_FAVORITE = "user";
50
51     /**
52      * Constant for {@link #getFavoriteType()} and {@link #setFavoriteType(String)}
53      * that indiciates the item has a <i>Policy Favorite</i>
54      */

55     public final static String JavaDoc GLOBAL_FAVORITE = "policy";
56
57     // Private instance variables
58

59     private String JavaDoc favoriteType;
60
61     /**
62      * Compare this favorite item with another using a resource type / resource
63      * ID comparison.
64      *
65      * @param o other resource item
66      * @return comparison
67      */

68     public int compareTo(Object JavaDoc o) {
69         int i = getResource().getResourceType().compareTo(((ResourceItem) o).getResource().getResourceType());
70         return i == 0 ? new Integer JavaDoc(getResource().getResourceId()).compareTo(new Integer JavaDoc(((ResourceItem) o).getResource()
71             .getResourceId())) : i;
72     }
73
74     /**
75      * Constructor.
76      *
77      * @param resource resource
78      * @param policies policies item is attached to
79      */

80     public AbstractFavoriteItem(Resource resource, List JavaDoc policies) {
81         super(resource, policies);
82     }
83
84     /**
85      * Return the link to launch this item using the show favorites page as the
86      * referer.
87      * @param policy TODO
88      * @param request equest
89      *
90      * @return link
91      */

92     public String JavaDoc getFavoriteLink(int policy, HttpServletRequest JavaDoc request) {
93         return getLink(-1, "/showFavorites.do?actionTarget=unspecified", request);
94     }
95
96     /**
97      * Get if this item has a favorite and if so what type it is.
98      * The value may be {@link #NO_FAVORITE}, {@link #USER_FAVORITE} or
99      * {@link #GLOBAL_FAVORITE}.
100      *
101      * @return favorite type
102      *
103      */

104     public String JavaDoc getFavoriteType() {
105         return favoriteType;
106     }
107
108     /**
109      * Set if this item has a favorite and if so what type it is.
110      * The value may be {@link #NO_FAVORITE}, {@link #USER_FAVORITE} or
111      * {@link #GLOBAL_FAVORITE}.
112      *
113      * @param favoriteType favorite type
114      *
115      */

116     public void setFavoriteType(String JavaDoc favoriteType) {
117         this.favoriteType = favoriteType;
118     }
119
120     /**
121      * Get the browsers frame target to use when launching this favorite.
122      *
123      * @return browser frame target
124      */

125     public abstract String JavaDoc getTarget();
126
127     /**
128      * Get a javascript fragment to use for the onClick event when launching
129      * this item.
130      *
131      * @return onclick javascript fragment
132      */

133     public abstract String JavaDoc getOnClick(int policy, HttpServletRequest JavaDoc request);
134
135     /**
136      * Get the link to launch this item using the specified referer as the page
137      * to return to.
138      * @param referer
139      *
140      * @return link
141      */

142     public abstract String JavaDoc getLink(int policy, String JavaDoc referer, HttpServletRequest JavaDoc request);
143
144     /**
145      * Get the name to display on the favorites list.
146      *
147      * @return favorite name
148      */

149     public abstract String JavaDoc getFavoriteName();
150
151     /**
152      * Get the sub-type to display on the favorites list
153      *
154      * @return favorite sub type
155      */

156     public abstract String JavaDoc getFavoriteSubType();
157
158     /**
159      * Get the path to the small icon to use for this resource for the given
160      * request
161      *
162      * @param request request
163      * @return path to small icon
164      */

165     public abstract String JavaDoc getSmallIconPath(HttpServletRequest JavaDoc request);
166
167     /**
168      * Get the path to the large icon to use for this resource for the given
169      * request
170      *
171      * @param request request
172      * @return path to large icon
173      */

174     public abstract String JavaDoc getLargeIconPath(HttpServletRequest JavaDoc request);
175
176 }
177
Popular Tags