001
014
015 package com.liferay.portal.kernel.settings;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.model.Group;
019 import com.liferay.portal.model.Layout;
020 import com.liferay.portal.service.GroupLocalServiceUtil;
021
022
026 public class PortletInstanceSettingsLocator implements SettingsLocator {
027
028 public PortletInstanceSettingsLocator(Layout layout, String portletId) {
029 _layout = layout;
030 _portletId = portletId;
031 }
032
033 @Override
034 public Settings getSettings() throws SettingsException {
035 long companyId = getCompanyId(_layout.getGroupId());
036
037 Settings portalPropertiesSettings =
038 _settingsLocatorHelper.getPortalPropertiesSettings();
039
040 Settings configurationBeanSettings =
041 _settingsLocatorHelper.getConfigurationBeanSettings(
042 _portletId, portalPropertiesSettings);
043
044 Settings portalPreferencesSettings =
045 _settingsLocatorHelper.getPortalPreferencesSettings(
046 companyId, configurationBeanSettings);
047
048 Settings companyPortletPreferencesSettings =
049 _settingsLocatorHelper.getCompanyPortletPreferencesSettings(
050 companyId, _portletId, portalPreferencesSettings);
051
052 Settings groupPortletPreferencesSettings =
053 _settingsLocatorHelper.getGroupPortletPreferencesSettings(
054 _layout.getGroupId(), _portletId,
055 companyPortletPreferencesSettings);
056
057 return
058 _settingsLocatorHelper.getPortletInstancePortletPreferencesSettings(
059 _layout, _portletId, groupPortletPreferencesSettings);
060 }
061
062 @Override
063 public String getSettingsId() {
064 return _portletId;
065 }
066
067 protected long getCompanyId(long groupId) throws SettingsException {
068 try {
069 Group group = GroupLocalServiceUtil.getGroup(groupId);
070
071 return group.getCompanyId();
072 }
073 catch (PortalException pe) {
074 throw new SettingsException(pe);
075 }
076 }
077
078 private final Layout _layout;
079 private final String _portletId;
080 private final SettingsLocatorHelper _settingsLocatorHelper =
081 SettingsLocatorHelperUtil.getSettingsLocatorHelper();
082
083 }