001
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.staging.LayoutStagingUtil;
022 import com.liferay.portal.kernel.util.PropsKeys;
023 import com.liferay.portal.kernel.util.UnicodeProperties;
024 import com.liferay.portal.kernel.util.Validator;
025 import com.liferay.portal.model.ColorScheme;
026 import com.liferay.portal.model.Group;
027 import com.liferay.portal.model.LayoutSet;
028 import com.liferay.portal.model.LayoutSetStagingHandler;
029 import com.liferay.portal.model.Theme;
030 import com.liferay.portal.service.GroupLocalServiceUtil;
031 import com.liferay.portal.service.LayoutSetLocalServiceUtil;
032 import com.liferay.portal.service.ThemeLocalServiceUtil;
033 import com.liferay.portal.util.PrefsPropsUtil;
034
035 import java.io.IOException;
036
037
041 public class LayoutSetBranchImpl extends LayoutSetBranchBaseImpl {
042
043 public LayoutSetBranchImpl() {
044 }
045
046 @Override
047 public ColorScheme getColorScheme() {
048 return ThemeLocalServiceUtil.getColorScheme(
049 getCompanyId(), getTheme().getThemeId(), getColorSchemeId(), false);
050 }
051
052 @Override
053 public Group getGroup() throws PortalException {
054 return GroupLocalServiceUtil.getGroup(getGroupId());
055 }
056
057 @Override
058 public LayoutSet getLayoutSet() {
059 if (_layoutSet != null) {
060 return _layoutSet;
061 }
062
063 try {
064 _layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(
065 getGroupId(), getPrivateLayout());
066
067 LayoutSetStagingHandler layoutSetStagingHandler =
068 LayoutStagingUtil.getLayoutSetStagingHandler(_layoutSet);
069
070 if (layoutSetStagingHandler == null) {
071 return _layoutSet;
072 }
073
074 _layoutSet = layoutSetStagingHandler.getLayoutSet();
075
076 return _layoutSet;
077 }
078 catch (SystemException se) {
079 }
080 catch (PortalException pe) {
081 }
082
083 return _layoutSet;
084 }
085
086 @Override
087 public long getLiveLogoId() {
088 long logoId = getLayoutSet().getLogoId();
089
090 if (logoId == 0) {
091 logoId = getLayoutSet().getLiveLogoId();
092 }
093
094 return logoId;
095 }
096
097 @Override
098 public boolean getLogo() {
099 if (getLogoId() > 0) {
100 return true;
101 }
102
103 return false;
104 }
105
106 @Override
107 public String getSettings() {
108 if (_settingsProperties == null) {
109 return super.getSettings();
110 }
111 else {
112 return _settingsProperties.toString();
113 }
114 }
115
116 @Override
117 public UnicodeProperties getSettingsProperties() {
118 if (_settingsProperties == null) {
119 _settingsProperties = new UnicodeProperties(true);
120
121 try {
122 _settingsProperties.load(super.getSettings());
123 }
124 catch (IOException ioe) {
125 _log.error(ioe, ioe);
126 }
127 }
128
129 return _settingsProperties;
130 }
131
132 @Override
133 public String getSettingsProperty(String key) {
134 UnicodeProperties settingsProperties = getSettingsProperties();
135
136 return settingsProperties.getProperty(key);
137 }
138
139 @Override
140 public Theme getTheme() {
141 return ThemeLocalServiceUtil.getTheme(
142 getCompanyId(), getThemeId(), false);
143 }
144
145 @Override
146 public String getThemeSetting(String key, String device) {
147 UnicodeProperties settingsProperties = getSettingsProperties();
148
149 String value = settingsProperties.getProperty(
150 ThemeSettingImpl.namespaceProperty(device, key));
151
152 if (value != null) {
153 return value;
154 }
155
156 Theme theme = null;
157
158 boolean controlPanel = false;
159
160 try {
161 Group group = getGroup();
162
163 controlPanel = group.isControlPanel();
164 }
165 catch (Exception e) {
166 }
167
168 if (controlPanel) {
169 String themeId = PrefsPropsUtil.getString(
170 getCompanyId(),
171 PropsKeys.CONTROL_PANEL_LAYOUT_REGULAR_THEME_ID);
172
173 theme = ThemeLocalServiceUtil.getTheme(
174 getCompanyId(), themeId, !device.equals("regular"));
175 }
176 else if (device.equals("regular")) {
177 theme = getTheme();
178 }
179 else {
180 theme = getWapTheme();
181 }
182
183 value = theme.getSetting(key);
184
185 return value;
186 }
187
188 @Override
189 public ColorScheme getWapColorScheme() {
190 return ThemeLocalServiceUtil.getColorScheme(
191 getCompanyId(), getWapTheme().getThemeId(), getWapColorSchemeId(),
192 true);
193 }
194
195 @Override
196 public Theme getWapTheme() {
197 return ThemeLocalServiceUtil.getTheme(
198 getCompanyId(), getWapThemeId(), true);
199 }
200
201 @Override
202 public boolean isLayoutSetPrototypeLinkActive() {
203 if (isLayoutSetPrototypeLinkEnabled() &&
204 Validator.isNotNull(getLayoutSetPrototypeUuid())) {
205
206 return true;
207 }
208
209 return false;
210 }
211
212 @Override
213 public boolean isLogo() {
214 return getLogo();
215 }
216
217 @Override
218 public void setSettings(String settings) {
219 _settingsProperties = null;
220
221 super.setSettings(settings);
222 }
223
224 @Override
225 public void setSettingsProperties(UnicodeProperties settingsProperties) {
226 _settingsProperties = settingsProperties;
227
228 super.setSettings(_settingsProperties.toString());
229 }
230
231 private static final Log _log = LogFactoryUtil.getLog(
232 LayoutSetBranchImpl.class);
233
234 private LayoutSet _layoutSet;
235 private UnicodeProperties _settingsProperties;
236
237 }