KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > console > keystores > UploadCertificateHandler


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.console.keystores;
18
19 import org.apache.commons.fileupload.FileItem;
20 import org.apache.geronimo.console.MultiPageModel;
21
22 import javax.portlet.ActionRequest;
23 import javax.portlet.ActionResponse;
24 import javax.portlet.PortletException;
25 import javax.portlet.RenderRequest;
26 import javax.portlet.RenderResponse;
27 import java.io.File JavaDoc;
28 import java.io.IOException JavaDoc;
29
30 /**
31  * Handler for entering a password to unlock a keystore
32  *
33  * @version $Rev: 476061 $ $Date: 2006-11-17 01:36:50 -0500 (Fri, 17 Nov 2006) $
34  */

35 public class UploadCertificateHandler extends BaseKeystoreHandler {
36     public UploadCertificateHandler() {
37         super(UPLOAD_CERTIFICATE, "/WEB-INF/view/keystore/uploadCertificate.jsp");
38     }
39
40     public String JavaDoc actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
41         String JavaDoc id = request.getParameter("id");
42         if(id != null) {
43             response.setRenderParameter("id", id);
44         } // else we hope this is after a failure and the actionAfterView took care of it below!
45
return getMode();
46     }
47
48     public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
49         request.setAttribute("id", request.getParameter("id"));
50     }
51
52     public String JavaDoc actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
53         String JavaDoc id = getUploadFields().getProperty("id");
54         if(id == null) {
55             return LIST_MODE+BEFORE_ACTION;
56         }
57         String JavaDoc alias = getUploadFields().getProperty("alias");
58         if(alias == null) {
59             return getMode()+BEFORE_ACTION; //todo: some kind of error message
60
}
61         /* // Uploading certificate using a disk file fails on Windows. Certificate text is used instead.
62         File certFile;
63         FileItem item = (FileItem) getUploadFiles().get("certificate");
64         if(item != null) {
65             certFile = File.createTempFile("geronimo", ".cert");
66             certFile.deleteOnExit();
67             try {
68                 item.write(certFile);
69             } catch (Exception e) {
70                 throw new PortletException("Unable to save uploaded file", e);
71             }
72         } else {
73             response.setRenderParameter("id", id);
74             return getMode()+BEFORE_ACTION;
75         }
76         */

77         response.setRenderParameter("id", id); // the Keystore
78
// Uploading certificate using a disk file fails on Windows. Certificate text is used instead.
79
//response.setRenderParameter("certificate", certFile.getAbsolutePath());
80
response.setRenderParameter("certificate", getUploadFields().getProperty("certificate"));
81         response.setRenderParameter("alias", alias);
82
83         return CONFIRM_CERTIFICATE+BEFORE_ACTION;
84     }
85 }
86
Popular Tags