1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet;
24  
25  import com.liferay.portal.kernel.job.Scheduler;
26  import com.liferay.portal.kernel.lar.PortletDataHandler;
27  import com.liferay.portal.kernel.pop.MessageListener;
28  import com.liferay.portal.kernel.portlet.ConfigurationAction;
29  import com.liferay.portal.kernel.portlet.FriendlyURLMapper;
30  import com.liferay.portal.kernel.portlet.PortletLayoutListener;
31  import com.liferay.portal.kernel.search.Indexer;
32  import com.liferay.portal.kernel.servlet.URLEncoder;
33  import com.liferay.portal.kernel.util.LocaleUtil;
34  import com.liferay.portlet.social.model.SocialActivityInterpreter;
35  import com.liferay.portlet.social.model.SocialRequestInterpreter;
36  
37  import java.util.Locale;
38  import java.util.Map;
39  import java.util.ResourceBundle;
40  
41  import javax.portlet.Portlet;
42  import javax.portlet.PreferencesValidator;
43  
44  import javax.servlet.ServletContext;
45  
46  /**
47   * <a href="PortletBag.java.html"><b><i>View Source</i></b></a>
48   *
49   * @author Brian Wing Shun Chan
50   *
51   */
52  public class PortletBag {
53  
54      public PortletBag(
55          String portletName, ServletContext  servletContext,
56          Portlet portletInstance,
57          ConfigurationAction configurationActionInstance,
58          Indexer indexerInstance, Scheduler schedulerInstance,
59          FriendlyURLMapper friendlyURLMapperInstance,
60          URLEncoder urlEncoderInstance,
61          PortletDataHandler portletDataHandlerInstance,
62          PortletLayoutListener portletLayoutListenerInstance,
63          MessageListener popMessageListenerInstance,
64          SocialActivityInterpreter socialActivityInterpreterInstance,
65          SocialRequestInterpreter socialRequestInterpreterInstance,
66          PreferencesValidator prefsValidatorInstance,
67          Map<String, ResourceBundle> resourceBundles) {
68  
69          _portletName = portletName;
70          _servletContext = servletContext;
71          _portletInstance = portletInstance;
72          _configurationActionInstance = configurationActionInstance;
73          _indexerInstance = indexerInstance;
74          _schedulerInstance = schedulerInstance;
75          _friendlyURLMapperInstance = friendlyURLMapperInstance;
76          _urlEncoderInstance = urlEncoderInstance;
77          _portletDataHandlerInstance = portletDataHandlerInstance;
78          _portletLayoutListenerInstance = portletLayoutListenerInstance;
79          _popMessageListenerInstance = popMessageListenerInstance;
80          _socialActivityInterpreterInstance = socialActivityInterpreterInstance;
81          _socialRequestInterpreterInstance = socialRequestInterpreterInstance;
82          _prefsValidatorInstance = prefsValidatorInstance;
83          _resourceBundles = resourceBundles;
84      }
85  
86      public String getPortletName() {
87          return _portletName;
88      }
89  
90      public ServletContext getServletContext() {
91          return _servletContext;
92      }
93  
94      public Portlet getPortletInstance() {
95          return _portletInstance;
96      }
97  
98      public void removePortletInstance() {
99          _portletInstance = null;
100     }
101 
102     public ConfigurationAction getConfigurationActionInstance() {
103         return _configurationActionInstance;
104     }
105 
106     public Indexer getIndexerInstance() {
107         return _indexerInstance;
108     }
109 
110     public Scheduler getSchedulerInstance() {
111         return _schedulerInstance;
112     }
113 
114     public FriendlyURLMapper getFriendlyURLMapperInstance() {
115         return _friendlyURLMapperInstance;
116     }
117 
118     public URLEncoder getURLEncoderInstance() {
119         return _urlEncoderInstance;
120     }
121 
122     public PortletDataHandler getPortletDataHandlerInstance() {
123         return _portletDataHandlerInstance;
124     }
125 
126     public PortletLayoutListener getPortletLayoutListenerInstance() {
127         return _portletLayoutListenerInstance;
128     }
129 
130     public MessageListener getPopMessageListenerInstance() {
131         return _popMessageListenerInstance;
132     }
133 
134     public SocialActivityInterpreter getSocialActivityInterpreterInstance() {
135         return _socialActivityInterpreterInstance;
136     }
137 
138     public SocialRequestInterpreter getSocialRequestInterpreterInstance() {
139         return _socialRequestInterpreterInstance;
140     }
141 
142     public PreferencesValidator getPreferencesValidatorInstance() {
143         return _prefsValidatorInstance;
144     }
145 
146     public ResourceBundle getResourceBundle(Locale locale) {
147         ResourceBundle resourceBundle = _resourceBundles.get(
148             LocaleUtil.toLanguageId(locale));
149 
150         if (resourceBundle == null) {
151             resourceBundle = _resourceBundles.get(locale.getLanguage());
152 
153             if (resourceBundle == null) {
154                 resourceBundle = _resourceBundles.get(
155                     LocaleUtil.toLanguageId(LocaleUtil.getDefault()));
156             }
157         }
158 
159         return resourceBundle;
160     }
161 
162     private String _portletName;
163     private ServletContext _servletContext;
164     private Portlet _portletInstance;
165     private ConfigurationAction _configurationActionInstance;
166     private Indexer _indexerInstance;
167     private Scheduler _schedulerInstance;
168     private FriendlyURLMapper _friendlyURLMapperInstance;
169     private URLEncoder _urlEncoderInstance;
170     private PortletDataHandler _portletDataHandlerInstance;
171     private PortletLayoutListener _portletLayoutListenerInstance;
172     private MessageListener _popMessageListenerInstance;
173     private SocialActivityInterpreter _socialActivityInterpreterInstance;
174     private SocialRequestInterpreter _socialRequestInterpreterInstance;
175     private PreferencesValidator _prefsValidatorInstance;
176     private Map<String, ResourceBundle> _resourceBundles;
177 
178 }