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