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.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.log.Log;
020    import com.liferay.portal.kernel.log.LogFactoryUtil;
021    import com.liferay.portal.kernel.util.PropsKeys;
022    import com.liferay.portal.kernel.util.UnicodeProperties;
023    import com.liferay.portal.kernel.util.Validator;
024    import com.liferay.portal.model.ColorScheme;
025    import com.liferay.portal.model.Group;
026    import com.liferay.portal.model.LayoutSet;
027    import com.liferay.portal.model.LayoutSetStagingHandler;
028    import com.liferay.portal.model.Theme;
029    import com.liferay.portal.service.GroupLocalServiceUtil;
030    import com.liferay.portal.service.LayoutSetLocalServiceUtil;
031    import com.liferay.portal.service.ThemeLocalServiceUtil;
032    import com.liferay.portal.util.PrefsPropsUtil;
033    import com.liferay.portlet.exportimport.staging.LayoutStagingUtil;
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(), false);
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(
139                            getCompanyId(), getThemeId(), false);
140            }
141    
142            @Override
143            public String getThemeSetting(String key, String device) {
144                    UnicodeProperties settingsProperties = getSettingsProperties();
145    
146                    String value = settingsProperties.getProperty(
147                            ThemeSettingImpl.namespaceProperty(device, key));
148    
149                    if (value != null) {
150                            return value;
151                    }
152    
153                    Theme theme = null;
154    
155                    boolean controlPanel = false;
156    
157                    try {
158                            Group group = getGroup();
159    
160                            controlPanel = group.isControlPanel();
161                    }
162                    catch (Exception e) {
163                    }
164    
165                    if (controlPanel) {
166                            String themeId = PrefsPropsUtil.getString(
167                                    getCompanyId(),
168                                    PropsKeys.CONTROL_PANEL_LAYOUT_REGULAR_THEME_ID);
169    
170                            theme = ThemeLocalServiceUtil.getTheme(
171                                    getCompanyId(), themeId, !device.equals("regular"));
172                    }
173                    else if (device.equals("regular")) {
174                            theme = getTheme();
175                    }
176                    else {
177                            theme = getWapTheme();
178                    }
179    
180                    value = theme.getSetting(key);
181    
182                    return value;
183            }
184    
185            @Override
186            public ColorScheme getWapColorScheme() {
187                    return ThemeLocalServiceUtil.getColorScheme(
188                            getCompanyId(), getWapTheme().getThemeId(), getWapColorSchemeId(),
189                            true);
190            }
191    
192            @Override
193            public Theme getWapTheme() {
194                    return ThemeLocalServiceUtil.getTheme(
195                            getCompanyId(), getWapThemeId(), true);
196            }
197    
198            @Override
199            public boolean isLayoutSetPrototypeLinkActive() {
200                    if (isLayoutSetPrototypeLinkEnabled() &&
201                            Validator.isNotNull(getLayoutSetPrototypeUuid())) {
202    
203                            return true;
204                    }
205    
206                    return false;
207            }
208    
209            @Override
210            public boolean isLogo() {
211                    return getLogo();
212            }
213    
214            @Override
215            public void setSettings(String settings) {
216                    _settingsProperties = null;
217    
218                    super.setSettings(settings);
219            }
220    
221            @Override
222            public void setSettingsProperties(UnicodeProperties settingsProperties) {
223                    _settingsProperties = settingsProperties;
224    
225                    super.setSettings(_settingsProperties.toString());
226            }
227    
228            private static final Log _log = LogFactoryUtil.getLog(
229                    LayoutSetBranchImpl.class);
230    
231            private LayoutSet _layoutSet;
232            private UnicodeProperties _settingsProperties;
233    
234    }