001    /**
002     * Copyright (c) 2000-2013 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.kernel.portlet;
016    
017    import com.liferay.portal.kernel.util.WebKeys;
018    
019    import javax.portlet.WindowState;
020    
021    import javax.servlet.http.HttpServletRequest;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     * @author Zsolt Balogh
026     */
027    public class LiferayWindowState extends WindowState {
028    
029            public static final WindowState EXCLUSIVE = new WindowState("exclusive");
030    
031            public static final WindowState POP_UP = new WindowState("pop_up");
032    
033            public static boolean isExclusive(HttpServletRequest request) {
034                    String state = _getWindowState(request);
035    
036                    if ((state != null) && state.equals(EXCLUSIVE.toString())) {
037                            return true;
038                    }
039                    else {
040                            return false;
041                    }
042            }
043    
044            public static boolean isMaximized(HttpServletRequest request) {
045                    String state = _getWindowState(request);
046    
047                    if ((state != null) && state.equals(WindowState.MAXIMIZED.toString())) {
048                            return true;
049                    }
050                    else {
051                            return false;
052                    }
053            }
054    
055            public static boolean isPopUp(HttpServletRequest request) {
056                    String state = _getWindowState(request);
057    
058                    if ((state != null) && state.equals(POP_UP.toString())) {
059                            return true;
060                    }
061                    else {
062                            return false;
063                    }
064            }
065    
066            public static boolean isWindowStatePreserved(
067                    WindowState oldWindowState, WindowState newWindowState) {
068    
069                    // Changes to EXCLUSIVE are always preserved
070    
071                    if ((newWindowState != null) &&
072                            newWindowState.equals(LiferayWindowState.EXCLUSIVE)) {
073    
074                            return true;
075                    }
076    
077                    // Some window states are automatically preserved
078    
079                    if ((oldWindowState != null) &&
080                            oldWindowState.equals(LiferayWindowState.POP_UP)) {
081    
082                            return false;
083                    }
084                    else {
085                            return true;
086                    }
087            }
088    
089            public LiferayWindowState(String name) {
090                    super(name);
091            }
092    
093            private static String _getWindowState(HttpServletRequest request) {
094                    WindowState windowState = (WindowState)request.getAttribute(
095                            WebKeys.WINDOW_STATE);
096    
097                    if (windowState != null) {
098                            return windowState.toString();
099                    }
100    
101                    return request.getParameter("p_p_state");
102            }
103    
104    }