KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > console > car > ViewPluginDownloadHandler


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.car;
18
19 import java.io.IOException JavaDoc;
20 import java.net.URL JavaDoc;
21 import javax.portlet.ActionRequest;
22 import javax.portlet.ActionResponse;
23 import javax.portlet.PortletException;
24 import javax.portlet.RenderRequest;
25 import javax.portlet.RenderResponse;
26 import javax.security.auth.login.FailedLoginException JavaDoc;
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.apache.geronimo.console.MultiPageModel;
30 import org.apache.geronimo.console.util.PortletManager;
31 import org.apache.geronimo.system.plugin.PluginMetadata;
32 import org.apache.geronimo.system.plugin.PluginList;
33
34 /**
35  * Handler for the screen that shows you plugin details before you go on and
36  * install it.
37  *
38  * @version $Rev: 46019 $ $Date: 2004-09-14 05:56:06 -0400 (Tue, 14 Sep 2004) $
39  */

40 public class ViewPluginDownloadHandler extends BaseImportExportHandler {
41     private final static Log log = LogFactory.getLog(ViewPluginDownloadHandler.class);
42
43     public ViewPluginDownloadHandler() {
44         super(VIEW_FOR_DOWNLOAD_MODE, "/WEB-INF/view/car/viewForDownload.jsp");
45     }
46
47     public String JavaDoc actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
48         String JavaDoc configId = request.getParameter("configId");
49         String JavaDoc repo = request.getParameter("repository");
50         String JavaDoc user = request.getParameter("repo-user");
51         String JavaDoc pass = request.getParameter("repo-pass");
52         response.setRenderParameter("configId", configId);
53         response.setRenderParameter("repository", repo);
54         if(!isEmpty(user)) response.setRenderParameter("repo-user", user);
55         if(!isEmpty(pass)) response.setRenderParameter("repo-pass", pass);
56
57         return getMode();
58     }
59
60     public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
61         String JavaDoc configId = request.getParameter("configId");
62         String JavaDoc repo = request.getParameter("repository");
63         String JavaDoc user = request.getParameter("repo-user");
64         String JavaDoc pass = request.getParameter("repo-pass");
65         PluginMetadata config = null;
66         try {
67             PluginList list = (PluginList) request.getPortletSession(true).getAttribute(CONFIG_LIST_SESSION_KEY);
68             if(list == null) {
69                 list = PortletManager.getCurrentServer(request).getPluginInstaller().listPlugins(new URL JavaDoc(repo), user, pass);
70                 request.getPortletSession(true).setAttribute(CONFIG_LIST_SESSION_KEY, list);
71             }
72             for (int i = 0; i < list.getPlugins().length; i++) {
73                 PluginMetadata metadata = list.getPlugins()[i];
74                 if(metadata.getModuleId().toString().equals(configId)) {
75                     config = metadata;
76                     break;
77                 }
78             }
79         } catch (FailedLoginException JavaDoc e) {
80             throw new PortletException("Invalid login for Maven repository '"+repo+"'", e);
81         }
82         if(config == null) {
83             throw new PortletException("No configuration found for '"+configId+"'");
84         }
85         request.setAttribute("configId", configId);
86         request.setAttribute("plugin", config);
87         request.setAttribute("repository", repo);
88         request.setAttribute("repouser", user);
89         request.setAttribute("repopass", pass);
90     }
91
92     public String JavaDoc actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
93         return DOWNLOAD_MODE+BEFORE_ACTION;
94     }
95 }
96
Popular Tags