001    /**
002     * Copyright (c) 2000-2010 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) &&
048                            (state.equals(WindowState.MAXIMIZED.toString()))) {
049    
050                            return true;
051                    }
052                    else {
053                            return false;
054                    }
055            }
056    
057            public static boolean isPopUp(HttpServletRequest request) {
058                    String state = _getWindowState(request);
059    
060                    if ((state != null) && (state.equals(POP_UP.toString()))) {
061                            return true;
062                    }
063                    else {
064                            return false;
065                    }
066            }
067    
068            public static boolean isWindowStatePreserved(
069                    WindowState oldWindowState, WindowState newWindowState) {
070    
071                    // Changes to EXCLUSIVE are always preserved
072    
073                    if ((newWindowState != null) &&
074                            (newWindowState.equals(LiferayWindowState.EXCLUSIVE))) {
075    
076                            return true;
077                    }
078    
079                    // Some window states are automatically preserved
080    
081                    if ((oldWindowState != null) &&
082                            (oldWindowState.equals(LiferayWindowState.POP_UP))) {
083    
084                            return false;
085                    }
086                    else {
087                            return true;
088                    }
089            }
090    
091            public LiferayWindowState(String name) {
092                    super(name);
093            }
094    
095            private static String _getWindowState(HttpServletRequest request) {
096                    WindowState windowState = (WindowState)request.getAttribute(
097                            WebKeys.WINDOW_STATE);
098    
099                    if (windowState != null) {
100                            return windowState.toString();
101                    }
102    
103                    return request.getParameter("p_p_state");
104            }
105    
106    }