001/*
002 * (C) Copyright 2006-2008 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Olivier Grisel
016 *     Florent Guillaume
017 */
018
019package org.nuxeo.ecm.webapp.contentbrowser;
020
021import static org.jboss.seam.ScopeType.CONVERSATION;
022
023import java.io.Serializable;
024import java.util.ArrayList;
025import java.util.List;
026
027import org.apache.commons.logging.Log;
028import org.apache.commons.logging.LogFactory;
029import org.jboss.seam.annotations.Factory;
030import org.jboss.seam.annotations.In;
031import org.jboss.seam.annotations.Name;
032import org.jboss.seam.annotations.Scope;
033import org.nuxeo.ecm.core.api.repository.Repository;
034import org.nuxeo.ecm.core.api.repository.RepositoryManager;
035import org.nuxeo.ecm.platform.ui.web.api.NavigationContext;
036import org.nuxeo.ecm.platform.util.RepositoryLocation;
037import org.nuxeo.runtime.api.Framework;
038
039/**
040 * Action listener that knows how to retrieve a list of core servers.
041 *
042 * @author Olivier Grisel
043 * @author Florent Guillaume
044 */
045@Name("serverActions")
046@Scope(CONVERSATION)
047public class ServerActionsBean implements ServerActions, Serializable {
048
049    private static final long serialVersionUID = 1L;
050
051    // XXX AT: hardcoded right now
052    protected static final String DEFAULT_VIEW = "view_domains";
053
054    private static final Log log = LogFactory.getLog(ServerActionsBean.class);
055
056    @In(required = true, create = true)
057    protected transient NavigationContext navigationContext;
058
059    /**
060     * Retrieves the available locations.
061     */
062    @Override
063    @Factory("availableCoreRepositories")
064    public List<Repository> getAvailableRepositories() {
065        RepositoryManager repositoryManager = Framework.getService(RepositoryManager.class);
066        return new ArrayList<Repository>(repositoryManager.getRepositories());
067    }
068
069    @Override
070    public String selectRepository(String repositoryName) {
071        boolean found = false;
072        RepositoryManager repositoryManager = Framework.getService(RepositoryManager.class);
073        for (String name : repositoryManager.getRepositoryNames()) {
074            if (name.equals(repositoryName)) {
075                found = true;
076                break;
077            }
078        }
079        if (found) {
080            log.debug("Selected core name: " + repositoryName);
081            RepositoryLocation selectedLocation = new RepositoryLocation(repositoryName);
082            navigationContext.setCurrentServerLocation(selectedLocation);
083            return DEFAULT_VIEW;
084        } else {
085            return null;
086        }
087    }
088
089}