/*
 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and contributors.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * Contributors:
 *     Anahide Tchertchian
 */
package org.nuxeo.ecm.platform.localconfiguration.theme.negociation;

import javax.faces.context.FacesContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuxeo.runtime.api.Framework;
import org.nuxeo.theme.negotiation.Scheme;
import org.nuxeo.theme.styling.service.ThemeStylingService;

/**
 * @since 5.4.3
 */
public class DefaultThemeFlavour implements Scheme {

    private static final Log log = LogFactory.getLog(DefaultThemeFlavour.class);

    public String getOutcome(Object context) {
        FacesContext faces = (FacesContext) context;
        // FIXME: retrieve current theme returned by negotiation instead of
        // using default theme
        String defaultTheme = (String) faces.getExternalContext().getRequestMap().get(
                "org.nuxeo.theme.default.theme");
        if (defaultTheme != null) {
            try {
                ThemeStylingService service = Framework.getService(ThemeStylingService.class);
                return service.getDefaultFlavour(defaultTheme);
            } catch (Exception e) {
                log.error(e);
            }
        }
        return null;
    }

}

@@ -878,16 +878,63 @@
 mework;%0A
+import org.nuxeo.theme.negotiation.Negotiator;%0A
 import o
@@ -1503,39 +1503,113 @@
     
-%22org.nuxeo.theme.default.theme%22
+Negotiator.NEGOTIATION_RESULT_PREFIX%0A                        + Negotiator.NEGOTIATION_OBJECT.theme.name()
 );%0A 

add negotiation results to the request map to pass it through to following negotiators