001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.portlet;
016    
017    import java.util.HashMap;
018    import java.util.Map;
019    
020    import javax.portlet.PortletMode;
021    
022    /**
023     * @author Brian Wing Shun Chan
024     */
025    public class PortletModeFactory {
026    
027            public static PortletMode getPortletMode(String name) {
028                    return _instance._getPortletMode(name);
029            }
030    
031            private PortletModeFactory() {
032                    _portletModes = new HashMap<String, PortletMode>();
033    
034                    _portletModes.put(_EDIT, LiferayPortletMode.EDIT);
035                    _portletModes.put(_HELP, LiferayPortletMode.HELP);
036                    _portletModes.put(_VIEW, LiferayPortletMode.VIEW);
037                    _portletModes.put(_ABOUT, LiferayPortletMode.ABOUT);
038                    _portletModes.put(_CONFIG, LiferayPortletMode.CONFIG);
039                    _portletModes.put(_EDIT_DEFAULTS, LiferayPortletMode.EDIT_DEFAULTS);
040                    _portletModes.put(_EDIT_GUEST, LiferayPortletMode.EDIT_GUEST);
041                    _portletModes.put(_PREVIEW, LiferayPortletMode.PREVIEW);
042                    _portletModes.put(_PRINT, LiferayPortletMode.PRINT);
043            }
044    
045            private PortletMode _getPortletMode(String name) {
046                    PortletMode portletMode = _portletModes.get(name);
047    
048                    if (portletMode == null) {
049                            portletMode = new PortletMode(name);
050                    }
051    
052                    return portletMode;
053            }
054    
055            private static final String _EDIT = PortletMode.EDIT.toString();
056    
057            private static final String _HELP = PortletMode.HELP.toString();
058    
059            private static final String _VIEW = PortletMode.VIEW.toString();
060    
061            private static final String _ABOUT = LiferayPortletMode.ABOUT.toString();
062    
063            private static final String _CONFIG = LiferayPortletMode.CONFIG.toString();
064    
065            private static final String _EDIT_DEFAULTS =
066                    LiferayPortletMode.EDIT_DEFAULTS.toString();
067    
068            private static final String _EDIT_GUEST =
069                    LiferayPortletMode.EDIT_GUEST.toString();
070    
071            private static final String _PREVIEW =
072                    LiferayPortletMode.PREVIEW.toString();
073    
074            private static final String _PRINT = LiferayPortletMode.PRINT.toString();
075    
076            private static PortletModeFactory _instance = new PortletModeFactory();
077    
078            private Map<String, PortletMode> _portletModes;
079    
080    }