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.pop.MessageListener;
27  import com.liferay.portal.kernel.portlet.ConfigurationAction;
28  import com.liferay.portal.kernel.portlet.FriendlyURLMapper;
29  import com.liferay.portal.kernel.portlet.PortletBag;
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.portal.lar.PortletDataHandler;
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, Scheduler schedulerInstance,
60          FriendlyURLMapper friendlyURLMapperInstance,
61          URLEncoder urlEncoderInstance,
62          PortletDataHandler portletDataHandlerInstance,
63          PortletLayoutListener portletLayoutListenerInstance,
64          MessageListener popMessageListenerInstance,
65          SocialActivityInterpreter socialActivityInterpreterInstance,
66          SocialRequestInterpreter socialRequestInterpreterInstance,
67          PreferencesValidator prefsValidatorInstance,
68          Map<String, ResourceBundle> resourceBundles) {
69  
70          _portletName = portletName;
71          _servletContext = servletContext;
72          _portletInstance = portletInstance;
73          _configurationActionInstance = configurationActionInstance;
74          _indexerInstance = indexerInstance;
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 Scheduler getSchedulerInstance() {
112         return _schedulerInstance;
113     }
114 
115     public FriendlyURLMapper getFriendlyURLMapperInstance() {
116         return _friendlyURLMapperInstance;
117     }
118 
119     public URLEncoder getURLEncoderInstance() {
120         return _urlEncoderInstance;
121     }
122 
123     public PortletDataHandler getPortletDataHandlerInstance() {
124         return _portletDataHandlerInstance;
125     }
126 
127     public PortletLayoutListener getPortletLayoutListenerInstance() {
128         return _portletLayoutListenerInstance;
129     }
130 
131     public MessageListener getPopMessageListenerInstance() {
132         return _popMessageListenerInstance;
133     }
134 
135     public SocialActivityInterpreter getSocialActivityInterpreterInstance() {
136         return _socialActivityInterpreterInstance;
137     }
138 
139     public SocialRequestInterpreter getSocialRequestInterpreterInstance() {
140         return _socialRequestInterpreterInstance;
141     }
142 
143     public PreferencesValidator getPreferencesValidatorInstance() {
144         return _prefsValidatorInstance;
145     }
146 
147     public ResourceBundle getResourceBundle(Locale locale) {
148         ResourceBundle resourceBundle = _resourceBundles.get(
149             LocaleUtil.toLanguageId(locale));
150 
151         if (resourceBundle == null) {
152             resourceBundle = _resourceBundles.get(locale.getLanguage());
153 
154             if (resourceBundle == null) {
155                 resourceBundle = _resourceBundles.get(
156                     LocaleUtil.toLanguageId(LocaleUtil.getDefault()));
157             }
158         }
159 
160         return resourceBundle;
161     }
162 
163     private String _portletName;
164     private ServletContext _servletContext;
165     private Portlet _portletInstance;
166     private ConfigurationAction _configurationActionInstance;
167     private Indexer _indexerInstance;
168     private Scheduler _schedulerInstance;
169     private FriendlyURLMapper _friendlyURLMapperInstance;
170     private URLEncoder _urlEncoderInstance;
171     private PortletDataHandler _portletDataHandlerInstance;
172     private PortletLayoutListener _portletLayoutListenerInstance;
173     private MessageListener _popMessageListenerInstance;
174     private SocialActivityInterpreter _socialActivityInterpreterInstance;
175     private SocialRequestInterpreter _socialRequestInterpreterInstance;
176     private PreferencesValidator _prefsValidatorInstance;
177     private Map<String, ResourceBundle> _resourceBundles;
178 
179 }