1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet;
24  
25  import com.liferay.portal.kernel.portlet.LiferayPortletMode;
26  import com.liferay.portal.kernel.portlet.LiferayWindowState;
27  import com.liferay.portal.kernel.util.ReleaseInfo;
28  
29  import java.util.ArrayList;
30  import java.util.Collections;
31  import java.util.Enumeration;
32  import java.util.List;
33  import java.util.Properties;
34  
35  import javax.portlet.PortalContext;
36  import javax.portlet.PortletMode;
37  import javax.portlet.WindowState;
38  
39  /**
40   * <a href="PortalContextImpl.java.html"><b><i>View Source</i></b></a>
41   *
42   * @author Brian Wing Shun Chan
43   *
44   */
45  public class PortalContextImpl implements PortalContext {
46  
47      static Properties props = new Properties();
48      static List<PortletMode> portletModes = new ArrayList<PortletMode>();
49      static List<WindowState> windowStates = new ArrayList<WindowState>();
50  
51      static {
52          portletModes.add(PortletMode.EDIT);
53          portletModes.add(PortletMode.HELP);
54          portletModes.add(PortletMode.VIEW);
55          portletModes.add(LiferayPortletMode.ABOUT);
56          portletModes.add(LiferayPortletMode.CONFIG);
57          portletModes.add(LiferayPortletMode.EDIT_DEFAULTS);
58          portletModes.add(LiferayPortletMode.PREVIEW);
59          portletModes.add(LiferayPortletMode.PRINT);
60  
61          windowStates.add(WindowState.MAXIMIZED);
62          windowStates.add(WindowState.MINIMIZED);
63          windowStates.add(WindowState.NORMAL);
64          windowStates.add(LiferayWindowState.EXCLUSIVE);
65          windowStates.add(LiferayWindowState.POP_UP);
66      }
67  
68      public static boolean isSupportedPortletMode(PortletMode portletMode) {
69          Enumeration<PortletMode> enu = Collections.enumeration(portletModes);
70  
71          while (enu.hasMoreElements()) {
72              PortletMode supported = enu.nextElement();
73  
74              if (supported.equals(portletMode)) {
75                  return true;
76              }
77          }
78  
79          return false;
80      }
81  
82      public static boolean isSupportedWindowState(WindowState windowState) {
83          Enumeration<WindowState> enu = Collections.enumeration(windowStates);
84  
85          while (enu.hasMoreElements()) {
86              WindowState supported = enu.nextElement();
87  
88              if (supported.equals(windowState)) {
89                  return true;
90              }
91          }
92  
93          return false;
94      }
95  
96      public String getPortalInfo() {
97          return ReleaseInfo.getReleaseInfo();
98      }
99  
100     public String getProperty(String name) {
101         return props.getProperty(name);
102     }
103 
104     public Enumeration<String> getPropertyNames() {
105         return (Enumeration<String>)props.propertyNames();
106     }
107 
108     public Enumeration<PortletMode> getSupportedPortletModes() {
109         return Collections.enumeration(portletModes);
110     }
111 
112     public Enumeration<WindowState> getSupportedWindowStates() {
113         return Collections.enumeration(windowStates);
114     }
115 
116 }