/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.portal.model.impl; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.model.ColorScheme; import com.liferay.portal.kernel.model.Layout; import com.liferay.portal.kernel.model.LayoutBranch; import com.liferay.portal.kernel.model.LayoutRevision; import com.liferay.portal.kernel.model.LayoutSet; import com.liferay.portal.kernel.model.LayoutTypePortletConstants; import com.liferay.portal.kernel.model.Theme; import com.liferay.portal.kernel.service.LayoutBranchLocalServiceUtil; import com.liferay.portal.kernel.service.LayoutLocalServiceUtil; import com.liferay.portal.kernel.service.LayoutRevisionLocalServiceUtil; import com.liferay.portal.kernel.service.LayoutSetLocalServiceUtil; import com.liferay.portal.kernel.service.ThemeLocalServiceUtil; import com.liferay.portal.kernel.theme.ThemeDisplay; import com.liferay.portal.kernel.util.CookieKeys; import com.liferay.portal.kernel.util.LocaleUtil; import com.liferay.portal.kernel.util.PortalUtil; import com.liferay.portal.kernel.util.StringPool; import com.liferay.portal.kernel.util.UnicodeProperties; import com.liferay.portal.kernel.util.Validator; import com.liferay.portal.kernel.util.WebKeys; import java.util.List; import java.util.Locale; import javax.servlet.http.HttpServletRequest; /** * @author Brian Wing Shun Chan */ public class LayoutRevisionImpl extends LayoutRevisionBaseImpl { @Override public List<LayoutRevision> getChildren() { return LayoutRevisionLocalServiceUtil.getChildLayoutRevisions( getLayoutSetBranchId(), getLayoutRevisionId(), getPlid()); } @Override public ColorScheme getColorScheme() throws PortalException { if (isInheritLookAndFeel()) { return getLayoutSet().getColorScheme(); } else { return ThemeLocalServiceUtil.getColorScheme( getCompanyId(), getTheme().getThemeId(), getColorSchemeId()); } } @Override public String getCssText() throws PortalException { if (isInheritLookAndFeel()) { return getLayoutSet().getCss(); } else { return getCss(); } } @Override public String getHTMLTitle(Locale locale) { String localeLanguageId = LocaleUtil.toLanguageId(locale); return getHTMLTitle(localeLanguageId); } @Override public String getHTMLTitle(String localeLanguageId) { String htmlTitle = getTitle(localeLanguageId); if (Validator.isNull(htmlTitle)) { htmlTitle = getName(localeLanguageId); } return htmlTitle; } @Override public boolean getIconImage() { if (getIconImageId() > 0) { return true; } return false; } @Override public LayoutBranch getLayoutBranch() throws PortalException { return LayoutBranchLocalServiceUtil.getLayoutBranch( getLayoutBranchId()); } @Override public LayoutSet getLayoutSet() throws PortalException { return LayoutSetLocalServiceUtil.getLayoutSet( getGroupId(), isPrivateLayout()); } @Override public String getRegularURL(HttpServletRequest request) throws PortalException { ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute( WebKeys.THEME_DISPLAY); String portalURL = PortalUtil.getPortalURL(request); Layout layout = LayoutLocalServiceUtil.getLayout(getPlid()); String url = PortalUtil.getLayoutURL(layout, themeDisplay); if (!CookieKeys.hasSessionId(request) && (url.startsWith(portalURL) || url.startsWith(StringPool.SLASH))) { url = PortalUtil.getURLWithSessionId( url, request.getSession().getId()); } return url; } @Override public Theme getTheme() throws PortalException { if (isInheritLookAndFeel()) { return getLayoutSet().getTheme(); } else { return ThemeLocalServiceUtil.getTheme(getCompanyId(), getThemeId()); } } @Override public String getThemeSetting(String key, String device) { UnicodeProperties typeSettingsProperties = getTypeSettingsProperties(); String value = typeSettingsProperties.getProperty( ThemeSettingImpl.namespaceProperty(device, key)); if (value != null) { return value; } if (!isInheritLookAndFeel()) { try { Theme theme = getTheme(); return theme.getSetting(key); } catch (Exception e) { } } try { LayoutSet layoutSet = getLayoutSet(); value = layoutSet.getThemeSetting(key, device); } catch (Exception e) { } return value; } @Override public String getTypeSettings() { if (_typeSettingsProperties == null) { return super.getTypeSettings(); } else { return _typeSettingsProperties.toString(); } } @Override public UnicodeProperties getTypeSettingsProperties() { if (_typeSettingsProperties == null) { _typeSettingsProperties = new UnicodeProperties(true); _typeSettingsProperties.fastLoad(super.getTypeSettings()); } return _typeSettingsProperties; } @Override public String getTypeSettingsProperty(String key) { UnicodeProperties typeSettingsProperties = getTypeSettingsProperties(); return typeSettingsProperties.getProperty(key); } @Override public String getTypeSettingsProperty(String key, String defaultValue) { UnicodeProperties typeSettingsProperties = getTypeSettingsProperties(); return typeSettingsProperties.getProperty(key, defaultValue); } @Override public boolean hasChildren() { if (!getChildren().isEmpty()) { return true; } return false; } @Override public boolean isContentDisplayPage() { UnicodeProperties typeSettingsProperties = getTypeSettingsProperties(); String defaultAssetPublisherPortletId = typeSettingsProperties.getProperty( LayoutTypePortletConstants.DEFAULT_ASSET_PUBLISHER_PORTLET_ID); if (Validator.isNotNull(defaultAssetPublisherPortletId)) { return true; } else { return false; } } @Override public boolean isIconImage() { return getIconImage(); } @Override public boolean isInheritLookAndFeel() { if (Validator.isNull(getThemeId()) || Validator.isNull(getColorSchemeId())) { return true; } else { return false; } } @Override public void setTypeSettings(String typeSettings) { _typeSettingsProperties = null; super.setTypeSettings(typeSettings); } @Override public void setTypeSettingsProperties( UnicodeProperties typeSettingsProperties) { _typeSettingsProperties = typeSettingsProperties; super.setTypeSettings(_typeSettingsProperties.toString()); } private UnicodeProperties _typeSettingsProperties; }