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