001    /**
002     * Copyright (c) 2000-2013 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 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    }