KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > console > ca > SetupCAHandler


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

18 package org.apache.geronimo.console.ca;
19
20 import java.io.IOException JavaDoc;
21 import java.math.BigInteger JavaDoc;
22 import java.text.DateFormat JavaDoc;
23 import java.text.SimpleDateFormat JavaDoc;
24 import java.util.Calendar JavaDoc;
25 import java.util.Date JavaDoc;
26 import java.util.GregorianCalendar JavaDoc;
27
28 import javax.portlet.ActionRequest;
29 import javax.portlet.ActionResponse;
30 import javax.portlet.PortletException;
31 import javax.portlet.RenderRequest;
32 import javax.portlet.RenderResponse;
33
34 import org.apache.commons.logging.Log;
35 import org.apache.commons.logging.LogFactory;
36 import org.apache.geronimo.console.MultiPageModel;
37
38 /**
39  * Handler for Setup CA screen to get CA details from user.
40  *
41  * @version $Rev: 476291 $ $Date: 2006-11-17 15:05:24 -0500 (Fri, 17 Nov 2006) $
42  */

43 public class SetupCAHandler extends BaseCAHandler {
44     private final static Log log = LogFactory.getLog(SetupCAHandler.class);
45     public SetupCAHandler() {
46         super(SETUPCA_MODE, "/WEB-INF/view/ca/setupCA.jsp");
47     }
48
49     public String JavaDoc actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
50         String JavaDoc[] params = {ERROR_MSG, INFO_MSG, "caCN", "caOU", "caO", "caL", "caST", "caC", "alias", "keyAlgorithm", "keySize", "algorithm", "validFrom", "validTo", "sNo", "password"};
51         for(int i = 0; i < params.length; ++i) {
52             String JavaDoc value = request.getParameter(params[i]);
53             if(value != null) response.setRenderParameter(params[i], value);
54         }
55         return getMode();
56     }
57
58     public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
59         String JavaDoc[] params = {ERROR_MSG, INFO_MSG, "caCN", "caOU", "caO", "caL", "caST", "caC", "alias", "keyAlgorithm", "keySize", "algorithm", "validFrom", "validTo", "sNo", "password"};
60         for(int i = 0; i < params.length; ++i) {
61             Object JavaDoc value = request.getParameter(params[i]);
62             if(value != null) request.setAttribute(params[i], value);
63         }
64     }
65
66     public String JavaDoc actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
67         String JavaDoc errorMsg = null;
68         try {
69             // Validate the Serial Number
70
String JavaDoc sNo = request.getParameter("sNo");
71             new BigInteger JavaDoc(sNo.trim());
72             
73             // Validate the from and to dates
74
String JavaDoc validFrom = request.getParameter("validFrom");
75             String JavaDoc validTo = request.getParameter("validTo");
76             // Check if the from date format is MM/DD/YYYY
77
DateFormat JavaDoc df = new SimpleDateFormat JavaDoc("MM/dd/yyyy");
78             Date JavaDoc validFromDate = df.parse(validFrom);
79             Calendar JavaDoc calendar = new GregorianCalendar JavaDoc();
80             calendar.setTime(validFromDate);
81             String JavaDoc mmddyyyy = (calendar.get(Calendar.MONTH) < 9 ? "0":"") + (calendar.get(Calendar.MONTH)+1);
82             mmddyyyy += "/"+(calendar.get(Calendar.DAY_OF_MONTH) < 10 ? "0":"") + (calendar.get(Calendar.DAY_OF_MONTH));
83             mmddyyyy += "/"+calendar.get(Calendar.YEAR);
84             if(!mmddyyyy.equals(validFrom)) {
85                 throw new Exception JavaDoc("validFrom must be a date in MM/DD/YYYY format.");
86             }
87             // Check if the to date format is MM/DD/YYYY
88
Date JavaDoc validToDate = df.parse(validTo);
89             calendar.setTime(validToDate);
90             mmddyyyy = (calendar.get(Calendar.MONTH) < 9 ? "0":"") + (calendar.get(Calendar.MONTH)+1);
91             mmddyyyy += "/"+(calendar.get(Calendar.DAY_OF_MONTH) < 10 ? "0":"") + (calendar.get(Calendar.DAY_OF_MONTH));
92             mmddyyyy += "/"+calendar.get(Calendar.YEAR);
93              if(!mmddyyyy.equals(validTo)) {
94                 throw new Exception JavaDoc("validTo must be a date in MM/DD/YYYY format.");
95             }
96             // Check if the from date is before the to date
97
if(validFromDate.after(validToDate)) {
98                 throw new Exception JavaDoc("Validity: From date '"+validFrom+"' is before the To date '"+validTo+"'.");
99             }
100
101             // Load page to confirm CA details
102
return CONFIRM_CA_MODE+BEFORE_ACTION;
103         } catch(Exception JavaDoc e) {
104             errorMsg = e.toString();
105             log.error("Error in user input during CA Setup.", e);
106         }
107         if(errorMsg != null) response.setRenderParameter(ERROR_MSG, errorMsg);
108         return getMode()+BEFORE_ACTION;
109     }
110
111 }
112
Popular Tags