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