1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet;
21  
22  import com.liferay.portal.kernel.portlet.LiferayPortletMode;
23  import com.liferay.portal.kernel.portlet.LiferayWindowState;
24  import com.liferay.portal.kernel.util.ReleaseInfo;
25  
26  import java.util.ArrayList;
27  import java.util.Collections;
28  import java.util.Enumeration;
29  import java.util.List;
30  import java.util.Properties;
31  
32  import javax.portlet.PortalContext;
33  import javax.portlet.PortletMode;
34  import javax.portlet.WindowState;
35  
36  /**
37   * <a href="PortalContextImpl.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   *
41   */
42  public class PortalContextImpl implements PortalContext {
43  
44      static Properties props = new Properties();
45      static List<PortletMode> portletModes = new ArrayList<PortletMode>();
46      static List<WindowState> windowStates = new ArrayList<WindowState>();
47  
48      static {
49          portletModes.add(PortletMode.EDIT);
50          portletModes.add(PortletMode.HELP);
51          portletModes.add(PortletMode.VIEW);
52          portletModes.add(LiferayPortletMode.ABOUT);
53          portletModes.add(LiferayPortletMode.CONFIG);
54          portletModes.add(LiferayPortletMode.EDIT_DEFAULTS);
55          portletModes.add(LiferayPortletMode.PREVIEW);
56          portletModes.add(LiferayPortletMode.PRINT);
57  
58          windowStates.add(WindowState.MAXIMIZED);
59          windowStates.add(WindowState.MINIMIZED);
60          windowStates.add(WindowState.NORMAL);
61          windowStates.add(LiferayWindowState.EXCLUSIVE);
62          windowStates.add(LiferayWindowState.POP_UP);
63      }
64  
65      public static boolean isSupportedPortletMode(PortletMode portletMode) {
66          Enumeration<PortletMode> enu = Collections.enumeration(portletModes);
67  
68          while (enu.hasMoreElements()) {
69              PortletMode supported = enu.nextElement();
70  
71              if (supported.equals(portletMode)) {
72                  return true;
73              }
74          }
75  
76          return false;
77      }
78  
79      public static boolean isSupportedWindowState(WindowState windowState) {
80          Enumeration<WindowState> enu = Collections.enumeration(windowStates);
81  
82          while (enu.hasMoreElements()) {
83              WindowState supported = enu.nextElement();
84  
85              if (supported.equals(windowState)) {
86                  return true;
87              }
88          }
89  
90          return false;
91      }
92  
93      public String getPortalInfo() {
94          return ReleaseInfo.getReleaseInfo();
95      }
96  
97      public String getProperty(String name) {
98          return props.getProperty(name);
99      }
100 
101     public Enumeration<String> getPropertyNames() {
102         return (Enumeration<String>)props.propertyNames();
103     }
104 
105     public Enumeration<PortletMode> getSupportedPortletModes() {
106         return Collections.enumeration(portletModes);
107     }
108 
109     public Enumeration<WindowState> getSupportedWindowStates() {
110         return Collections.enumeration(windowStates);
111     }
112 
113 }