001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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    /**
029     * @author Mate Thurzo
030     */
031    public class ThemeImporter {
032    
033            public static ThemeImporter getInstance() {
034                    return _instance;
035            }
036    
037            public void importTheme(
038                            PortletDataContext portletDataContext, LayoutSet layoutSet)
039                    throws Exception {
040    
041                    boolean importThemeSettings = MapUtil.getBoolean(
042                            portletDataContext.getParameterMap(),
043                            PortletDataHandlerKeys.THEME_REFERENCE);
044    
045                    if (_log.isDebugEnabled()) {
046                            _log.debug("Import theme settings " + importThemeSettings);
047                    }
048    
049                    if (!importThemeSettings) {
050                            return;
051                    }
052    
053                    Element importDataRootElement =
054                            portletDataContext.getImportDataRootElement();
055                    Element headerElement = importDataRootElement.element("header");
056    
057                    String themeId = layoutSet.getThemeId();
058                    String colorSchemeId = layoutSet.getColorSchemeId();
059    
060                    Attribute themeIdAttribute = headerElement.attribute("theme-id");
061    
062                    if (themeIdAttribute != null) {
063                            themeId = themeIdAttribute.getValue();
064                    }
065    
066                    Attribute colorSchemeIdAttribute = headerElement.attribute(
067                            "color-scheme-id");
068    
069                    if (colorSchemeIdAttribute != null) {
070                            colorSchemeId = colorSchemeIdAttribute.getValue();
071                    }
072    
073                    String css = GetterUtil.getString(headerElement.elementText("css"));
074    
075                    LayoutSetLocalServiceUtil.updateLookAndFeel(
076                            layoutSet.getGroupId(), layoutSet.isPrivateLayout(), themeId,
077                            colorSchemeId, css, false);
078            }
079    
080            private ThemeImporter() {
081            }
082    
083            private static final Log _log = LogFactoryUtil.getLog(ThemeImporter.class);
084    
085            private static final ThemeImporter _instance = new ThemeImporter();
086    
087    }