KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > applications > ApplicationShortcutItem


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.applications;
21
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27
28 import com.sslexplorer.boot.Util;
29 import com.sslexplorer.core.CoreUtil;
30 import com.sslexplorer.extensions.ExtensionDescriptor;
31 import com.sslexplorer.navigation.RequiresSessionPasswordAbstractFavoriteItem;
32
33 /**
34  * Wrapper for {@link com.sslexplorer.applications.ApplicationShortcut} instances.
35  *
36  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
37  */

38
39 public class ApplicationShortcutItem extends RequiresSessionPasswordAbstractFavoriteItem {
40
41     // Private instance variables
42
private ExtensionDescriptor application;
43     private int navigationContext;
44
45     /**
46      * Constructor
47      *
48      * @param application application extension descriptor
49      * @param resource application shortcut resource
50      * @param policies policies attached to resource
51      * @param navigationContext navigation context
52      * @param requiresSessionPassword requires session password
53      */

54     public ApplicationShortcutItem(ExtensionDescriptor application,ApplicationShortcut resource, List JavaDoc policies, int navigationContext, boolean requiresSessionPassword) {
55         super(resource, policies, requiresSessionPassword);
56         this.application = application;
57         this.navigationContext = navigationContext;
58     }
59
60     /**
61      * Get the extension descriptor of the application this shortcut requires
62      *
63      * @return extension description
64      */

65     public ExtensionDescriptor getExtensionDescriptor() {
66         return application;
67     }
68
69     /*
70      * (non-Javadoc)
71      *
72      * @see com.sslexplorer.navigation.FavoriteItem#getLink(java.lang.String)
73      */

74     public String JavaDoc getLink(int policy, String JavaDoc referer, HttpServletRequest JavaDoc request) {
75         return "/launchApplication.do?resourceId=" + getResource().getResourceId() + "&policy=" + policy +
76         "&returnTo=" + Util.urlEncode(Util.isNullOrTrimmedBlank(referer) ? CoreUtil.getRealRequestURI(request) : referer);
77     }
78
79     /*
80      * (non-Javadoc)
81      *
82      * @see com.sslexplorer.navigation.AbstractFavoriteItem#getSmallIconPath(javax.servlet.http.HttpServletRequest)
83      */

84     public String JavaDoc getSmallIconPath(HttpServletRequest JavaDoc request) {
85         if (application.getSmallIcon() == null) {
86             return CoreUtil.getThemePath(request.getSession()) + "/images/actions/runApplication.gif";
87         } else {
88             return "/fs/apps/" + application.getApplicationBundle().getId() + "/" + application.getSmallIcon();
89         }
90     }
91
92     /*
93      * (non-Javadoc)
94      *
95      * @see com.sslexplorer.navigation.AbstractFavoriteItem#getLargeIconPath(javax.servlet.http.HttpServletRequest)
96      */

97     public String JavaDoc getLargeIconPath(HttpServletRequest JavaDoc request) {
98         if (application.getSmallIcon() == null) {
99             return CoreUtil.getThemePath(request.getSession()) + "/images/actions/runApplicationLarge.gif";
100         } else {
101             return "/fs/apps/" + application.getApplicationBundle().getId() + "/" + application.getLargeIcon();
102         }
103     }
104
105     /**
106      * Get all of the parameters as encoded URL parameter string
107      *
108      * @return parameters as encoded URL parameter string
109      */

110     public String JavaDoc getParameterString() {
111         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
112         for (Iterator JavaDoc i = ((ApplicationShortcut) getResource()).getParameters().entrySet().iterator(); i.hasNext();) {
113             if (buf.length() > 0) {
114                 buf.append("&");
115             }
116             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) i.next();
117             buf.append(entry.getKey());
118             buf.append("=");
119             buf.append(Util.urlEncode(String.valueOf(entry.getValue())));
120         }
121         return buf.toString();
122     }
123
124     /*
125      * (non-Javadoc)
126      *
127      * @see com.sslexplorer.navigation.FavoriteItem#getName()
128      */

129     public String JavaDoc getFavoriteName() {
130         return getResource().getResourceName();
131     }
132
133     /*
134      * (non-Javadoc)
135      *
136      * @see com.sslexplorer.navigation.AbstractFavoriteItem#getFavoriteSubType()
137      */

138     public String JavaDoc getFavoriteSubType() {
139         return getExtensionDescriptor().getName();
140     }
141
142     /*
143      * (non-Javadoc)
144      *
145      * @see com.sslexplorer.navigation.FavoriteItem#getTarget()
146      */

147     public String JavaDoc getTarget() {
148         return "_self";
149     }
150     
151     /* (non-Javadoc)
152      * @see com.sslexplorer.navigation.AbstractFavoriteItem#getOnClick(int, javax.servlet.http.HttpServletRequest)
153      */

154     public String JavaDoc getOnClick(int policy, HttpServletRequest JavaDoc request) {
155         return "";
156     }
157 }
Popular Tags