1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.model.impl;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portal.kernel.log.Log;
20  import com.liferay.portal.kernel.log.LogFactoryUtil;
21  import com.liferay.portal.kernel.util.UnicodeProperties;
22  import com.liferay.portal.model.ColorScheme;
23  import com.liferay.portal.model.Group;
24  import com.liferay.portal.model.LayoutSet;
25  import com.liferay.portal.model.Theme;
26  import com.liferay.portal.service.GroupLocalServiceUtil;
27  import com.liferay.portal.service.ThemeLocalServiceUtil;
28  
29  import java.io.IOException;
30  
31  /**
32   * <a href="LayoutSetImpl.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   * @author Jorge Ferrer
36   */
37  public class LayoutSetImpl extends LayoutSetModelImpl implements LayoutSet {
38  
39      public LayoutSetImpl() {
40      }
41  
42      public Theme getTheme() throws SystemException {
43          return ThemeLocalServiceUtil.getTheme(
44              getCompanyId(), getThemeId(), false);
45      }
46  
47      public ColorScheme getColorScheme() throws SystemException {
48          return ThemeLocalServiceUtil.getColorScheme(
49              getCompanyId(), getTheme().getThemeId(), getColorSchemeId(), false);
50      }
51  
52      public Group getGroup() throws PortalException, SystemException {
53          return GroupLocalServiceUtil.getGroup(getGroupId());
54      }
55  
56      public String getSettings() {
57          if (_settingsProperties == null) {
58              return super.getSettings();
59          }
60          else {
61              return _settingsProperties.toString();
62          }
63      }
64  
65      public UnicodeProperties getSettingsProperties() {
66          if (_settingsProperties == null) {
67              _settingsProperties = new UnicodeProperties(true);
68  
69              try {
70                  _settingsProperties.load(super.getSettings());
71              }
72              catch (IOException ioe) {
73                  _log.error(ioe, ioe);
74              }
75          }
76  
77          return _settingsProperties;
78      }
79  
80      public String getSettingsProperty(String key) {
81          UnicodeProperties settingsProperties = getSettingsProperties();
82  
83          return settingsProperties.getProperty(key);
84      }
85  
86      public Theme getWapTheme() throws SystemException {
87          return ThemeLocalServiceUtil.getTheme(
88              getCompanyId(), getWapThemeId(), true);
89      }
90  
91      public ColorScheme getWapColorScheme() throws SystemException {
92          return ThemeLocalServiceUtil.getColorScheme(
93              getCompanyId(), getWapTheme().getThemeId(), getWapColorSchemeId(),
94              true);
95      }
96  
97      public void setSettings(String settings) {
98          _settingsProperties = null;
99  
100         super.setSettings(settings);
101     }
102 
103     public void setSettingsProperties(UnicodeProperties settingsProperties) {
104         _settingsProperties = settingsProperties;
105 
106         super.setSettings(_settingsProperties.toString());
107     }
108 
109     private static Log _log = LogFactoryUtil.getLog(LayoutSetImpl.class);
110 
111     private UnicodeProperties _settingsProperties;
112 
113 }