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