001/*
002 * (C) Copyright 2011 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 * Contributors:
016 * Nuxeo - initial API and implementation
017 */
018
019package org.nuxeo.ecm.localconf;
020
021import java.io.Serializable;
022import java.util.List;
023
024import org.jboss.seam.annotations.In;
025import org.jboss.seam.annotations.Install;
026import org.jboss.seam.annotations.Name;
027import org.jboss.seam.annotations.Scope;
028import org.nuxeo.ecm.core.api.DocumentModel;
029import org.nuxeo.ecm.platform.ui.web.api.NavigationContext;
030import org.nuxeo.theme.localconfiguration.LocalThemeConfig;
031import org.nuxeo.theme.localconfiguration.LocalThemeHelper;
032import org.nuxeo.theme.styling.service.ThemeStylingService;
033import org.nuxeo.theme.styling.service.descriptors.FlavorDescriptor;
034
035import static org.jboss.seam.ScopeType.CONVERSATION;
036
037@Name("themeConfigurationActions")
038@Scope(CONVERSATION)
039@Install(precedence = Install.FRAMEWORK)
040public class ThemeConfigurationActions implements Serializable {
041
042    private static final long serialVersionUID = 1L;
043
044    @In(create = true)
045    protected transient NavigationContext navigationContext;
046
047    @In(create = true, required = false)
048    protected transient ThemeStylingService themeStylingService;
049
050    protected String theme;
051
052    /**
053     * Returns the layout to use for local configuration, to handle migration to a flavor model
054     *
055     * @since 5.5
056     */
057    public String getConfigurationLayout() {
058        return "theme_configuration";
059    }
060
061    public List<FlavorDescriptor> getAvailableFlavors(String themePage) {
062        return themeStylingService.getFlavors(themePage);
063    }
064
065    public String getDefaultFlavorName(String themePage) {
066        return themeStylingService.getDefaultFlavorName(themePage);
067    }
068
069    public FlavorDescriptor getDefaultFlavor(String themePage) {
070        String flavorName = themeStylingService.getDefaultFlavorName(themePage);
071        if (flavorName != null) {
072            return themeStylingService.getFlavor(flavorName);
073        }
074        return null;
075    }
076
077    public String getCurrentLocalFlavorName() {
078        DocumentModel currentSuperSpace = navigationContext.getCurrentSuperSpace();
079        if (currentSuperSpace != null) {
080            LocalThemeConfig localThemeConfig = LocalThemeHelper.getLocalThemeConfig(currentSuperSpace);
081            if (localThemeConfig != null) {
082                // extract the flavor
083                String flavor = localThemeConfig.getFlavor();
084                return flavor;
085            }
086        }
087        return null;
088    }
089
090}