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