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.portlet.layoutsadmin.lar;
016    
017    import com.liferay.portal.kernel.lar.BaseStagedModelDataHandler;
018    import com.liferay.portal.kernel.lar.PortletDataContext;
019    import com.liferay.portal.kernel.lar.PortletDataHandlerKeys;
020    import com.liferay.portal.kernel.util.MapUtil;
021    import com.liferay.portal.kernel.xml.Element;
022    import com.liferay.portal.model.Theme;
023    import com.liferay.portal.service.ThemeLocalServiceUtil;
024    
025    import java.util.List;
026    
027    /**
028     * @author Mate Thurzo
029     */
030    public class StagedThemeStagedModelDataHandler
031            extends BaseStagedModelDataHandler<StagedTheme> {
032    
033            public static final String[] CLASS_NAMES = {StagedTheme.class.getName()};
034    
035            @Override
036            public void deleteStagedModel(
037                    String uuid, long groupId, String className, String extraData) {
038            }
039    
040            @Override
041            public String[] getClassNames() {
042                    return CLASS_NAMES;
043            }
044    
045            @Override
046            public String getDisplayName(StagedTheme stagedTheme) {
047                    return stagedTheme.getThemeId();
048            }
049    
050            @Override
051            public boolean validateReference(
052                    PortletDataContext portletDataContext, Element referenceElement) {
053    
054                    boolean importThemeSettings = MapUtil.getBoolean(
055                            portletDataContext.getParameterMap(),
056                            PortletDataHandlerKeys.THEME_REFERENCE);
057    
058                    if (!importThemeSettings) {
059                            return true;
060                    }
061    
062                    String classPK = referenceElement.attributeValue("class-pk");
063    
064                    List<Theme> themes = ThemeLocalServiceUtil.getThemes(
065                            portletDataContext.getCompanyId());
066    
067                    for (Theme theme : themes) {
068                            String themeId = theme.getThemeId();
069    
070                            if (themeId.equals(classPK)) {
071                                    return true;
072                            }
073                    }
074    
075                    return false;
076            }
077    
078            @Override
079            protected void doExportStagedModel(
080                    PortletDataContext portletDataContext, StagedTheme stagedTheme) {
081            }
082    
083            @Override
084            protected void doImportStagedModel(
085                    PortletDataContext portletDataContext, StagedTheme stagedTheme) {
086            }
087    
088    }