001
014
015 package com.liferay.portlet.exportimport.lar;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.util.GetterUtil;
020 import com.liferay.portal.kernel.util.MapUtil;
021 import com.liferay.portal.kernel.xml.Attribute;
022 import com.liferay.portal.kernel.xml.Element;
023 import com.liferay.portal.model.LayoutSet;
024 import com.liferay.portal.service.LayoutSetLocalServiceUtil;
025
026
029 public class ThemeImporter {
030
031 public static ThemeImporter getInstance() {
032 return _instance;
033 }
034
035 public void importTheme(
036 PortletDataContext portletDataContext, LayoutSet layoutSet)
037 throws Exception {
038
039 boolean importThemeSettings = MapUtil.getBoolean(
040 portletDataContext.getParameterMap(),
041 PortletDataHandlerKeys.THEME_REFERENCE);
042
043 if (_log.isDebugEnabled()) {
044 _log.debug("Import theme settings " + importThemeSettings);
045 }
046
047 if (!importThemeSettings) {
048 return;
049 }
050
051 Element importDataRootElement =
052 portletDataContext.getImportDataRootElement();
053 Element headerElement = importDataRootElement.element("header");
054
055 String themeId = layoutSet.getThemeId();
056 String colorSchemeId = layoutSet.getColorSchemeId();
057
058 Attribute themeIdAttribute = headerElement.attribute("theme-id");
059
060 if (themeIdAttribute != null) {
061 themeId = themeIdAttribute.getValue();
062 }
063
064 Attribute colorSchemeIdAttribute = headerElement.attribute(
065 "color-scheme-id");
066
067 if (colorSchemeIdAttribute != null) {
068 colorSchemeId = colorSchemeIdAttribute.getValue();
069 }
070
071 String css = GetterUtil.getString(headerElement.elementText("css"));
072
073 LayoutSetLocalServiceUtil.updateLookAndFeel(
074 layoutSet.getGroupId(), layoutSet.isPrivateLayout(), themeId,
075 colorSchemeId, css, false);
076 }
077
078 private ThemeImporter() {
079 }
080
081 private static final Log _log = LogFactoryUtil.getLog(ThemeImporter.class);
082
083 private static final ThemeImporter _instance = new ThemeImporter();
084
085 }