001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet;
016    
017    import com.liferay.portal.kernel.portlet.LiferayPortletMode;
018    import com.liferay.portal.kernel.portlet.LiferayWindowState;
019    import com.liferay.portal.kernel.util.ReleaseInfo;
020    
021    import java.util.ArrayList;
022    import java.util.Collections;
023    import java.util.Enumeration;
024    import java.util.List;
025    import java.util.Properties;
026    
027    import javax.portlet.PortalContext;
028    import javax.portlet.PortletMode;
029    import javax.portlet.WindowState;
030    
031    /**
032     * @author Brian Wing Shun Chan
033     */
034    public class PortalContextImpl implements PortalContext {
035    
036            static Properties properties = new Properties();
037            static List<PortletMode> portletModes = new ArrayList<PortletMode>();
038            static List<WindowState> windowStates = new ArrayList<WindowState>();
039    
040            static {
041                    properties.setProperty(
042                            MARKUP_HEAD_ELEMENT_SUPPORT, Boolean.TRUE.toString());
043    
044                    portletModes.add(PortletMode.EDIT);
045                    portletModes.add(PortletMode.HELP);
046                    portletModes.add(PortletMode.VIEW);
047                    portletModes.add(LiferayPortletMode.ABOUT);
048                    portletModes.add(LiferayPortletMode.CONFIG);
049                    portletModes.add(LiferayPortletMode.EDIT_DEFAULTS);
050                    portletModes.add(LiferayPortletMode.PREVIEW);
051                    portletModes.add(LiferayPortletMode.PRINT);
052    
053                    windowStates.add(WindowState.MAXIMIZED);
054                    windowStates.add(WindowState.MINIMIZED);
055                    windowStates.add(WindowState.NORMAL);
056                    windowStates.add(LiferayWindowState.EXCLUSIVE);
057                    windowStates.add(LiferayWindowState.POP_UP);
058            }
059    
060            public static boolean isSupportedPortletMode(PortletMode portletMode) {
061                    Enumeration<PortletMode> enu = Collections.enumeration(portletModes);
062    
063                    while (enu.hasMoreElements()) {
064                            PortletMode supported = enu.nextElement();
065    
066                            if (supported.equals(portletMode)) {
067                                    return true;
068                            }
069                    }
070    
071                    return false;
072            }
073    
074            public static boolean isSupportedWindowState(WindowState windowState) {
075                    Enumeration<WindowState> enu = Collections.enumeration(windowStates);
076    
077                    while (enu.hasMoreElements()) {
078                            WindowState supported = enu.nextElement();
079    
080                            if (supported.equals(windowState)) {
081                                    return true;
082                            }
083                    }
084    
085                    return false;
086            }
087    
088            public String getPortalInfo() {
089                    return ReleaseInfo.getReleaseInfo();
090            }
091    
092            public String getProperty(String name) {
093                    return properties.getProperty(name);
094            }
095    
096            public Enumeration<String> getPropertyNames() {
097                    return (Enumeration<String>)properties.propertyNames();
098            }
099    
100            public Enumeration<PortletMode> getSupportedPortletModes() {
101                    return Collections.enumeration(portletModes);
102            }
103    
104            public Enumeration<WindowState> getSupportedWindowStates() {
105                    return Collections.enumeration(windowStates);
106            }
107    
108    }