001/*
002 * (C) Copyright 2006-2009 Nuxeo SAS <http://nuxeo.com> and others
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     Jean-Marc Orliaguet, Chalmers
011 *
012 * $Id$
013 */
014
015package org.nuxeo.theme.webengine.negotiation.theme;
016
017import org.nuxeo.ecm.webengine.model.WebContext;
018import org.nuxeo.theme.Manager;
019import org.nuxeo.theme.elements.PageElement;
020import org.nuxeo.theme.negotiation.Scheme;
021
022public final class RequestAttribute implements Scheme {
023
024    public String getOutcome(final Object context) {
025        final String path = (String) ((WebContext) context).getRequest().getAttribute("org.nuxeo.theme.theme");
026        if (path == null) {
027            return null;
028        }
029        final PageElement page = Manager.getThemeManager().getPageByPath(path);
030        if (page != null) {
031            return path;
032        }
033        return null;
034    }
035
036}