001    /**
002     * Copyright (c) 2000-2011 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.mobile.device.rulegroup.action.impl;
016    
017    import com.liferay.portal.kernel.mobile.device.rulegroup.action.ActionHandler;
018    import com.liferay.portal.kernel.util.GetterUtil;
019    import com.liferay.portal.kernel.util.UnicodeProperties;
020    import com.liferay.portal.model.Layout;
021    import com.liferay.portal.model.LayoutTypePortletConstants;
022    import com.liferay.portal.theme.ThemeDisplay;
023    import com.liferay.portal.util.WebKeys;
024    import com.liferay.portlet.mobiledevicerules.model.MDRAction;
025    
026    import java.util.ArrayList;
027    import java.util.Collection;
028    import java.util.Collections;
029    
030    import javax.servlet.http.HttpServletRequest;
031    import javax.servlet.http.HttpServletResponse;
032    
033    /**
034     * @author Edward Han
035     */
036    public class LayoutTemplateModificationActionHandler implements ActionHandler {
037    
038            public static String getHandlerType() {
039                    return LayoutTemplateModificationActionHandler.class.getName();
040            }
041    
042            public void applyAction(
043                    MDRAction mdrAction, HttpServletRequest request,
044                    HttpServletResponse response) {
045    
046                    UnicodeProperties mdrActionTypeSettingsProperties =
047                            mdrAction.getTypeSettingsProperties();
048    
049                    String layoutTemplateId = GetterUtil.getString(
050                            mdrActionTypeSettingsProperties.getProperty("layoutTemplateId"));
051    
052                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
053                            WebKeys.THEME_DISPLAY);
054    
055                    Layout layout = themeDisplay.getLayout();
056    
057                    UnicodeProperties layoutTypeSettingsProperties =
058                            layout.getTypeSettingsProperties();
059    
060                    layoutTypeSettingsProperties.setProperty(
061                            LayoutTypePortletConstants.LAYOUT_TEMPLATE_ID, layoutTemplateId);
062    
063                    layout.setTypeSettingsProperties(layoutTypeSettingsProperties);
064            }
065    
066            public Collection<String> getPropertyNames() {
067                    return _propertyNames;
068            }
069    
070            public String getType() {
071                    return getHandlerType();
072            }
073    
074            private static Collection<String> _propertyNames;
075    
076            static {
077                    _propertyNames = new ArrayList<String>(1);
078    
079                    _propertyNames.add("layoutTemplateId");
080    
081                    _propertyNames = Collections.unmodifiableCollection(_propertyNames);
082            }
083    
084    }