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.portal.kernel.portlet;
21  
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  import javax.portlet.PortletMode;
26  
27  /**
28   * <a href="PortletModeFactory.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   *
32   */
33  public class PortletModeFactory {
34  
35      public static PortletMode getPortletMode(String name) {
36          return _instance._getPortletMode(name);
37      }
38  
39      private PortletModeFactory() {
40          _portletModes = new HashMap<String, PortletMode>();
41  
42          _portletModes.put(_EDIT, LiferayPortletMode.EDIT);
43          _portletModes.put(_HELP, LiferayPortletMode.HELP);
44          _portletModes.put(_VIEW, LiferayPortletMode.VIEW);
45          _portletModes.put(_ABOUT, LiferayPortletMode.ABOUT);
46          _portletModes.put(_CONFIG, LiferayPortletMode.CONFIG);
47          _portletModes.put(_EDIT_DEFAULTS, LiferayPortletMode.EDIT_DEFAULTS);
48          _portletModes.put(_EDIT_GUEST, LiferayPortletMode.EDIT_GUEST);
49          _portletModes.put(_PREVIEW, LiferayPortletMode.PREVIEW);
50          _portletModes.put(_PRINT, LiferayPortletMode.PRINT);
51      }
52  
53      private PortletMode _getPortletMode(String name) {
54          PortletMode portletMode = _portletModes.get(name);
55  
56          if (portletMode == null) {
57              portletMode = new PortletMode(name);
58          }
59  
60          return portletMode;
61      }
62  
63      private static final String _EDIT = PortletMode.EDIT.toString();
64  
65      private static final String _HELP = PortletMode.HELP.toString();
66  
67      private static final String _VIEW = PortletMode.VIEW.toString();
68  
69      private static final String _ABOUT = LiferayPortletMode.ABOUT.toString();
70  
71      private static final String _CONFIG = LiferayPortletMode.CONFIG.toString();
72  
73      private static final String _EDIT_DEFAULTS =
74          LiferayPortletMode.EDIT_DEFAULTS.toString();
75  
76      private static final String _EDIT_GUEST =
77          LiferayPortletMode.EDIT_GUEST.toString();
78  
79      private static final String _PREVIEW =
80          LiferayPortletMode.PREVIEW.toString();
81  
82      private static final String _PRINT = LiferayPortletMode.PRINT.toString();
83  
84      private static PortletModeFactory _instance = new PortletModeFactory();
85  
86      private Map<String, PortletMode> _portletModes;
87  
88  }