1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.kernel.portlet;
16  
17  import java.util.HashMap;
18  import java.util.Map;
19  
20  import javax.portlet.PortletMode;
21  
22  /**
23   * <a href="PortletModeFactory.java.html"><b><i>View Source</i></b></a>
24   *
25   * @author Brian Wing Shun Chan
26   */
27  public class PortletModeFactory {
28  
29      public static PortletMode getPortletMode(String name) {
30          return _instance._getPortletMode(name);
31      }
32  
33      private PortletModeFactory() {
34          _portletModes = new HashMap<String, PortletMode>();
35  
36          _portletModes.put(_EDIT, LiferayPortletMode.EDIT);
37          _portletModes.put(_HELP, LiferayPortletMode.HELP);
38          _portletModes.put(_VIEW, LiferayPortletMode.VIEW);
39          _portletModes.put(_ABOUT, LiferayPortletMode.ABOUT);
40          _portletModes.put(_CONFIG, LiferayPortletMode.CONFIG);
41          _portletModes.put(_EDIT_DEFAULTS, LiferayPortletMode.EDIT_DEFAULTS);
42          _portletModes.put(_EDIT_GUEST, LiferayPortletMode.EDIT_GUEST);
43          _portletModes.put(_PREVIEW, LiferayPortletMode.PREVIEW);
44          _portletModes.put(_PRINT, LiferayPortletMode.PRINT);
45      }
46  
47      private PortletMode _getPortletMode(String name) {
48          PortletMode portletMode = _portletModes.get(name);
49  
50          if (portletMode == null) {
51              portletMode = new PortletMode(name);
52          }
53  
54          return portletMode;
55      }
56  
57      private static final String _EDIT = PortletMode.EDIT.toString();
58  
59      private static final String _HELP = PortletMode.HELP.toString();
60  
61      private static final String _VIEW = PortletMode.VIEW.toString();
62  
63      private static final String _ABOUT = LiferayPortletMode.ABOUT.toString();
64  
65      private static final String _CONFIG = LiferayPortletMode.CONFIG.toString();
66  
67      private static final String _EDIT_DEFAULTS =
68          LiferayPortletMode.EDIT_DEFAULTS.toString();
69  
70      private static final String _EDIT_GUEST =
71          LiferayPortletMode.EDIT_GUEST.toString();
72  
73      private static final String _PREVIEW =
74          LiferayPortletMode.PREVIEW.toString();
75  
76      private static final String _PRINT = LiferayPortletMode.PRINT.toString();
77  
78      private static PortletModeFactory _instance = new PortletModeFactory();
79  
80      private Map<String, PortletMode> _portletModes;
81  
82  }