001/*
002 * (C) Copyright 2011 Nuxeo SAS (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 * Contributors:
014 * Nuxeo - initial API and implementation
015 */
016
017package org.nuxeo.theme.localconfiguration;
018
019import org.nuxeo.ecm.core.api.DocumentModel;
020import org.nuxeo.ecm.core.api.DocumentRef;
021import org.nuxeo.ecm.core.api.PropertyException;
022import org.nuxeo.ecm.core.api.localconfiguration.AbstractLocalConfiguration;
023
024/**
025 * Default implementation of {@code LocalThemeConfig}.
026 *
027 * @author <a href="mailto:qlamerand@nuxeo.com">Quentin Lamerand</a>
028 */
029public class LocalThemeConfigAdapter extends AbstractLocalConfiguration<LocalThemeConfig> implements LocalThemeConfig {
030
031    protected DocumentRef documentRef;
032
033    protected String theme;
034
035    protected String page;
036
037    protected String perspective;
038
039    protected String engine;
040
041    protected String mode;
042
043    protected String flavor;
044
045    public LocalThemeConfigAdapter(DocumentModel doc) {
046        documentRef = doc.getRef();
047        try {
048            theme = (String) doc.getPropertyValue(LocalThemeConfigConstants.THEME_CONFIGURATION_THEME_PROPERTY);
049            page = (String) doc.getPropertyValue(LocalThemeConfigConstants.THEME_CONFIGURATION_PAGE_PROPERTY);
050            perspective = (String) doc.getPropertyValue(LocalThemeConfigConstants.THEME_CONFIGURATION_PERSPECTIVE_PROPERTY);
051            engine = (String) doc.getPropertyValue(LocalThemeConfigConstants.THEME_CONFIGURATION_ENGINE_PROPERTY);
052            mode = (String) doc.getPropertyValue(LocalThemeConfigConstants.THEME_CONFIGURATION_MODE_PROPERTY);
053            flavor = (String) doc.getPropertyValue(LocalThemeConfigConstants.THEME_CONFIGURATION_FLAVOR_PROPERTY);
054        } catch (PropertyException e) {
055        }
056    }
057
058    @Override
059    public DocumentRef getDocumentRef() {
060        return documentRef;
061    }
062
063    @Override
064    public boolean canMerge() {
065        return false;
066    }
067
068    @Override
069    public LocalThemeConfig merge(LocalThemeConfig other) {
070        return this;
071    }
072
073    @Override
074    public String getTheme() {
075        return theme;
076    }
077
078    @Override
079    public String getPage() {
080        return page;
081    }
082
083    @Override
084    public String getPerspective() {
085        return perspective;
086    }
087
088    @Override
089    public String getEngine() {
090        return engine;
091    }
092
093    @Override
094    public String getMode() {
095        return mode;
096    }
097
098    /**
099     * @since 5.5
100     */
101    @Override
102    public String getFlavor() {
103        return flavor;
104    }
105
106    @Override
107    public String computePagePath() {
108        if (theme == null || page == null) {
109            return null;
110        }
111        return String.format("%s/%s", theme, page);
112    }
113
114}