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.portlet;
16  
17  import com.liferay.portal.kernel.portlet.LiferayPortletMode;
18  import com.liferay.portal.kernel.portlet.LiferayWindowState;
19  import com.liferay.portal.kernel.util.ReleaseInfo;
20  
21  import java.util.ArrayList;
22  import java.util.Collections;
23  import java.util.Enumeration;
24  import java.util.List;
25  import java.util.Properties;
26  
27  import javax.portlet.PortalContext;
28  import javax.portlet.PortletMode;
29  import javax.portlet.WindowState;
30  
31  /**
32   * <a href="PortalContextImpl.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   */
36  public class PortalContextImpl implements PortalContext {
37  
38      static Properties props = new Properties();
39      static List<PortletMode> portletModes = new ArrayList<PortletMode>();
40      static List<WindowState> windowStates = new ArrayList<WindowState>();
41  
42      static {
43          portletModes.add(PortletMode.EDIT);
44          portletModes.add(PortletMode.HELP);
45          portletModes.add(PortletMode.VIEW);
46          portletModes.add(LiferayPortletMode.ABOUT);
47          portletModes.add(LiferayPortletMode.CONFIG);
48          portletModes.add(LiferayPortletMode.EDIT_DEFAULTS);
49          portletModes.add(LiferayPortletMode.PREVIEW);
50          portletModes.add(LiferayPortletMode.PRINT);
51  
52          windowStates.add(WindowState.MAXIMIZED);
53          windowStates.add(WindowState.MINIMIZED);
54          windowStates.add(WindowState.NORMAL);
55          windowStates.add(LiferayWindowState.EXCLUSIVE);
56          windowStates.add(LiferayWindowState.POP_UP);
57      }
58  
59      public static boolean isSupportedPortletMode(PortletMode portletMode) {
60          Enumeration<PortletMode> enu = Collections.enumeration(portletModes);
61  
62          while (enu.hasMoreElements()) {
63              PortletMode supported = enu.nextElement();
64  
65              if (supported.equals(portletMode)) {
66                  return true;
67              }
68          }
69  
70          return false;
71      }
72  
73      public static boolean isSupportedWindowState(WindowState windowState) {
74          Enumeration<WindowState> enu = Collections.enumeration(windowStates);
75  
76          while (enu.hasMoreElements()) {
77              WindowState supported = enu.nextElement();
78  
79              if (supported.equals(windowState)) {
80                  return true;
81              }
82          }
83  
84          return false;
85      }
86  
87      public String getPortalInfo() {
88          return ReleaseInfo.getReleaseInfo();
89      }
90  
91      public String getProperty(String name) {
92          return props.getProperty(name);
93      }
94  
95      public Enumeration<String> getPropertyNames() {
96          return (Enumeration<String>)props.propertyNames();
97      }
98  
99      public Enumeration<PortletMode> getSupportedPortletModes() {
100         return Collections.enumeration(portletModes);
101     }
102 
103     public Enumeration<WindowState> getSupportedWindowStates() {
104         return Collections.enumeration(windowStates);
105     }
106 
107 }