KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > keystore > wizards > AbstractKeyStoreImportType


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.keystore.wizards;
21
22 import java.io.File JavaDoc;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25
26 import org.apache.struts.action.ActionMessage;
27 import org.apache.struts.action.ActionMessages;
28
29 import com.sslexplorer.security.SessionInfo;
30 import com.sslexplorer.wizard.AbstractWizardSequence;
31
32 /**
33  * Plugins may register implementations of this class with the
34  * {@link com.sslexplorer.boot.KeyStoreType} to add new types to the key store
35  * import wizard.
36  * <p>
37  * A number of message resources must be provided. For example, for a type that
38  * has a name <i>caRoot</i> must provide :-
39  * <ul>
40  * <li>keyStoreImportType.caRoot.title</li>,
41  * <li>keyStoreImportType.caRoot.description</li>
42  * <li>keyStoreImportType.caRoot.summaryTitle</li>,
43  * <li>keyStoreImportType.caRoot.installed</li>
44  * <li>keyStoreImportType.caRoot.installFailed</li>
45  * </ul>
46  *
47  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
48  * @see com.sslexplorer.keystore.wizards.KeyStoreImportTypeManager
49  */

50 public abstract class AbstractKeyStoreImportType implements Comparable JavaDoc {
51
52     // Private instance variables
53
private String JavaDoc name;
54     private String JavaDoc bundle;
55     private boolean requiresPassphrase;
56     private boolean requiresAlias;
57     private int weight;
58
59     /**
60      * Constructor.
61      *
62      * @param name name
63      * @param bundle bunlde that contains resources
64      * @param requiresPassphrase requires a passphrase
65      * @param requiresAlias requires an alias
66      * @param weight weight
67      */

68     public AbstractKeyStoreImportType(String JavaDoc name, String JavaDoc bundle, boolean requiresPassphrase, boolean requiresAlias, int weight) {
69         this.name = name;
70         this.bundle = bundle;
71         this.requiresPassphrase = requiresPassphrase;
72         this.requiresAlias = requiresAlias;
73         this.weight = weight;
74     }
75     
76     /**
77      * Install the certificiate
78      *
79      * @param file uploaded ifle
80      * @param alias alias or <code>null</code> if not required
81      * @param passphrase passphrase or <code>null</code> if not required
82      * @param seq wizard sequence
83      * @param sessionInfo TODO
84      * @throws Exception on any error
85      */

86     public abstract void doInstall(File JavaDoc file, String JavaDoc alias, String JavaDoc passphrase, AbstractWizardSequence seq, SessionInfo sessionInfo) throws Exception JavaDoc;
87
88     
89     /**
90      * Validate the input. Default implementation does nothing.
91      *
92      * @param errs errors ojbect to add to
93      * @param alias alias
94      * @param passphrase passphrase
95      * @param seq wizard sequence
96      * @param sessionInfo sessionInfo
97      */

98     public void validate(ActionMessages errs, String JavaDoc alias, String JavaDoc passphrase, AbstractWizardSequence seq, SessionInfo sessionInfo) {
99         if(requiresAlias && (alias==null || alias.trim().equals(""))) {
100             errs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("keyStoreImportType.alias.required"));
101         }
102     }
103     
104     /**
105      * Invoked when the type is first selected.
106      *
107      * @param request request
108      */

109     public void init(HttpServletRequest JavaDoc request) {
110     }
111
112     /**
113      * Get the bundle id that contains the resources for this import type
114      *
115      * @return bundle that contains resources
116      */

117     public String JavaDoc getBundle() {
118         return bundle;
119     }
120
121     /**
122      * Set the bundle id that contains the resources for this import type
123      *
124      * @param bundle bundle that contains resources
125      */

126     public void setBundle(String JavaDoc bundle) {
127         this.bundle = bundle;
128     }
129
130     /**
131      * Get the internal name for this type. This will be determine the resources
132      * to use in the wizard.
133      *
134      * @return name
135      */

136     public String JavaDoc getName() {
137         return name;
138     }
139
140     /**
141      * Set the internal name for this type. This will be determine the resources
142      * to use in the wizard.
143      *
144      * @param name name
145      */

146     public void setName(String JavaDoc name) {
147         this.name = name;
148     }
149
150     /**
151      * Get if this import type requires an alias to be specified by the user
152      *
153      * @return requires alias
154      */

155     public boolean isRequiresAlias() {
156         return requiresAlias;
157     }
158
159     /**
160      * Set if this import type requires an alias to be specified by the user
161      *
162      * @param requiresAlias requires alias
163      */

164     public void setRequiresAlias(boolean requiresAlias) {
165         this.requiresAlias = requiresAlias;
166     }
167
168     /**
169      * Get if this import type requires a passphrase to be specified by the user
170      *
171      * @return requires passphrase
172      */

173     public boolean isRequiresPassphrase() {
174         return requiresPassphrase;
175     }
176
177     /**
178      * Set if this import type requires a passphrase to be specified by the user
179      *
180      * @param requiresPassphrase requires passphrase
181      */

182     public void setRequiresPassphrase(boolean requiresPassphrase) {
183         this.requiresPassphrase = requiresPassphrase;
184     }
185
186     /**
187      * Get the weight used to determine this import types order in the list
188      * in the wizard. The lower the number the higher in the list
189      *
190      * @return weight
191      */

192     public int getWeight() {
193         return weight;
194     }
195     
196     /**
197      * Set the weight used to determine this import types order in the list
198      * in the wizard. The lower the number the higher in the list
199      *
200      * @param weight weight
201      */

202     public void setWeight(int weight) {
203         this.weight = weight;
204     }
205
206     /**
207      * Compare this type with another based on the weight. If the weight
208      * is equal then compare by nam,e
209      *
210      * @param arg0
211      * @return comparison
212      */

213     public int compareTo(Object JavaDoc arg0) {
214         int i = new Integer JavaDoc(getWeight()).compareTo(new Integer JavaDoc(((AbstractKeyStoreImportType)arg0).getWeight()));
215         return i == 0 ? getName().compareTo(((AbstractKeyStoreImportType)arg0).getName()) : i;
216     }
217
218 }
219
Popular Tags