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