001
014
015 package com.liferay.portal.model.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.model.ColorScheme;
019 import com.liferay.portal.kernel.model.Layout;
020 import com.liferay.portal.kernel.model.LayoutBranch;
021 import com.liferay.portal.kernel.model.LayoutRevision;
022 import com.liferay.portal.kernel.model.LayoutSet;
023 import com.liferay.portal.kernel.model.LayoutTypePortletConstants;
024 import com.liferay.portal.kernel.model.Theme;
025 import com.liferay.portal.kernel.service.LayoutBranchLocalServiceUtil;
026 import com.liferay.portal.kernel.service.LayoutLocalServiceUtil;
027 import com.liferay.portal.kernel.service.LayoutRevisionLocalServiceUtil;
028 import com.liferay.portal.kernel.service.LayoutSetLocalServiceUtil;
029 import com.liferay.portal.kernel.service.ThemeLocalServiceUtil;
030 import com.liferay.portal.kernel.theme.ThemeDisplay;
031 import com.liferay.portal.kernel.util.CookieKeys;
032 import com.liferay.portal.kernel.util.LocaleUtil;
033 import com.liferay.portal.kernel.util.PortalUtil;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.UnicodeProperties;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.kernel.util.WebKeys;
038
039 import java.util.List;
040 import java.util.Locale;
041
042 import javax.servlet.http.HttpServletRequest;
043
044
047 public class LayoutRevisionImpl extends LayoutRevisionBaseImpl {
048
049 @Override
050 public List<LayoutRevision> getChildren() {
051 return LayoutRevisionLocalServiceUtil.getChildLayoutRevisions(
052 getLayoutSetBranchId(), getLayoutRevisionId(), getPlid());
053 }
054
055 @Override
056 public ColorScheme getColorScheme() throws PortalException {
057 if (isInheritLookAndFeel()) {
058 return getLayoutSet().getColorScheme();
059 }
060 else {
061 return ThemeLocalServiceUtil.getColorScheme(
062 getCompanyId(), getTheme().getThemeId(), getColorSchemeId());
063 }
064 }
065
066 @Override
067 public String getCssText() throws PortalException {
068 if (isInheritLookAndFeel()) {
069 return getLayoutSet().getCss();
070 }
071 else {
072 return getCss();
073 }
074 }
075
076 @Override
077 public String getHTMLTitle(Locale locale) {
078 String localeLanguageId = LocaleUtil.toLanguageId(locale);
079
080 return getHTMLTitle(localeLanguageId);
081 }
082
083 @Override
084 public String getHTMLTitle(String localeLanguageId) {
085 String htmlTitle = getTitle(localeLanguageId);
086
087 if (Validator.isNull(htmlTitle)) {
088 htmlTitle = getName(localeLanguageId);
089 }
090
091 return htmlTitle;
092 }
093
094 @Override
095 public boolean getIconImage() {
096 if (getIconImageId() > 0) {
097 return true;
098 }
099
100 return false;
101 }
102
103 @Override
104 public LayoutBranch getLayoutBranch() throws PortalException {
105 return LayoutBranchLocalServiceUtil.getLayoutBranch(
106 getLayoutBranchId());
107 }
108
109 @Override
110 public LayoutSet getLayoutSet() throws PortalException {
111 return LayoutSetLocalServiceUtil.getLayoutSet(
112 getGroupId(), isPrivateLayout());
113 }
114
115 @Override
116 public String getRegularURL(HttpServletRequest request)
117 throws PortalException {
118
119 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
120 WebKeys.THEME_DISPLAY);
121
122 String portalURL = PortalUtil.getPortalURL(request);
123
124 Layout layout = LayoutLocalServiceUtil.getLayout(getPlid());
125
126 String url = PortalUtil.getLayoutURL(layout, themeDisplay);
127
128 if (!CookieKeys.hasSessionId(request) &&
129 (url.startsWith(portalURL) || url.startsWith(StringPool.SLASH))) {
130
131 url = PortalUtil.getURLWithSessionId(
132 url, request.getSession().getId());
133 }
134
135 return url;
136 }
137
138 @Override
139 public Theme getTheme() throws PortalException {
140 if (isInheritLookAndFeel()) {
141 return getLayoutSet().getTheme();
142 }
143 else {
144 return ThemeLocalServiceUtil.getTheme(getCompanyId(), getThemeId());
145 }
146 }
147
148 @Override
149 public String getThemeSetting(String key, String device) {
150 UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();
151
152 String value = typeSettingsProperties.getProperty(
153 ThemeSettingImpl.namespaceProperty(device, key));
154
155 if (value != null) {
156 return value;
157 }
158
159 if (!isInheritLookAndFeel()) {
160 try {
161 Theme theme = getTheme();
162
163 return theme.getSetting(key);
164 }
165 catch (Exception e) {
166 }
167 }
168
169 try {
170 LayoutSet layoutSet = getLayoutSet();
171
172 value = layoutSet.getThemeSetting(key, device);
173 }
174 catch (Exception e) {
175 }
176
177 return value;
178 }
179
180 @Override
181 public String getTypeSettings() {
182 if (_typeSettingsProperties == null) {
183 return super.getTypeSettings();
184 }
185 else {
186 return _typeSettingsProperties.toString();
187 }
188 }
189
190 @Override
191 public UnicodeProperties getTypeSettingsProperties() {
192 if (_typeSettingsProperties == null) {
193 _typeSettingsProperties = new UnicodeProperties(true);
194
195 _typeSettingsProperties.fastLoad(super.getTypeSettings());
196 }
197
198 return _typeSettingsProperties;
199 }
200
201 @Override
202 public String getTypeSettingsProperty(String key) {
203 UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();
204
205 return typeSettingsProperties.getProperty(key);
206 }
207
208 @Override
209 public String getTypeSettingsProperty(String key, String defaultValue) {
210 UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();
211
212 return typeSettingsProperties.getProperty(key, defaultValue);
213 }
214
215 @Override
216 public boolean hasChildren() {
217 if (!getChildren().isEmpty()) {
218 return true;
219 }
220
221 return false;
222 }
223
224 @Override
225 public boolean isContentDisplayPage() {
226 UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();
227
228 String defaultAssetPublisherPortletId =
229 typeSettingsProperties.getProperty(
230 LayoutTypePortletConstants.DEFAULT_ASSET_PUBLISHER_PORTLET_ID);
231
232 if (Validator.isNotNull(defaultAssetPublisherPortletId)) {
233 return true;
234 }
235 else {
236 return false;
237 }
238 }
239
240 @Override
241 public boolean isIconImage() {
242 return getIconImage();
243 }
244
245 @Override
246 public boolean isInheritLookAndFeel() {
247 if (Validator.isNull(getThemeId()) ||
248 Validator.isNull(getColorSchemeId())) {
249
250 return true;
251 }
252 else {
253 return false;
254 }
255 }
256
257 @Override
258 public void setTypeSettings(String typeSettings) {
259 _typeSettingsProperties = null;
260
261 super.setTypeSettings(typeSettings);
262 }
263
264 @Override
265 public void setTypeSettingsProperties(
266 UnicodeProperties typeSettingsProperties) {
267
268 _typeSettingsProperties = typeSettingsProperties;
269
270 super.setTypeSettings(_typeSettingsProperties.toString());
271 }
272
273 private UnicodeProperties _typeSettingsProperties;
274
275 }