001/*
002 * (C) Copyright 2006-2007 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.compat.negotiators;
016
017import org.jboss.seam.Component;
018import org.nuxeo.ecm.core.api.DocumentModel;
019import org.nuxeo.runtime.api.Framework;
020import org.nuxeo.theme.Manager;
021import org.nuxeo.theme.elements.PageElement;
022import org.nuxeo.theme.localconfiguration.LocalThemeConfig;
023import org.nuxeo.theme.localconfiguration.LocalThemeHelper;
024import org.nuxeo.theme.negotiation.Scheme;
025
026/**
027 * Negotiation scheme for obtaining the local theme from the current space.
028 *
029 * @author <a href="mailto:jmo@chalmers.se">Jean-Marc Orliaguet</a>
030 * @deprecated since 5.5: use local theme flavor instead
031 */
032@Deprecated
033public class LocalTheme implements Scheme {
034
035    /**
036     * Called by the theme negotiation module.
037     *
038     * @return the local theme associated to the current space (workspace, section, ...) as a 'theme/page' string.
039     *         Return null otherwise.
040     */
041    public String getOutcome(Object context) {
042        Boolean useOldThemeConf = Boolean.valueOf(Framework.getProperty(LocalThemeConfig.OLD_THEME_CONFIGURATION_PROPERTY));
043        if (Boolean.FALSE.equals(useOldThemeConf)) {
044            return null;
045        }
046
047        DocumentModel currentSuperSpace = (DocumentModel) Component.getInstance("currentSuperSpace");
048        if (currentSuperSpace == null) {
049            return null;
050        }
051
052        // Get the placeful local theme configuration for the current
053        // workspace.
054        LocalThemeConfig localThemeConfig = LocalThemeHelper.getLocalThemeConfig(currentSuperSpace);
055        if (localThemeConfig == null) {
056            return null;
057        }
058
059        // Extract the page path
060        String path = localThemeConfig.computePagePath();
061        if (path == null) {
062            return null;
063        }
064
065        // Look up the page
066        PageElement page = Manager.getThemeManager().getPageByPath(path);
067        if (page != null) {
068            return path;
069        }
070        return null;
071    }
072
073}