001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.model.impl;
016    
017    import com.liferay.exportimport.kernel.staging.LayoutStagingUtil;
018    import com.liferay.portal.kernel.exception.PortalException;
019    import com.liferay.portal.kernel.exception.SystemException;
020    import com.liferay.portal.kernel.log.Log;
021    import com.liferay.portal.kernel.log.LogFactoryUtil;
022    import com.liferay.portal.kernel.model.ColorScheme;
023    import com.liferay.portal.kernel.model.Group;
024    import com.liferay.portal.kernel.model.LayoutSet;
025    import com.liferay.portal.kernel.model.LayoutSetStagingHandler;
026    import com.liferay.portal.kernel.model.Theme;
027    import com.liferay.portal.kernel.service.GroupLocalServiceUtil;
028    import com.liferay.portal.kernel.service.LayoutSetLocalServiceUtil;
029    import com.liferay.portal.kernel.service.ThemeLocalServiceUtil;
030    import com.liferay.portal.kernel.util.PropsKeys;
031    import com.liferay.portal.kernel.util.UnicodeProperties;
032    import com.liferay.portal.kernel.util.Validator;
033    import com.liferay.portal.util.PrefsPropsUtil;
034    
035    import java.io.IOException;
036    
037    /**
038     * @author Raymond Aug??
039     * @author Julio Camarero
040     */
041    public class LayoutSetBranchImpl extends LayoutSetBranchBaseImpl {
042    
043            @Override
044            public ColorScheme getColorScheme() {
045                    return ThemeLocalServiceUtil.getColorScheme(
046                            getCompanyId(), getTheme().getThemeId(), getColorSchemeId());
047            }
048    
049            @Override
050            public Group getGroup() throws PortalException {
051                    return GroupLocalServiceUtil.getGroup(getGroupId());
052            }
053    
054            @Override
055            public LayoutSet getLayoutSet() {
056                    if (_layoutSet != null) {
057                            return _layoutSet;
058                    }
059    
060                    try {
061                            _layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(
062                                    getGroupId(), getPrivateLayout());
063    
064                            LayoutSetStagingHandler layoutSetStagingHandler =
065                                    LayoutStagingUtil.getLayoutSetStagingHandler(_layoutSet);
066    
067                            if (layoutSetStagingHandler == null) {
068                                    return _layoutSet;
069                            }
070    
071                            _layoutSet = layoutSetStagingHandler.getLayoutSet();
072    
073                            return _layoutSet;
074                    }
075                    catch (SystemException se) {
076                    }
077                    catch (PortalException pe) {
078                    }
079    
080                    return _layoutSet;
081            }
082    
083            @Override
084            public long getLiveLogoId() {
085                    long logoId = getLayoutSet().getLogoId();
086    
087                    if (logoId == 0) {
088                            logoId = getLayoutSet().getLiveLogoId();
089                    }
090    
091                    return logoId;
092            }
093    
094            @Override
095            public boolean getLogo() {
096                    if (getLogoId() > 0) {
097                            return true;
098                    }
099    
100                    return false;
101            }
102    
103            @Override
104            public String getSettings() {
105                    if (_settingsProperties == null) {
106                            return super.getSettings();
107                    }
108                    else {
109                            return _settingsProperties.toString();
110                    }
111            }
112    
113            @Override
114            public UnicodeProperties getSettingsProperties() {
115                    if (_settingsProperties == null) {
116                            _settingsProperties = new UnicodeProperties(true);
117    
118                            try {
119                                    _settingsProperties.load(super.getSettings());
120                            }
121                            catch (IOException ioe) {
122                                    _log.error(ioe, ioe);
123                            }
124                    }
125    
126                    return _settingsProperties;
127            }
128    
129            @Override
130            public String getSettingsProperty(String key) {
131                    UnicodeProperties settingsProperties = getSettingsProperties();
132    
133                    return settingsProperties.getProperty(key);
134            }
135    
136            @Override
137            public Theme getTheme() {
138                    return ThemeLocalServiceUtil.getTheme(getCompanyId(), getThemeId());
139            }
140    
141            @Override
142            public String getThemeSetting(String key, String device) {
143                    UnicodeProperties settingsProperties = getSettingsProperties();
144    
145                    String value = settingsProperties.getProperty(
146                            ThemeSettingImpl.namespaceProperty(device, key));
147    
148                    if (value != null) {
149                            return value;
150                    }
151    
152                    Theme theme = null;
153    
154                    boolean controlPanel = false;
155    
156                    try {
157                            Group group = getGroup();
158    
159                            controlPanel = group.isControlPanel();
160                    }
161                    catch (Exception e) {
162                    }
163    
164                    if (controlPanel) {
165                            String themeId = PrefsPropsUtil.getString(
166                                    getCompanyId(),
167                                    PropsKeys.CONTROL_PANEL_LAYOUT_REGULAR_THEME_ID);
168    
169                            theme = ThemeLocalServiceUtil.getTheme(getCompanyId(), themeId);
170                    }
171                    else {
172                            theme = getTheme();
173                    }
174    
175                    value = theme.getSetting(key);
176    
177                    return value;
178            }
179    
180            @Override
181            public boolean isLayoutSetPrototypeLinkActive() {
182                    if (isLayoutSetPrototypeLinkEnabled() &&
183                            Validator.isNotNull(getLayoutSetPrototypeUuid())) {
184    
185                            return true;
186                    }
187    
188                    return false;
189            }
190    
191            @Override
192            public boolean isLogo() {
193                    return getLogo();
194            }
195    
196            @Override
197            public void setSettings(String settings) {
198                    _settingsProperties = null;
199    
200                    super.setSettings(settings);
201            }
202    
203            @Override
204            public void setSettingsProperties(UnicodeProperties settingsProperties) {
205                    _settingsProperties = settingsProperties;
206    
207                    super.setSettings(_settingsProperties.toString());
208            }
209    
210            private static final Log _log = LogFactoryUtil.getLog(
211                    LayoutSetBranchImpl.class);
212    
213            private LayoutSet _layoutSet;
214            private UnicodeProperties _settingsProperties;
215    
216    }