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: */package org.apache.geronimo.console.car;
017:
018: import java.io.IOException;
019: import java.net.URL;
020:
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:
028: import org.apache.geronimo.console.MultiPageModel;
029: import org.apache.geronimo.system.plugin.PluginInstaller;
030: import org.apache.geronimo.system.plugin.model.PluginListType;
031:
032: /**
033: * Handler for the import export list screen.
034: *
035: * @version $Rev: 613462 $ $Date: 2008-01-19 13:46:39 -0800 (Sat, 19 Jan 2008) $
036: */
037: public class ListHandler extends AbstractListHandler {
038:
039: public ListHandler() {
040: super (LIST_MODE, "/WEB-INF/view/car/list.jsp");
041: }
042:
043: public String actionBeforeView(ActionRequest request,
044: ActionResponse response, MultiPageModel model)
045: 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))
056: response.setRenderParameter("repo-user", user);
057: if (!isEmpty(pass))
058: response.setRenderParameter("repo-pass", pass);
059: if (!isEmpty(column))
060: response.setRenderParameter("column", column);
061: return getMode();
062: }
063:
064: public void renderView(RenderRequest request,
065: RenderResponse response, MultiPageModel model)
066: throws PortletException, IOException {
067: String repository = request.getParameter("repository");
068: String user = request.getParameter("repo-user");
069: String pass = request.getParameter("repo-pass");
070: String column = request.getParameter("column");
071: if (!loadFromRepository(request, repository, user, pass)) {
072: //todo: loading failed -- do something!
073: }
074: request.setAttribute("repository", repository);
075: request.setAttribute("repouser", user);
076: request.setAttribute("repopass", pass);
077: request.setAttribute("column", column);
078: }
079:
080: public String actionAfterView(ActionRequest request,
081: ActionResponse response, MultiPageModel model)
082: throws PortletException, IOException {
083: return getMode() + BEFORE_ACTION;
084: }
085:
086: private boolean loadFromRepository(RenderRequest request,
087: String repository, String username, String password)
088: throws IOException, PortletException {
089:
090: PluginInstaller pluginInstaller = ManagementHelper
091: .getManagementHelper(request).getPluginInstaller();
092:
093: // try to reuse the catalog data if it was already downloaded
094: PluginListType data = getRepoPluginList(request,
095: pluginInstaller, repository, username, password);
096:
097: if (data == null || data.getPlugin() == null) {
098: return false;
099: }
100:
101: listPlugins(request, pluginInstaller, data, true);
102: request.getPortletSession(true).setAttribute(
103: CONFIG_LIST_SESSION_KEY, data);
104: return true;
105: }
106:
107: }
|