KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > keystore > wizards > forms > KeyStoreImportFileForm


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.forms;
21
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23
24 import org.apache.struts.upload.FormFile;
25
26 import com.sslexplorer.keystore.wizards.AbstractKeyStoreImportType;
27 import com.sslexplorer.keystore.wizards.KeyStoreImportTypeManager;
28 import com.sslexplorer.keystore.wizards.types.ReplyFromCAImportType;
29 import com.sslexplorer.wizard.AbstractWizardSequence;
30 import com.sslexplorer.wizard.forms.DefaultWizardForm;
31
32 /**
33  * Extension of a {@link com.sslexplorer.wizard.forms.DefaultWizardForm} used
34  * for entering the file upload details for a key store import.
35  * <p>
36  * Note, due to the nature of the Java keystore the alias will be lower
37  * case regardless of the case the user gives it.
38  *
39  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
40  */

41
42 public class KeyStoreImportFileForm extends DefaultWizardForm {
43     // Statics for sequence attributes
44

45     /**
46      * Constant for passphrase wizard seqeunce attribute
47      */

48     public static final String JavaDoc ATTR_PASSPHRASE = "passphrase";
49     
50     /**
51      * Constant for uploaded file wizard sequence attribute (will be a File
52      * object)
53      */

54     public static final String JavaDoc ATTR_UPLOADED_FILE = "uploadedFile";
55     
56     /**
57      * Constant for filename wizard sequence attribute
58      */

59     public static final Object JavaDoc ATTR_FILENAME = "filename";
60     
61     /**
62      * Constant for alias wizard sequence attribute
63      */

64     public static final Object JavaDoc ATTR_ALIAS = "alias";
65
66     // Private instance variables
67
private String JavaDoc alias;
68     private String JavaDoc passphrase;
69     private FormFile uploadFile;
70     private AbstractKeyStoreImportType importType;
71
72     /**
73      * Constructor
74      */

75     public KeyStoreImportFileForm() {
76         super(true, true, "/WEB-INF/jsp/content/keystore/keyStoreImportWizard/file.jspf",
77             "passphrase", false, false, "keyStoreImportFile", "keystore", "keyStoreImportWizard.keyStoreImportFile", 2);
78     }
79
80     /* (non-Javadoc)
81      * @see com.sslexplorer.wizard.forms.AbstractWizardForm#getFormEncoding()
82      */

83     public String JavaDoc getFormEncoding() {
84         return "multipart/form-data";
85     }
86
87     /* (non-Javadoc)
88      * @see com.sslexplorer.wizard.forms.AbstractWizardForm#getNextOnClick()
89      */

90     public String JavaDoc getNextOnClick() {
91         return "upload();";
92     }
93
94     /* (non-Javadoc)
95      * @see com.sslexplorer.wizard.forms.AbstractWizardForm#init(com.sslexplorer.wizard.AbstractWizardSequence, javax.servlet.http.HttpServletRequest)
96      */

97     public void init(AbstractWizardSequence wizardSequence, HttpServletRequest JavaDoc request) throws Exception JavaDoc {
98         super.init(wizardSequence, request);
99         uploadFile = (FormFile)wizardSequence.getAttribute(ATTR_FILENAME, null);
100         passphrase = (String JavaDoc)wizardSequence.getAttribute(ATTR_PASSPHRASE, "");
101         alias = (String JavaDoc)wizardSequence.getAttribute(ATTR_ALIAS, "");
102         importType = KeyStoreImportTypeManager.getInstance().getType(
103                 (String JavaDoc)wizardSequence.getAttribute(KeyStoreImportTypeForm.ATTR_TYPE, ReplyFromCAImportType.REPLY_FROM_CA));
104     }
105
106     /* (non-Javadoc)
107      * @see com.sslexplorer.wizard.forms.AbstractWizardForm#apply(com.sslexplorer.wizard.AbstractWizardSequence)
108      */

109     public void apply(AbstractWizardSequence sequence) throws Exception JavaDoc {
110         super.apply(sequence);
111         sequence.putAttribute(ATTR_FILENAME, uploadFile);
112         sequence.putAttribute(ATTR_ALIAS, alias == null ? "" : alias.toLowerCase());
113         sequence.putAttribute(ATTR_PASSPHRASE, passphrase == null ? "" : passphrase);
114     }
115     
116     /**
117      * Read-only getter to determine if the <b>Name</b> field should be
118      * requested
119      *
120      * @return ask for name
121      */

122     public boolean getAskForName() {
123         return KeyStoreImportTypeManager.getInstance().getType((String JavaDoc)getWizardSequence().getAttribute(KeyStoreImportTypeForm.ATTR_TYPE,
124             ReplyFromCAImportType.REPLY_FROM_CA)).isRequiresAlias();
125     }
126     
127     /**
128      * Read-only getter to determine if the <b>Passphrase</b> field should be
129      * requested
130      *
131      * @return ask for passphrase
132      */

133     public boolean getAskForPassphrase() {
134         return KeyStoreImportTypeManager.getInstance().getType((String JavaDoc)getWizardSequence().getAttribute(KeyStoreImportTypeForm.ATTR_TYPE,
135             ReplyFromCAImportType.REPLY_FROM_CA)).isRequiresPassphrase();
136     }
137
138     /**
139      * Get the alias.
140      *
141      * @return alias
142      */

143     public String JavaDoc getAlias() {
144         return alias;
145     }
146
147     /**
148      * Set the alias.
149      *
150      * @param alias alias
151      */

152     public void setAlias(String JavaDoc alias) {
153         this.alias = alias;
154     }
155      
156     /**
157      * Get the passphrase
158      *
159      * @return passphrase
160      */

161     public String JavaDoc getPassphrase() {
162         return passphrase;
163     }
164
165     /**
166      * Set the passphrase
167      *
168      * @param passphrase passphrase
169      */

170     public void setPassphrase(String JavaDoc passphrase) {
171         this.passphrase = passphrase;
172     }
173
174     /**
175      * Get the file to upload
176      *
177      * @return upload file
178      */

179     public FormFile getUploadFile() {
180         return uploadFile;
181     }
182
183     /**
184      * Set the file to upload
185      *
186      * @param uploadFile upload file
187      */

188     public void setUploadFile(FormFile uploadFile) {
189         this.uploadFile = uploadFile;
190     }
191
192     /* (non-Javadoc)
193      * @see com.sslexplorer.wizard.forms.AbstractWizardForm#getFocussedField()
194      */

195     public String JavaDoc getFocussedField() {
196         return getAskForName() ? "name" : (getAskForPassphrase() ? "passphrase" : "uploadFile") ;
197     }
198     
199     /**
200      * Get the selected import type
201      *
202      * @return import type
203      */

204     public AbstractKeyStoreImportType getImportType() {
205         return importType;
206     }
207 }
208
Popular Tags