001    /**
002     * Copyright (c) 2000-2013 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.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 _ABOUT = LiferayPortletMode.ABOUT.toString();
056    
057            private static final String _CONFIG = LiferayPortletMode.CONFIG.toString();
058    
059            private static final String _EDIT = PortletMode.EDIT.toString();
060    
061            private static final String _EDIT_DEFAULTS =
062                    LiferayPortletMode.EDIT_DEFAULTS.toString();
063    
064            private static final String _EDIT_GUEST =
065                    LiferayPortletMode.EDIT_GUEST.toString();
066    
067            private static final String _HELP = PortletMode.HELP.toString();
068    
069            private static final String _PREVIEW =
070                    LiferayPortletMode.PREVIEW.toString();
071    
072            private static final String _PRINT = LiferayPortletMode.PRINT.toString();
073    
074            private static final String _VIEW = PortletMode.VIEW.toString();
075    
076            private static PortletModeFactory _instance = new PortletModeFactory();
077    
078            private Map<String, PortletMode> _portletModes;
079    
080    }