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.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 StagedTheme fetchStagedModelByUuidAndCompanyId(
042                    String uuid, long companyId) {
043    
044                    return null;
045            }
046    
047            @Override
048            public String[] getClassNames() {
049                    return CLASS_NAMES;
050            }
051    
052            @Override
053            public String getDisplayName(StagedTheme stagedTheme) {
054                    return stagedTheme.getThemeId();
055            }
056    
057            @Override
058            public boolean validateReference(
059                    PortletDataContext portletDataContext, Element referenceElement) {
060    
061                    boolean importThemeSettings = MapUtil.getBoolean(
062                            portletDataContext.getParameterMap(),
063                            PortletDataHandlerKeys.THEME_REFERENCE);
064    
065                    if (!importThemeSettings) {
066                            return true;
067                    }
068    
069                    String classPK = referenceElement.attributeValue("class-pk");
070    
071                    List<Theme> themes = ThemeLocalServiceUtil.getThemes(
072                            portletDataContext.getCompanyId());
073    
074                    for (Theme theme : themes) {
075                            String themeId = theme.getThemeId();
076    
077                            if (themeId.equals(classPK)) {
078                                    return true;
079                            }
080                    }
081    
082                    return false;
083            }
084    
085            @Override
086            protected void doExportStagedModel(
087                    PortletDataContext portletDataContext, StagedTheme stagedTheme) {
088            }
089    
090            @Override
091            protected void doImportStagedModel(
092                    PortletDataContext portletDataContext, StagedTheme stagedTheme) {
093            }
094    
095    }