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() throws SystemException {
048 return ThemeLocalServiceUtil.getColorScheme(
049 getCompanyId(), getTheme().getThemeId(), getColorSchemeId(), false);
050 }
051
052 @Override
053 public Group getGroup() throws PortalException, SystemException {
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 String getSettings() {
099 if (_settingsProperties == null) {
100 return super.getSettings();
101 }
102 else {
103 return _settingsProperties.toString();
104 }
105 }
106
107 @Override
108 public UnicodeProperties getSettingsProperties() {
109 if (_settingsProperties == null) {
110 _settingsProperties = new UnicodeProperties(true);
111
112 try {
113 _settingsProperties.load(super.getSettings());
114 }
115 catch (IOException ioe) {
116 _log.error(ioe, ioe);
117 }
118 }
119
120 return _settingsProperties;
121 }
122
123 @Override
124 public String getSettingsProperty(String key) {
125 UnicodeProperties settingsProperties = getSettingsProperties();
126
127 return settingsProperties.getProperty(key);
128 }
129
130 @Override
131 public Theme getTheme() throws SystemException {
132 return ThemeLocalServiceUtil.getTheme(
133 getCompanyId(), getThemeId(), false);
134 }
135
136 @Override
137 public String getThemeSetting(String key, String device)
138 throws SystemException {
139
140 UnicodeProperties settingsProperties = getSettingsProperties();
141
142 String value = settingsProperties.getProperty(
143 ThemeSettingImpl.namespaceProperty(device, key));
144
145 if (value != null) {
146 return value;
147 }
148
149 Theme theme = null;
150
151 boolean controlPanel = false;
152
153 try {
154 Group group = getGroup();
155
156 controlPanel = group.isControlPanel();
157 }
158 catch (Exception e) {
159 }
160
161 if (controlPanel) {
162 String themeId = PrefsPropsUtil.getString(
163 getCompanyId(),
164 PropsKeys.CONTROL_PANEL_LAYOUT_REGULAR_THEME_ID);
165
166 theme = ThemeLocalServiceUtil.getTheme(
167 getCompanyId(), themeId, !device.equals("regular"));
168 }
169 else if (device.equals("regular")) {
170 theme = getTheme();
171 }
172 else {
173 theme = getWapTheme();
174 }
175
176 value = theme.getSetting(key);
177
178 return value;
179 }
180
181 @Override
182 public ColorScheme getWapColorScheme() throws SystemException {
183 return ThemeLocalServiceUtil.getColorScheme(
184 getCompanyId(), getWapTheme().getThemeId(), getWapColorSchemeId(),
185 true);
186 }
187
188 @Override
189 public Theme getWapTheme() throws SystemException {
190 return ThemeLocalServiceUtil.getTheme(
191 getCompanyId(), getWapThemeId(), true);
192 }
193
194 @Override
195 public boolean isLayoutSetPrototypeLinkActive() {
196 if (isLayoutSetPrototypeLinkEnabled() &&
197 Validator.isNotNull(getLayoutSetPrototypeUuid())) {
198
199 return true;
200 }
201
202 return false;
203 }
204
205 @Override
206 public void setSettings(String settings) {
207 _settingsProperties = null;
208
209 super.setSettings(settings);
210 }
211
212 @Override
213 public void setSettingsProperties(UnicodeProperties settingsProperties) {
214 _settingsProperties = settingsProperties;
215
216 super.setSettings(_settingsProperties.toString());
217 }
218
219 private static Log _log = LogFactoryUtil.getLog(LayoutSetBranchImpl.class);
220
221 private LayoutSet _layoutSet;
222 private UnicodeProperties _settingsProperties;
223
224 }