001/*
002 * (C) Copyright 2006-2008 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Olivier Grisel
018 *     Florent Guillaume
019 */
020
021package org.nuxeo.ecm.webapp.contentbrowser;
022
023import static org.jboss.seam.ScopeType.CONVERSATION;
024
025import java.io.Serializable;
026import java.util.ArrayList;
027import java.util.List;
028
029import org.apache.commons.logging.Log;
030import org.apache.commons.logging.LogFactory;
031import org.jboss.seam.annotations.Factory;
032import org.jboss.seam.annotations.In;
033import org.jboss.seam.annotations.Name;
034import org.jboss.seam.annotations.Scope;
035import org.nuxeo.ecm.core.api.repository.Repository;
036import org.nuxeo.ecm.core.api.repository.RepositoryManager;
037import org.nuxeo.ecm.platform.ui.web.api.NavigationContext;
038import org.nuxeo.ecm.platform.util.RepositoryLocation;
039import org.nuxeo.runtime.api.Framework;
040
041/**
042 * Action listener that knows how to retrieve a list of core servers.
043 *
044 * @author Olivier Grisel
045 * @author Florent Guillaume
046 */
047@Name("serverActions")
048@Scope(CONVERSATION)
049public class ServerActionsBean implements ServerActions, Serializable {
050
051    private static final long serialVersionUID = 1L;
052
053    // XXX AT: hardcoded right now
054    protected static final String DEFAULT_VIEW = "view_domains";
055
056    private static final Log log = LogFactory.getLog(ServerActionsBean.class);
057
058    @In(required = true, create = true)
059    protected transient NavigationContext navigationContext;
060
061    /**
062     * Retrieves the available locations.
063     */
064    @Override
065    @Factory("availableCoreRepositories")
066    public List<Repository> getAvailableRepositories() {
067        RepositoryManager repositoryManager = Framework.getService(RepositoryManager.class);
068        return new ArrayList<Repository>(repositoryManager.getRepositories());
069    }
070
071    @Override
072    public String selectRepository(String repositoryName) {
073        boolean found = false;
074        RepositoryManager repositoryManager = Framework.getService(RepositoryManager.class);
075        for (String name : repositoryManager.getRepositoryNames()) {
076            if (name.equals(repositoryName)) {
077                found = true;
078                break;
079            }
080        }
081        if (found) {
082            log.debug("Selected core name: " + repositoryName);
083            RepositoryLocation selectedLocation = new RepositoryLocation(repositoryName);
084            navigationContext.setCurrentServerLocation(selectedLocation);
085            return DEFAULT_VIEW;
086        } else {
087            return null;
088        }
089    }
090
091}