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