001
014
015 package com.liferay.portlet.assetcategoriesnavigation.lar;
016
017 import com.liferay.portal.kernel.lar.DataLevel;
018 import com.liferay.portal.kernel.lar.DefaultConfigurationPortletDataHandler;
019 import com.liferay.portal.kernel.lar.ExportImportHelperUtil;
020 import com.liferay.portal.kernel.lar.PortletDataContext;
021 import com.liferay.portal.model.Company;
022 import com.liferay.portal.model.Group;
023 import com.liferay.portal.model.Portlet;
024 import com.liferay.portal.service.CompanyLocalServiceUtil;
025 import com.liferay.portal.service.PortletLocalServiceUtil;
026 import com.liferay.portlet.asset.model.AssetVocabulary;
027
028 import java.util.Enumeration;
029
030 import javax.portlet.PortletPreferences;
031
032
035 public class AssetCategoriesNavigationPortletDataHandler
036 extends DefaultConfigurationPortletDataHandler {
037
038 public AssetCategoriesNavigationPortletDataHandler() {
039 setDataLevel(DataLevel.PORTLET_INSTANCE);
040 setPublishToLiveByDefault(true);
041 }
042
043 @Override
044 protected PortletPreferences doProcessExportPortletPreferences(
045 PortletDataContext portletDataContext, String portletId,
046 PortletPreferences portletPreferences)
047 throws Exception {
048
049 return updateExportPortletPreferences(
050 portletDataContext, portletPreferences, portletId);
051 }
052
053 @Override
054 protected PortletPreferences doProcessImportPortletPreferences(
055 PortletDataContext portletDataContext, String portletId,
056 PortletPreferences portletPreferences)
057 throws Exception {
058
059 return updateImportPortletPreferences(
060 portletDataContext, portletId, portletPreferences);
061 }
062
063 protected PortletPreferences updateExportPortletPreferences(
064 PortletDataContext portletDataContext,
065 PortletPreferences portletPreferences, String portletId)
066 throws Exception {
067
068 Portlet portlet = PortletLocalServiceUtil.getPortletById(
069 portletDataContext.getCompanyId(), portletId);
070
071 Enumeration<String> enu = portletPreferences.getNames();
072
073 while (enu.hasMoreElements()) {
074 String name = enu.nextElement();
075
076 if (name.equals("assetVocabularyIds")) {
077 ExportImportHelperUtil.updateExportPortletPreferencesClassPKs(
078 portletDataContext, portlet, portletPreferences, name,
079 AssetVocabulary.class.getName());
080 }
081 }
082
083 return portletPreferences;
084 }
085
086 protected PortletPreferences updateImportPortletPreferences(
087 PortletDataContext portletDataContext, String portletId,
088 PortletPreferences portletPreferences)
089 throws Exception {
090
091 Company company = CompanyLocalServiceUtil.getCompanyById(
092 portletDataContext.getCompanyId());
093
094 Group companyGroup = company.getGroup();
095
096 Enumeration<String> enu = portletPreferences.getNames();
097
098 while (enu.hasMoreElements()) {
099 String name = enu.nextElement();
100
101 if (name.equals("assetVocabularyIds")) {
102 ExportImportHelperUtil.updateImportPortletPreferencesClassPKs(
103 portletDataContext, portletPreferences, name,
104 AssetVocabulary.class, companyGroup.getGroupId());
105 }
106 }
107
108 return portletPreferences;
109 }
110
111 }