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