001    /**
002     * Copyright (c) 2000-present 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 com.liferay.portal.kernel.util.Validator;
018    
019    import java.util.HashMap;
020    import java.util.Map;
021    
022    import javax.portlet.PortletMode;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class PortletModeFactory {
028    
029            public static PortletMode getPortletMode(String name) {
030                    return _instance._getPortletMode(name);
031            }
032    
033            private PortletModeFactory() {
034                    _portletModes = new HashMap<>();
035    
036                    _portletModes.put(_EDIT, LiferayPortletMode.EDIT);
037                    _portletModes.put(_HELP, LiferayPortletMode.HELP);
038                    _portletModes.put(_VIEW, LiferayPortletMode.VIEW);
039                    _portletModes.put(_ABOUT, LiferayPortletMode.ABOUT);
040                    _portletModes.put(_CONFIG, LiferayPortletMode.CONFIG);
041                    _portletModes.put(_EDIT_DEFAULTS, LiferayPortletMode.EDIT_DEFAULTS);
042                    _portletModes.put(_EDIT_GUEST, LiferayPortletMode.EDIT_GUEST);
043                    _portletModes.put(_PREVIEW, LiferayPortletMode.PREVIEW);
044                    _portletModes.put(_PRINT, LiferayPortletMode.PRINT);
045            }
046    
047            private PortletMode _getPortletMode(String name) {
048                    if (Validator.isNull(name)) {
049                            return PortletMode.VIEW;
050                    }
051    
052                    PortletMode portletMode = _portletModes.get(name);
053    
054                    if (portletMode == null) {
055                            portletMode = new PortletMode(name);
056                    }
057    
058                    return portletMode;
059            }
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 = PortletMode.EDIT.toString();
066    
067            private static final String _EDIT_DEFAULTS =
068                    LiferayPortletMode.EDIT_DEFAULTS.toString();
069    
070            private static final String _EDIT_GUEST =
071                    LiferayPortletMode.EDIT_GUEST.toString();
072    
073            private static final String _HELP = PortletMode.HELP.toString();
074    
075            private static final String _PREVIEW =
076                    LiferayPortletMode.PREVIEW.toString();
077    
078            private static final String _PRINT = LiferayPortletMode.PRINT.toString();
079    
080            private static final String _VIEW = PortletMode.VIEW.toString();
081    
082            private static final PortletModeFactory _instance =
083                    new PortletModeFactory();
084    
085            private final Map<String, PortletMode> _portletModes;
086    
087    }