001/*
002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Jean-Marc Orliaguet, Chalmers
018 *
019 * $Id$
020 */
021
022package org.nuxeo.theme.compat.negotiators;
023
024import org.jboss.seam.Component;
025import org.nuxeo.ecm.core.api.DocumentModel;
026import org.nuxeo.runtime.api.Framework;
027import org.nuxeo.theme.localconfiguration.LocalThemeConfig;
028import org.nuxeo.theme.localconfiguration.LocalThemeHelper;
029import org.nuxeo.theme.negotiation.Scheme;
030import org.nuxeo.theme.perspectives.PerspectiveManager;
031import org.nuxeo.theme.perspectives.PerspectiveType;
032
033/**
034 * Negotiation scheme for obtaining the local perspective from the current document.
035 *
036 * @author <a href="mailto:jmo@chalmers.se">Jean-Marc Orliaguet</a>
037 * @deprecated since 5.5: use local theme flavour instead
038 */
039@Deprecated
040public class LocalPerspective implements Scheme {
041
042    /**
043     * Called by the theme negotiation module.
044     *
045     * @return the local theme associated to the current space (workspace, section, ...) as a 'theme/page' string.
046     *         Return null otherwise.
047     */
048    public String getOutcome(Object context) {
049        Boolean useOldThemeConf = Boolean.valueOf(Framework.getProperty(LocalThemeConfig.OLD_THEME_CONFIGURATION_PROPERTY));
050        if (Boolean.FALSE.equals(useOldThemeConf)) {
051            return null;
052        }
053
054        DocumentModel currentSuperSpace = (DocumentModel) Component.getInstance("currentSuperSpace");
055        if (currentSuperSpace == null) {
056            return null;
057        }
058
059        // Get the placeful local theme configuration for the current
060        // workspace.
061        LocalThemeConfig localThemeConfig = LocalThemeHelper.getLocalThemeConfig(currentSuperSpace);
062        if (localThemeConfig == null) {
063            return null;
064        }
065
066        // Extract the perspective
067        String perspectiveName = localThemeConfig.getPerspective();
068        if (perspectiveName == null) {
069            return null;
070        }
071
072        // Look up the perspective
073        PerspectiveType perspective = PerspectiveManager.getPerspectiveByName(perspectiveName);
074        if (perspective != null) {
075            return perspectiveName;
076        }
077        return null;
078    }
079
080}