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