001
014
015 package com.liferay.portal.model.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.log.Log;
019 import com.liferay.portal.kernel.log.LogFactoryUtil;
020 import com.liferay.portal.kernel.util.PropsKeys;
021 import com.liferay.portal.kernel.util.StringPool;
022 import com.liferay.portal.kernel.util.UnicodeProperties;
023 import com.liferay.portal.kernel.util.Validator;
024 import com.liferay.portal.model.CacheField;
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.LayoutSetPrototype;
029 import com.liferay.portal.model.Theme;
030 import com.liferay.portal.model.VirtualHost;
031 import com.liferay.portal.service.GroupLocalServiceUtil;
032 import com.liferay.portal.service.LayoutSetPrototypeLocalServiceUtil;
033 import com.liferay.portal.service.ThemeLocalServiceUtil;
034 import com.liferay.portal.service.VirtualHostLocalServiceUtil;
035 import com.liferay.portal.util.PrefsPropsUtil;
036
037 import java.io.IOException;
038
039
051 public class LayoutSetImpl extends LayoutSetBaseImpl {
052
053 public LayoutSetImpl() {
054 }
055
056
067 @Override
068 public ColorScheme getColorScheme() {
069 return ThemeLocalServiceUtil.getColorScheme(
070 getCompanyId(), getTheme().getThemeId(), getColorSchemeId(), false);
071 }
072
073
080 @Override
081 public Group getGroup() throws PortalException {
082 return GroupLocalServiceUtil.getGroup(getGroupId());
083 }
084
085
098 @Override
099 public long getLayoutSetPrototypeId() throws PortalException {
100 String layoutSetPrototypeUuid = getLayoutSetPrototypeUuid();
101
102 if (Validator.isNull(layoutSetPrototypeUuid)) {
103 return 0;
104 }
105
106 LayoutSetPrototype layoutSetPrototype =
107 LayoutSetPrototypeLocalServiceUtil.
108 getLayoutSetPrototypeByUuidAndCompanyId(
109 layoutSetPrototypeUuid, getCompanyId());
110
111 return layoutSetPrototype.getLayoutSetPrototypeId();
112 }
113
114 @Override
115 public long getLiveLogoId() {
116 long logoId = 0;
117
118 Group group = null;
119
120 try {
121 group = getGroup();
122
123 if (!group.isStagingGroup()) {
124 return logoId;
125 }
126 }
127 catch (Exception e) {
128 return logoId;
129 }
130
131 Group liveGroup = group.getLiveGroup();
132
133 LayoutSet liveLayoutSet = null;
134
135 if (isPrivateLayout()) {
136 liveLayoutSet = liveGroup.getPrivateLayoutSet();
137 }
138 else {
139 liveLayoutSet = liveGroup.getPublicLayoutSet();
140 }
141
142 return liveLayoutSet.getLogoId();
143 }
144
145 @Override
146 public boolean getLogo() {
147 if (getLogoId() > 0) {
148 return true;
149 }
150
151 return false;
152 }
153
154 @Override
155 public String getSettings() {
156 if (_settingsProperties == null) {
157 return super.getSettings();
158 }
159 else {
160 return _settingsProperties.toString();
161 }
162 }
163
164 @Override
165 public UnicodeProperties getSettingsProperties() {
166 if (_settingsProperties == null) {
167 _settingsProperties = new UnicodeProperties(true);
168
169 try {
170 _settingsProperties.load(super.getSettings());
171 }
172 catch (IOException ioe) {
173 _log.error(ioe, ioe);
174 }
175 }
176
177 return _settingsProperties;
178 }
179
180 @Override
181 public String getSettingsProperty(String key) {
182 UnicodeProperties settingsProperties = getSettingsProperties();
183
184 return settingsProperties.getProperty(key);
185 }
186
187 @Override
188 public Theme getTheme() {
189 return ThemeLocalServiceUtil.getTheme(
190 getCompanyId(), getThemeId(), false);
191 }
192
193 @Override
194 public String getThemeSetting(String key, String device) {
195 UnicodeProperties settingsProperties = getSettingsProperties();
196
197 String value = settingsProperties.getProperty(
198 ThemeSettingImpl.namespaceProperty(device, key));
199
200 if (value != null) {
201 return value;
202 }
203
204 Theme theme = getTheme(device);
205
206 value = theme.getSetting(key);
207
208 return value;
209 }
210
211
222 @Override
223 public String getVirtualHostname() {
224 if (_virtualHostname != null) {
225 return _virtualHostname;
226 }
227
228 try {
229 VirtualHost virtualHost =
230 VirtualHostLocalServiceUtil.fetchVirtualHost(
231 getCompanyId(), getLayoutSetId());
232
233 if (virtualHost == null) {
234 _virtualHostname = StringPool.BLANK;
235 }
236 else {
237 _virtualHostname = virtualHost.getHostname();
238 }
239 }
240 catch (Exception e) {
241 _virtualHostname = StringPool.BLANK;
242 }
243
244 return _virtualHostname;
245 }
246
247 @Override
248 public ColorScheme getWapColorScheme() {
249 return ThemeLocalServiceUtil.getColorScheme(
250 getCompanyId(), getWapTheme().getThemeId(), getWapColorSchemeId(),
251 true);
252 }
253
254 @Override
255 public Theme getWapTheme() {
256 return ThemeLocalServiceUtil.getTheme(
257 getCompanyId(), getWapThemeId(), true);
258 }
259
260 @Override
261 public boolean isLayoutSetPrototypeLinkActive() {
262 if (isLayoutSetPrototypeLinkEnabled() &&
263 Validator.isNotNull(getLayoutSetPrototypeUuid())) {
264
265 return true;
266 }
267
268 return false;
269 }
270
271 @Override
272 public boolean isLogo() {
273 return getLogo();
274 }
275
276 @Override
277 public void setSettings(String settings) {
278 _settingsProperties = null;
279
280 super.setSettings(settings);
281 }
282
283 @Override
284 public void setSettingsProperties(UnicodeProperties settingsProperties) {
285 _settingsProperties = settingsProperties;
286
287 super.setSettings(_settingsProperties.toString());
288 }
289
290
296 @Override
297 public void setVirtualHostname(String virtualHostname) {
298 _virtualHostname = virtualHostname;
299 }
300
301 protected Theme getTheme(String device) {
302 boolean controlPanel = false;
303
304 try {
305 Group group = getGroup();
306
307 controlPanel = group.isControlPanel();
308 }
309 catch (Exception e) {
310 }
311
312 if (controlPanel) {
313 String themeId = PrefsPropsUtil.getString(
314 getCompanyId(),
315 PropsKeys.CONTROL_PANEL_LAYOUT_REGULAR_THEME_ID);
316
317 return ThemeLocalServiceUtil.getTheme(
318 getCompanyId(), themeId, !device.equals("regular"));
319 }
320 else if (device.equals("regular")) {
321 return getTheme();
322 }
323 else {
324 return getWapTheme();
325 }
326 }
327
328 private static final Log _log = LogFactoryUtil.getLog(LayoutSetImpl.class);
329
330 private UnicodeProperties _settingsProperties;
331
332 @CacheField
333 private String _virtualHostname;
334
335 }