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