KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.IOException JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
22 import javax.portlet.ActionRequest;
23 import javax.portlet.ActionResponse;
24 import javax.portlet.PortletException;
25 import javax.portlet.PortletSession;
26 import javax.portlet.RenderRequest;
27 import javax.portlet.RenderResponse;
28 import org.apache.geronimo.console.MultiPageModel;
29 import org.apache.geronimo.console.util.PortletManager;
30 import org.apache.geronimo.gbean.AbstractName;
31 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
32 import org.apache.geronimo.management.geronimo.KeystoreException;
33 import org.apache.geronimo.management.geronimo.KeystoreInstance;
34 import org.apache.geronimo.management.geronimo.KeystoreIsLocked;
35 import org.apache.geronimo.management.geronimo.KeystoreManager;
36
37 /**
38  * Handler for the keystore list screen.
39  *
40  * @version $Rev: 477134 $ $Date: 2006-11-20 05:19:42 -0500 (Mon, 20 Nov 2006) $
41  */

42 public class ListHandler extends BaseKeystoreHandler {
43     public ListHandler() {
44         super(LIST_MODE, "/WEB-INF/view/keystore/index.jsp");
45     }
46
47     public String JavaDoc actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
48         return getMode();
49     }
50
51     public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
52         String JavaDoc[] params = {ERROR_MSG, INFO_MSG};
53         for(int i = 0; i < params.length; ++i) {
54             String JavaDoc value = request.getParameter(params[i]);
55             if(value != null) request.setAttribute(params[i], value);
56         }
57         KeystoreManager manager = PortletManager.getCurrentServer(request).getKeystoreManager();
58         KeystoreInstance[] keystores = manager.getKeystores();
59         PortletSession session = request.getPortletSession(true);
60         KeystoreData[] datas = new KeystoreData[keystores.length];
61         Map JavaDoc keys = new HashMap JavaDoc();
62         for (int i = 0; i < datas.length; i++) {
63             AbstractName aName = PortletManager.getNameFor(request, keystores[i]);
64             String JavaDoc name = (String JavaDoc) aName.getName().get(NameFactory.J2EE_NAME);
65             KeystoreData data = (KeystoreData) session.getAttribute(KEYSTORE_DATA_PREFIX+name);
66             if(data == null) {
67                 data = new KeystoreData();
68                 data.setInstance(keystores[i]);
69                 session.setAttribute(KEYSTORE_DATA_PREFIX+name, data);
70             }
71             datas[i] = data;
72             if(!data.getInstance().isKeystoreLocked()) {
73                 try {
74                     String JavaDoc[] all = data.getInstance().getUnlockedKeys(null);
75                     if(all.length > 0) {
76                         keys.put(data.getInstance().getKeystoreName(), all.length+" key"+(all.length > 1 ? "s" : "")+" ready");
77                     } else {
78                         keys.put(data.getInstance().getKeystoreName(), "trust store only");
79                     }
80                 } catch (KeystoreException locked) {}
81             }
82         }
83         request.setAttribute("keystores", datas);
84         request.setAttribute("keys", keys);
85     }
86
87     public String JavaDoc actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
88         return getMode()+BEFORE_ACTION;
89     }
90
91 }
92
Popular Tags