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.PortletRequest;
022: import javax.portlet.PortletException;
023: import javax.portlet.PortletSession;
024: import javax.portlet.RenderRequest;
025: import javax.security.auth.login.FailedLoginException;
026:
027: import org.apache.geronimo.console.MultiPageAbstractHandler;
028: import org.apache.geronimo.system.plugin.model.PluginListType;
029: import org.apache.geronimo.system.plugin.model.PluginType;
030: import org.apache.geronimo.system.plugin.model.PluginArtifactType;
031: import org.apache.geronimo.system.plugin.PluginInstaller;
032: import org.apache.geronimo.system.plugin.PluginInstallerGBean;
033: import org.apache.geronimo.kernel.config.NoSuchStoreException;
034:
035: /**
036: * The base class for all handlers for this portlet
037: *
038: * @version $Rev: 627838 $ $Date: 2008-02-14 10:54:30 -0800 (Thu, 14 Feb 2008) $
039: */
040: public abstract class BaseImportExportHandler extends
041: MultiPageAbstractHandler {
042: protected static final String CONFIG_LIST_SESSION_KEY = "console.plugins.ConfigurationList";
043: protected static final String CONFIG_LIST_REPO_SESSION_KEY = "console.plugins.ConfigurationListRepo";
044: protected static final String SERVER_CONFIG_LIST_SESSION_KEY = "console.plugins.ServerConfigurationList";
045: public static final String DOWNLOAD_RESULTS_SESSION_KEY = "console.plugins.DownloadResults";
046: protected static final String INDEX_MODE = "index";
047: protected static final String ADD_REPO_MODE = "addRepository";
048: protected static final String LIST_MODE = "list";
049: protected static final String DOWNLOAD_MODE = "download";
050: protected static final String VIEW_FOR_DOWNLOAD_MODE = "viewForDownload";
051: protected static final String DOWNLOAD_STATUS_MODE = "downloadStatus";
052: protected static final String RESULTS_MODE = "results";
053: protected static final String CONFIGURE_EXPORT_MODE = "configure";
054: protected static final String CONFIRM_EXPORT_MODE = "confirm";
055: protected static final String UPDATE_REPOS_MODE = "updateList";
056: protected static final String ASSEMBLY_CONFIRM_MODE = "assemblyConfirm";
057: protected static final String LIST_SERVER_MODE = "listServer";
058: protected static final String ASSEMBLY_VIEW_MODE = "assemblyView";
059:
060: protected BaseImportExportHandler(String mode, String viewName) {
061: super (mode, viewName);
062: }
063:
064: protected PluginListType getRepoPluginList(PortletRequest request,
065: PluginInstaller pluginInstaller, String repo, String user,
066: String pass) throws IOException, PortletException {
067: PortletSession session = request.getPortletSession(true);
068: PluginListType list = (PluginListType) session
069: .getAttribute(CONFIG_LIST_SESSION_KEY);
070: String listRepo = (String) session
071: .getAttribute(CONFIG_LIST_REPO_SESSION_KEY);
072:
073: if (list == null || !repo.equals(listRepo)) {
074: try {
075: list = pluginInstaller.listPlugins(new URL(repo), user,
076: pass);
077: } catch (FailedLoginException e) {
078: throw new PortletException(
079: "Invalid login for repository '" + repo + "'",
080: e);
081: }
082: session.setAttribute(CONFIG_LIST_SESSION_KEY, list);
083: session.setAttribute(CONFIG_LIST_REPO_SESSION_KEY, repo);
084: }
085: return list;
086: }
087:
088: protected PluginListType getServerPluginList(
089: PortletRequest request, PluginInstaller pluginInstaller)
090: throws PortletException {
091: PluginListType data = (PluginListType) request
092: .getPortletSession(true).getAttribute(
093: SERVER_CONFIG_LIST_SESSION_KEY);
094: if (data == null) {
095: try {
096: data = pluginInstaller
097: .createPluginListForRepositories(null);
098: } catch (NoSuchStoreException e) {
099: throw new PortletException("Server in unknown state", e);
100: }
101: }
102: return data;
103: }
104:
105: protected PluginListType getPluginsFromIds(String[] configIds,
106: PluginListType list) throws PortletException {
107: PluginListType installList = new PluginListType();
108: for (String configId : configIds) {
109: PluginType plugin = null;
110: for (PluginType metadata : list.getPlugin()) {
111: for (PluginArtifactType testInstance : metadata
112: .getPluginArtifact()) {
113: if (PluginInstallerGBean.toArtifact(
114: testInstance.getModuleId()).toString()
115: .equals(configId)) {
116: plugin = PluginInstallerGBean.copy(metadata,
117: testInstance);
118: installList.getPlugin().add(plugin);
119: break;
120: }
121: }
122: }
123: if (plugin == null) {
124: throw new PortletException(
125: "No configuration found for '" + configId + "'");
126: }
127: }
128: return installList;
129: }
130: }
|