001/*
002 * (C) Copyright 2011 Nuxeo SA (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 *     Anahide Tchertchian
016 */
017package org.nuxeo.theme.compat.negotiators;
018
019import javax.faces.context.FacesContext;
020
021import org.nuxeo.runtime.api.Framework;
022import org.nuxeo.theme.negotiation.Negotiator;
023import org.nuxeo.theme.negotiation.Scheme;
024import org.nuxeo.theme.styling.service.ThemeStylingService;
025import org.nuxeo.theme.styling.service.descriptors.FlavorDescriptor;
026
027/**
028 * Negotiator that returns the default flavor configured for negotiated theme page.
029 *
030 * @see ThemeStylingService
031 * @see FlavorDescriptor
032 * @since 5.5
033 */
034public class DefaultThemeFlavor implements Scheme {
035
036    @Override
037    public String getOutcome(Object context) {
038        FacesContext faces = (FacesContext) context;
039        String theme = (String) faces.getExternalContext().getRequestMap().get(
040                Negotiator.NEGOTIATION_RESULT_PREFIX + Negotiator.NEGOTIATION_OBJECT.theme.name());
041        if (theme != null) {
042            ThemeStylingService service = Framework.getService(ThemeStylingService.class);
043            return service.getDefaultFlavorName(theme);
044        }
045        return null;
046    }
047}