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