1   /**
2    * Copyright (c) 2000-2009 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.poller.PollerProcessor;
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.PortletBag;
31  import com.liferay.portal.kernel.portlet.PortletLayoutListener;
32  import com.liferay.portal.kernel.search.Indexer;
33  import com.liferay.portal.kernel.search.OpenSearch;
34  import com.liferay.portal.kernel.servlet.URLEncoder;
35  import com.liferay.portal.kernel.util.LocaleUtil;
36  import com.liferay.portal.lar.PortletDataHandler;
37  import com.liferay.portlet.social.model.SocialActivityInterpreter;
38  import com.liferay.portlet.social.model.SocialRequestInterpreter;
39  
40  import java.util.Locale;
41  import java.util.Map;
42  import java.util.ResourceBundle;
43  
44  import javax.portlet.Portlet;
45  import javax.portlet.PreferencesValidator;
46  
47  import javax.servlet.ServletContext;
48  
49  /**
50   * <a href="PortletBagImpl.java.html"><b><i>View Source</i></b></a>
51   *
52   * @author Brian Wing Shun Chan
53   *
54   */
55  public class PortletBagImpl implements PortletBag {
56  
57      public PortletBagImpl(
58          String portletName, ServletContext  servletContext,
59          Portlet portletInstance,
60          ConfigurationAction configurationActionInstance,
61          Indexer indexerInstance, OpenSearch openSearchInstance,
62          Scheduler schedulerInstance,
63          FriendlyURLMapper friendlyURLMapperInstance,
64          URLEncoder urlEncoderInstance,
65          PortletDataHandler portletDataHandlerInstance,
66          PortletLayoutListener portletLayoutListenerInstance,
67          PollerProcessor pollerProcessorInstance,
68          MessageListener popMessageListenerInstance,
69          SocialActivityInterpreter socialActivityInterpreterInstance,
70          SocialRequestInterpreter socialRequestInterpreterInstance,
71          PreferencesValidator prefsValidatorInstance,
72          Map<String, ResourceBundle> resourceBundles) {
73  
74          _portletName = portletName;
75          _servletContext = servletContext;
76          _portletInstance = portletInstance;
77          _configurationActionInstance = configurationActionInstance;
78          _indexerInstance = indexerInstance;
79          _openSearchInstance = openSearchInstance;
80          _schedulerInstance = schedulerInstance;
81          _friendlyURLMapperInstance = friendlyURLMapperInstance;
82          _urlEncoderInstance = urlEncoderInstance;
83          _portletDataHandlerInstance = portletDataHandlerInstance;
84          _portletLayoutListenerInstance = portletLayoutListenerInstance;
85          _pollerProcessorInstance = pollerProcessorInstance;
86          _popMessageListenerInstance = popMessageListenerInstance;
87          _socialActivityInterpreterInstance = socialActivityInterpreterInstance;
88          _socialRequestInterpreterInstance = socialRequestInterpreterInstance;
89          _prefsValidatorInstance = prefsValidatorInstance;
90          _resourceBundles = resourceBundles;
91      }
92  
93      public String getPortletName() {
94          return _portletName;
95      }
96  
97      public ServletContext getServletContext() {
98          return _servletContext;
99      }
100 
101     public Portlet getPortletInstance() {
102         return _portletInstance;
103     }
104 
105     public void removePortletInstance() {
106         _portletInstance = null;
107     }
108 
109     public ConfigurationAction getConfigurationActionInstance() {
110         return _configurationActionInstance;
111     }
112 
113     public Indexer getIndexerInstance() {
114         return _indexerInstance;
115     }
116 
117     public OpenSearch getOpenSearchInstance() {
118         return _openSearchInstance;
119     }
120 
121     public Scheduler getSchedulerInstance() {
122         return _schedulerInstance;
123     }
124 
125     public FriendlyURLMapper getFriendlyURLMapperInstance() {
126         return _friendlyURLMapperInstance;
127     }
128 
129     public URLEncoder getURLEncoderInstance() {
130         return _urlEncoderInstance;
131     }
132 
133     public PortletDataHandler getPortletDataHandlerInstance() {
134         return _portletDataHandlerInstance;
135     }
136 
137     public PortletLayoutListener getPortletLayoutListenerInstance() {
138         return _portletLayoutListenerInstance;
139     }
140 
141     public PollerProcessor getPollerProcessorInstance() {
142         return _pollerProcessorInstance;
143     }
144 
145     public MessageListener getPopMessageListenerInstance() {
146         return _popMessageListenerInstance;
147     }
148 
149     public SocialActivityInterpreter getSocialActivityInterpreterInstance() {
150         return _socialActivityInterpreterInstance;
151     }
152 
153     public SocialRequestInterpreter getSocialRequestInterpreterInstance() {
154         return _socialRequestInterpreterInstance;
155     }
156 
157     public PreferencesValidator getPreferencesValidatorInstance() {
158         return _prefsValidatorInstance;
159     }
160 
161     public ResourceBundle getResourceBundle(Locale locale) {
162         ResourceBundle resourceBundle = _resourceBundles.get(
163             LocaleUtil.toLanguageId(locale));
164 
165         if (resourceBundle == null) {
166             resourceBundle = _resourceBundles.get(locale.getLanguage());
167 
168             if (resourceBundle == null) {
169                 resourceBundle = _resourceBundles.get(
170                     LocaleUtil.toLanguageId(LocaleUtil.getDefault()));
171             }
172         }
173 
174         return resourceBundle;
175     }
176 
177     private String _portletName;
178     private ServletContext _servletContext;
179     private Portlet _portletInstance;
180     private ConfigurationAction _configurationActionInstance;
181     private Indexer _indexerInstance;
182     private OpenSearch _openSearchInstance;
183     private Scheduler _schedulerInstance;
184     private FriendlyURLMapper _friendlyURLMapperInstance;
185     private URLEncoder _urlEncoderInstance;
186     private PortletDataHandler _portletDataHandlerInstance;
187     private PortletLayoutListener _portletLayoutListenerInstance;
188     private PollerProcessor _pollerProcessorInstance;
189     private MessageListener _popMessageListenerInstance;
190     private SocialActivityInterpreter _socialActivityInterpreterInstance;
191     private SocialRequestInterpreter _socialRequestInterpreterInstance;
192     private PreferencesValidator _prefsValidatorInstance;
193     private Map<String, ResourceBundle> _resourceBundles;
194 
195 }