001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    }