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