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 022 import javax.portlet.ActionRequest; 023 import javax.portlet.ActionResponse; 024 import javax.portlet.PortletException; 025 import javax.portlet.RenderRequest; 026 import javax.portlet.RenderResponse; 027 import javax.portlet.WindowState; 028 import javax.security.auth.login.FailedLoginException; 029 030 import org.apache.geronimo.console.MultiPageModel; 031 import org.apache.geronimo.system.plugin.PluginInstaller; 032 import org.apache.geronimo.system.plugin.model.PluginListType; 033 034 /** 035 * Handler for the import export list screen. 036 * 037 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $ 038 */ 039 public class ListHandler extends AbstractListHandler { 040 041 public ListHandler() { 042 super(LIST_MODE, "/WEB-INF/view/car/list.jsp"); 043 } 044 045 public String actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException { 046 String repository = (String) request.getAttribute("repository"); 047 if(repository == null || repository.equals("")) { 048 return INDEX_MODE+BEFORE_ACTION; 049 } 050 response.setRenderParameter("repository", repository); 051 String user = (String) request.getAttribute("repo-user"); 052 String pass = (String) request.getAttribute("repo-pass"); 053 String column = (String) request.getAttribute("column"); 054 055 if(!isEmpty(user)) response.setRenderParameter("repo-user", user); 056 if(!isEmpty(pass)) response.setRenderParameter("repo-pass", pass); 057 if(!isEmpty(column)) response.setRenderParameter("column", column); 058 059 response.setWindowState(WindowState.MAXIMIZED); 060 061 return getMode(); 062 } 063 064 public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException { 065 String repository = request.getParameter("repository"); 066 String user = request.getParameter("repo-user"); 067 String pass = request.getParameter("repo-pass"); 068 String column = request.getParameter("column"); 069 if(!loadFromRepository(request, repository, user, pass)) { 070 //todo: loading failed -- do something! 071 } 072 request.setAttribute("repository", repository); 073 request.setAttribute("repouser", user); 074 request.setAttribute("repopass", pass); 075 request.setAttribute("column", column); 076 } 077 078 public String actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException { 079 return getMode()+BEFORE_ACTION; 080 } 081 082 private boolean loadFromRepository(RenderRequest request, String repository, String username, String password) throws IOException, PortletException { 083 084 PluginInstaller pluginInstaller = ManagementHelper.getManagementHelper(request).getPluginInstaller(); 085 086 // try to reuse the catalog data if it was already downloaded 087 PluginListType data = getRepoPluginList(request, pluginInstaller, repository, username, password); 088 089 if(data == null || data.getPlugin() == null) { 090 return false; 091 } 092 093 listPlugins(request, pluginInstaller, data, true); 094 request.getPortletSession(true).setAttribute(CONFIG_LIST_SESSION_KEY, data); 095 return true; 096 } 097 098 }