001    /**
002     * Copyright (c) 2000-2012 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.LayoutTypePortlet;
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                    if (layout.isTypePortlet()) {
058                            LayoutTypePortlet layoutTypePortlet =
059                                    (LayoutTypePortlet)layout.getLayoutType();
060    
061                            layoutTypePortlet.setLayoutTemplateId(0, layoutTemplateId, false);
062                    }
063            }
064    
065            public Collection<String> getPropertyNames() {
066                    return _propertyNames;
067            }
068    
069            public String getType() {
070                    return getHandlerType();
071            }
072    
073            private static Collection<String> _propertyNames;
074    
075            static {
076                    _propertyNames = new ArrayList<String>(1);
077    
078                    _propertyNames.add("layoutTemplateId");
079    
080                    _propertyNames = Collections.unmodifiableCollection(_propertyNames);
081            }
082    
083    }