1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  public class PortalContextImpl implements PortalContext {
45  
46      static Properties props = new Properties();
47      static List<PortletMode> portletModes = new ArrayList<PortletMode>();
48      static List<WindowState> windowStates = new ArrayList<WindowState>();
49  
50      static {
51          portletModes.add(PortletMode.EDIT);
52          portletModes.add(PortletMode.HELP);
53          portletModes.add(PortletMode.VIEW);
54          portletModes.add(LiferayPortletMode.ABOUT);
55          portletModes.add(LiferayPortletMode.CONFIG);
56          portletModes.add(LiferayPortletMode.EDIT_DEFAULTS);
57          portletModes.add(LiferayPortletMode.PREVIEW);
58          portletModes.add(LiferayPortletMode.PRINT);
59  
60          windowStates.add(WindowState.MAXIMIZED);
61          windowStates.add(WindowState.MINIMIZED);
62          windowStates.add(WindowState.NORMAL);
63          windowStates.add(LiferayWindowState.EXCLUSIVE);
64          windowStates.add(LiferayWindowState.POP_UP);
65      }
66  
67      public static boolean isSupportedPortletMode(PortletMode portletMode) {
68          Enumeration<PortletMode> enu = Collections.enumeration(portletModes);
69  
70          while (enu.hasMoreElements()) {
71              PortletMode supported = enu.nextElement();
72  
73              if (supported.equals(portletMode)) {
74                  return true;
75              }
76          }
77  
78          return false;
79      }
80  
81      public static boolean isSupportedWindowState(WindowState windowState) {
82          Enumeration<WindowState> enu = Collections.enumeration(windowStates);
83  
84          while (enu.hasMoreElements()) {
85              WindowState supported = enu.nextElement();
86  
87              if (supported.equals(windowState)) {
88                  return true;
89              }
90          }
91  
92          return false;
93      }
94  
95      public String getPortalInfo() {
96          return ReleaseInfo.getReleaseInfo();
97      }
98  
99      public String getProperty(String name) {
100         return props.getProperty(name);
101     }
102 
103     public Enumeration<String> getPropertyNames() {
104         return (Enumeration<String>)props.propertyNames();
105     }
106 
107     public Enumeration<PortletMode> getSupportedPortletModes() {
108         return Collections.enumeration(portletModes);
109     }
110 
111     public Enumeration<WindowState> getSupportedWindowStates() {
112         return Collections.enumeration(windowStates);
113     }
114 
115 }