1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.kernel.portlet;
16  
17  import javax.portlet.WindowState;
18  
19  import javax.servlet.http.HttpServletRequest;
20  
21  /**
22   * <a href="LiferayWindowState.java.html"><b><i>View Source</i></b></a>
23   *
24   * @author Brian Wing Shun Chan
25   */
26  public class LiferayWindowState extends WindowState {
27  
28      public final static WindowState EXCLUSIVE = new WindowState("exclusive");
29  
30      public final static WindowState POP_UP = new WindowState("pop_up");
31  
32      public static boolean isExclusive(HttpServletRequest request) {
33          String state = request.getParameter("p_p_state");
34  
35          if ((state != null) && (state.equals(EXCLUSIVE.toString()))) {
36              return true;
37          }
38          else {
39              return false;
40          }
41      }
42  
43      public static boolean isMaximized(HttpServletRequest request) {
44          String state = request.getParameter("p_p_state");
45  
46          if ((state != null) &&
47              (state.equals(WindowState.MAXIMIZED.toString()))) {
48  
49              return true;
50          }
51          else {
52              return false;
53          }
54      }
55  
56      public static boolean isPopUp(HttpServletRequest request) {
57          String state = request.getParameter("p_p_state");
58  
59          if ((state != null) && (state.equals(POP_UP.toString()))) {
60              return true;
61          }
62          else {
63              return false;
64          }
65      }
66  
67      public static boolean isWindowStatePreserved(
68          WindowState oldWindowState, WindowState newWindowState) {
69  
70          // Changes to EXCLUSIVE are always preserved
71  
72          if ((newWindowState != null) &&
73              (newWindowState.equals(LiferayWindowState.EXCLUSIVE))) {
74  
75              return true;
76          }
77  
78          // Some window states are automatically preserved
79  
80          if ((oldWindowState != null) &&
81              (oldWindowState.equals(LiferayWindowState.POP_UP))) {
82  
83              return false;
84          }
85          else {
86              return true;
87          }
88      }
89  
90      public LiferayWindowState(String name) {
91          super(name);
92      }
93  
94  }