KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.Serializable JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import javax.portlet.ActionRequest;
24 import javax.portlet.ActionResponse;
25 import javax.portlet.PortletException;
26 import javax.portlet.RenderRequest;
27 import javax.portlet.RenderResponse;
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.apache.geronimo.console.MultiPageModel;
31 import org.apache.geronimo.kernel.repository.Artifact;
32 import org.apache.geronimo.system.plugin.DownloadResults;
33
34 /**
35  * Handler for the initial download screen.
36  *
37  * @version $Rev: 476061 $ $Date: 2006-11-17 01:36:50 -0500 (Fri, 17 Nov 2006) $
38  */

39 public class DownloadStatusHandler extends BaseImportExportHandler {
40     private final static Log log = LogFactory.getLog(DownloadStatusHandler.class);
41
42     public DownloadStatusHandler() {
43         super(DOWNLOAD_STATUS_MODE, "/WEB-INF/view/car/downloadStatus.jsp");
44     }
45
46     public String JavaDoc actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
47         return getMode();
48     }
49
50     public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
51         String JavaDoc configId = request.getParameter("configId");
52         String JavaDoc repo = request.getParameter("repository");
53         String JavaDoc user = request.getParameter("repo-user");
54         String JavaDoc pass = request.getParameter("repo-pass");
55         request.setAttribute("configId", configId);
56         request.setAttribute("repository", repo);
57         request.setAttribute("repouser", user);
58         request.setAttribute("repopass", pass);
59     }
60
61     public String JavaDoc actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
62         String JavaDoc repo = request.getParameter("repository");
63         String JavaDoc user = request.getParameter("repo-user");
64         String JavaDoc pass = request.getParameter("repo-pass");
65         String JavaDoc configId = request.getParameter("configId");
66
67         DownloadResults results = (DownloadResults) request.getPortletSession(true).getAttribute(DOWNLOAD_RESULTS_SESSION_KEY);
68         if(results.isFailed()) {
69             throw new PortletException("Unable to install configuration", results.getFailure());
70         }
71         List JavaDoc dependencies = new ArrayList JavaDoc();
72         for (int i = 0; i < results.getDependenciesInstalled().length; i++) {
73             Artifact uri = results.getDependenciesInstalled()[i];
74             dependencies.add(new InstallResults(uri.toString(), "installed"));
75         }
76         for (int i = 0; i < results.getDependenciesPresent().length; i++) {
77             Artifact uri = results.getDependenciesPresent()[i];
78             dependencies.add(new InstallResults(uri.toString(), "already present"));
79         }
80         request.getPortletSession(true).setAttribute("car.install.results", dependencies);
81
82         response.setRenderParameter("configId", configId);
83         response.setRenderParameter("repository", repo);
84         if(!isEmpty(user)) response.setRenderParameter("repo-user", user);
85         if(!isEmpty(pass)) response.setRenderParameter("repo-pass", pass);
86         return RESULTS_MODE+BEFORE_ACTION;
87     }
88
89     public static class InstallResults implements Serializable JavaDoc {
90         private String JavaDoc name;
91         private String JavaDoc action;
92
93         public InstallResults(String JavaDoc name, String JavaDoc action) {
94             this.name = name;
95             this.action = action;
96         }
97
98         public String JavaDoc getName() {
99             return name;
100         }
101
102         public String JavaDoc getAction() {
103             return action;
104         }
105     }
106 }
107
Popular Tags