001    /**
002     * Copyright (c) 2000-2012 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.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    }