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.util.PropsKeys;
022 import com.liferay.portal.kernel.util.StringPool;
023 import com.liferay.portal.kernel.util.UnicodeProperties;
024 import com.liferay.portal.model.ColorScheme;
025 import com.liferay.portal.model.Group;
026 import com.liferay.portal.model.Theme;
027 import com.liferay.portal.model.VirtualHost;
028 import com.liferay.portal.service.GroupLocalServiceUtil;
029 import com.liferay.portal.service.ThemeLocalServiceUtil;
030 import com.liferay.portal.service.VirtualHostLocalServiceUtil;
031 import com.liferay.portal.util.PrefsPropsUtil;
032
033 import java.io.IOException;
034
035
039 public class LayoutSetImpl extends LayoutSetBaseImpl {
040
041 public LayoutSetImpl() {
042 }
043
044 public Theme getTheme() throws SystemException {
045 return ThemeLocalServiceUtil.getTheme(
046 getCompanyId(), getThemeId(), false);
047 }
048
049 public ColorScheme getColorScheme() throws SystemException {
050 return ThemeLocalServiceUtil.getColorScheme(
051 getCompanyId(), getTheme().getThemeId(), getColorSchemeId(), false);
052 }
053
054 public Group getGroup() throws PortalException, SystemException {
055 return GroupLocalServiceUtil.getGroup(getGroupId());
056 }
057
058 @Override
059 public String getSettings() {
060 if (_settingsProperties == null) {
061 return super.getSettings();
062 }
063 else {
064 return _settingsProperties.toString();
065 }
066 }
067
068 public UnicodeProperties getSettingsProperties() {
069 if (_settingsProperties == null) {
070 _settingsProperties = new UnicodeProperties(true);
071
072 try {
073 _settingsProperties.load(super.getSettings());
074 }
075 catch (IOException ioe) {
076 _log.error(ioe, ioe);
077 }
078 }
079
080 return _settingsProperties;
081 }
082
083 public String getSettingsProperty(String key) {
084 UnicodeProperties settingsProperties = getSettingsProperties();
085
086 return settingsProperties.getProperty(key);
087 }
088
089 public String getThemeSetting(String key, String device)
090 throws SystemException {
091
092 UnicodeProperties settingsProperties = getSettingsProperties();
093
094 String value = settingsProperties.getProperty(
095 ThemeSettingImpl.namespaceProperty(device, key));
096
097 if (value != null) {
098 return value;
099 }
100
101 Theme theme = null;
102
103 boolean controlPanel = false;
104
105 try {
106 Group group = getGroup();
107
108 controlPanel = group.isControlPanel();
109 }
110 catch (Exception e) {
111 }
112
113 if (controlPanel) {
114 String themeId = PrefsPropsUtil.getString(
115 getCompanyId(),
116 PropsKeys.CONTROL_PANEL_LAYOUT_REGULAR_THEME_ID);
117
118 theme = ThemeLocalServiceUtil.getTheme(
119 getCompanyId(), themeId, !device.equals("regular"));
120 }
121 else if (device.equals("regular")) {
122 theme = getTheme();
123 }
124 else {
125 theme = getWapTheme();
126 }
127
128 value = theme.getSetting(key);
129
130 return value;
131 }
132
133 public String getVirtualHostname() {
134 try {
135 VirtualHost virtualHost =
136 VirtualHostLocalServiceUtil.fetchVirtualHost(
137 getCompanyId(), getLayoutSetId());
138
139 if (virtualHost == null) {
140 return StringPool.BLANK;
141 }
142 else {
143 return virtualHost.getHostname();
144 }
145 }
146 catch (Exception e) {
147 return StringPool.BLANK;
148 }
149 }
150
151 public Theme getWapTheme() throws SystemException {
152 return ThemeLocalServiceUtil.getTheme(
153 getCompanyId(), getWapThemeId(), true);
154 }
155
156 public ColorScheme getWapColorScheme() throws SystemException {
157 return ThemeLocalServiceUtil.getColorScheme(
158 getCompanyId(), getWapTheme().getThemeId(), getWapColorSchemeId(),
159 true);
160 }
161
162 @Override
163 public void setSettings(String settings) {
164 _settingsProperties = null;
165
166 super.setSettings(settings);
167 }
168
169 public void setSettingsProperties(UnicodeProperties settingsProperties) {
170 _settingsProperties = settingsProperties;
171
172 super.setSettings(_settingsProperties.toString());
173 }
174
175 private static Log _log = LogFactoryUtil.getLog(LayoutSetImpl.class);
176
177 private UnicodeProperties _settingsProperties;
178
179 }