1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.kernel.portlet;
16  
17  import com.liferay.portal.kernel.util.WebKeys;
18  
19  import javax.portlet.WindowState;
20  
21  import javax.servlet.http.HttpServletRequest;
22  
23  /**
24   * <a href="LiferayWindowState.java.html"><b><i>View Source</i></b></a>
25   *
26   * @author Brian Wing Shun Chan
27   * @author Zsolt Balogh
28   */
29  public class LiferayWindowState extends WindowState {
30  
31      public static final WindowState EXCLUSIVE = new WindowState("exclusive");
32  
33      public static final WindowState POP_UP = new WindowState("pop_up");
34  
35      public static boolean isExclusive(HttpServletRequest request) {
36          String state = _getWindowState(request);
37  
38          if ((state != null) && (state.equals(EXCLUSIVE.toString()))) {
39              return true;
40          }
41          else {
42              return false;
43          }
44      }
45  
46      public static boolean isMaximized(HttpServletRequest request) {
47          String state = _getWindowState(request);
48  
49          if ((state != null) &&
50              (state.equals(WindowState.MAXIMIZED.toString()))) {
51  
52              return true;
53          }
54          else {
55              return false;
56          }
57      }
58  
59      public static boolean isPopUp(HttpServletRequest request) {
60          String state = _getWindowState(request);
61  
62          if ((state != null) && (state.equals(POP_UP.toString()))) {
63              return true;
64          }
65          else {
66              return false;
67          }
68      }
69  
70      public static boolean isWindowStatePreserved(
71          WindowState oldWindowState, WindowState newWindowState) {
72  
73          // Changes to EXCLUSIVE are always preserved
74  
75          if ((newWindowState != null) &&
76              (newWindowState.equals(LiferayWindowState.EXCLUSIVE))) {
77  
78              return true;
79          }
80  
81          // Some window states are automatically preserved
82  
83          if ((oldWindowState != null) &&
84              (oldWindowState.equals(LiferayWindowState.POP_UP))) {
85  
86              return false;
87          }
88          else {
89              return true;
90          }
91      }
92  
93      public LiferayWindowState(String name) {
94          super(name);
95      }
96  
97      private static String _getWindowState(HttpServletRequest request) {
98          WindowState windowState = (WindowState)request.getAttribute(
99              WebKeys.WINDOW_STATE);
100 
101         if (windowState != null) {
102             return windowState.toString();
103         }
104 
105         return request.getParameter("p_p_state");
106     }
107 
108 }