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.ecm.web.resources.jsf.negotiators; 018 019import javax.faces.context.FacesContext; 020 021import org.nuxeo.runtime.api.Framework; 022import org.nuxeo.theme.styling.negotiation.AbstractNegotiator; 023import org.nuxeo.theme.styling.service.ThemeStylingService; 024import org.nuxeo.theme.styling.service.descriptors.FlavorDescriptor; 025 026/** 027 * Negotiator that returns the default flavor configured for negotiated theme page. 028 * 029 * @see ThemeStylingService 030 * @see FlavorDescriptor 031 * @since 5.5 032 */ 033public class DefaultPageFlavor extends AbstractNegotiator { 034 035 @Override 036 public String getResult(String target, Object context) { 037 FacesContext faces = null; 038 if (context instanceof FacesContext) { 039 faces = (FacesContext) context; 040 } else { 041 return null; 042 } 043 String theme = (String) faces.getExternalContext().getRequestMap().get(getProperty("negotiatedPageVariable")); 044 if (theme != null) { 045 ThemeStylingService service = Framework.getService(ThemeStylingService.class); 046 return service.getDefaultFlavorName(theme); 047 } 048 return null; 049 } 050}