001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    package org.apache.geronimo.console.car;
018    
019    import java.io.IOException;
020    import java.net.URL;
021    import javax.portlet.ActionRequest;
022    import javax.portlet.ActionResponse;
023    import javax.portlet.PortletException;
024    import javax.portlet.RenderRequest;
025    import javax.portlet.RenderResponse;
026    import javax.security.auth.login.FailedLoginException;
027    import org.apache.commons.logging.Log;
028    import org.apache.commons.logging.LogFactory;
029    import org.apache.geronimo.console.MultiPageModel;
030    import org.apache.geronimo.console.util.PortletManager;
031    import org.apache.geronimo.system.plugin.PluginMetadata;
032    import org.apache.geronimo.system.plugin.PluginList;
033    
034    /**
035     * Handler for the screen that shows you plugin details before you go on and
036     * install it.
037     *
038     * @version $Rev: 549707 $ $Date: 2007-06-22 00:54:05 -0400 (Fri, 22 Jun 2007) $
039     */
040    public class ViewPluginDownloadHandler  extends BaseImportExportHandler {
041        private final static Log log = LogFactory.getLog(ViewPluginDownloadHandler.class);
042    
043        public ViewPluginDownloadHandler() {
044            super(VIEW_FOR_DOWNLOAD_MODE, "/WEB-INF/view/car/viewForDownload.jsp");
045        }
046    
047        public String actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException {
048            String configId = request.getParameter("configId");
049            String repo = request.getParameter("repository");
050            String user = request.getParameter("repo-user");
051            String pass = request.getParameter("repo-pass");
052            response.setRenderParameter("configId", configId);
053            response.setRenderParameter("repository", repo);
054            if(!isEmpty(user)) response.setRenderParameter("repo-user", user);
055            if(!isEmpty(pass)) response.setRenderParameter("repo-pass", pass);
056    
057            return getMode();
058        }
059    
060        public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException {
061            String configId = request.getParameter("configId");
062            String repo = request.getParameter("repository");
063            String user = request.getParameter("repo-user");
064            String pass = request.getParameter("repo-pass");
065            PluginMetadata config = null;
066            try {
067                PluginList list = (PluginList) request.getPortletSession(true).getAttribute(CONFIG_LIST_SESSION_KEY);
068                if(list == null) {
069                    list = PortletManager.getCurrentServer(request).getPluginInstaller().listPlugins(new URL(repo), user, pass);
070                    request.getPortletSession(true).setAttribute(CONFIG_LIST_SESSION_KEY, list);
071                }
072                for (int i = 0; i < list.getPlugins().length; i++) {
073                    PluginMetadata metadata = list.getPlugins()[i];
074                    if(metadata.getModuleId().toString().equals(configId)) {
075                        config = metadata;
076                        break;
077                    }
078                }
079            } catch (FailedLoginException e) {
080                throw new PortletException("Invalid login for Maven repository '"+repo+"'", e);
081            }
082            if(config == null) {
083                throw new PortletException("No configuration found for '"+configId+"'");
084            }
085            request.setAttribute("configId", configId);
086            request.setAttribute("plugin", config);
087            request.setAttribute("gerVersions",config.getGeronimoVersions());
088            request.setAttribute("repository", repo);
089            request.setAttribute("repouser", user);
090            request.setAttribute("repopass", pass);
091        }
092    
093        public String actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException {
094            return DOWNLOAD_MODE+BEFORE_ACTION;
095        }
096    }