001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet;
016    
017    import com.liferay.portal.kernel.atom.AtomCollectionAdapter;
018    import com.liferay.portal.kernel.lar.PortletDataHandler;
019    import com.liferay.portal.kernel.lar.StagedModelDataHandler;
020    import com.liferay.portal.kernel.notifications.UserNotificationHandler;
021    import com.liferay.portal.kernel.poller.PollerProcessor;
022    import com.liferay.portal.kernel.pop.MessageListener;
023    import com.liferay.portal.kernel.portlet.ConfigurationAction;
024    import com.liferay.portal.kernel.portlet.FriendlyURLMapper;
025    import com.liferay.portal.kernel.portlet.PortletBag;
026    import com.liferay.portal.kernel.portlet.PortletLayoutListener;
027    import com.liferay.portal.kernel.search.Indexer;
028    import com.liferay.portal.kernel.search.OpenSearch;
029    import com.liferay.portal.kernel.servlet.URLEncoder;
030    import com.liferay.portal.kernel.template.TemplateHandler;
031    import com.liferay.portal.kernel.trash.TrashHandler;
032    import com.liferay.portal.kernel.util.LocaleUtil;
033    import com.liferay.portal.kernel.webdav.WebDAVStorage;
034    import com.liferay.portal.kernel.workflow.WorkflowHandler;
035    import com.liferay.portal.kernel.xmlrpc.Method;
036    import com.liferay.portal.security.permission.PermissionPropagator;
037    import com.liferay.portlet.asset.model.AssetRendererFactory;
038    import com.liferay.portlet.expando.model.CustomAttributesDisplay;
039    import com.liferay.portlet.social.model.SocialActivityInterpreter;
040    import com.liferay.portlet.social.model.SocialRequestInterpreter;
041    
042    import java.util.List;
043    import java.util.Locale;
044    import java.util.Map;
045    import java.util.ResourceBundle;
046    
047    import javax.portlet.Portlet;
048    import javax.portlet.PreferencesValidator;
049    
050    import javax.servlet.ServletContext;
051    
052    /**
053     * @author Brian Wing Shun Chan
054     * @author Jorge Ferrer
055     */
056    public class PortletBagImpl implements PortletBag {
057    
058            public PortletBagImpl(
059                    String portletName, ServletContext servletContext,
060                    Portlet portletInstance,
061                    ConfigurationAction configurationActionInstance,
062                    List<Indexer> indexerInstances, OpenSearch openSearchInstance,
063                    FriendlyURLMapper friendlyURLMapperInstance,
064                    URLEncoder urlEncoderInstance,
065                    PortletDataHandler portletDataHandlerInstance,
066                    List<StagedModelDataHandler<?>> stagedModelDataHandlerInstances,
067                    TemplateHandler templateHandlerInstance,
068                    PortletLayoutListener portletLayoutListenerInstance,
069                    PollerProcessor pollerProcessorInstance,
070                    MessageListener popMessageListenerInstance,
071                    List<SocialActivityInterpreter> socialActivityInterpreterInstances,
072                    SocialRequestInterpreter socialRequestInterpreterInstance,
073                    List<UserNotificationHandler> userNotificationHandlerInstances,
074                    WebDAVStorage webDAVStorageInstance, Method xmlRpcMethodInstance,
075                    ControlPanelEntry controlPanelEntryInstance,
076                    List<AssetRendererFactory> assetRendererFactoryInstances,
077                    List<AtomCollectionAdapter<?>> atomCollectionAdapters,
078                    List<CustomAttributesDisplay> customAttributesDisplayInstances,
079                    PermissionPropagator permissionPropagatorInstance,
080                    List<TrashHandler> trashHandlerInstances,
081                    List<WorkflowHandler> workflowHandlerInstances,
082                    PreferencesValidator preferencesValidatorInstance,
083                    Map<String, ResourceBundle> resourceBundles) {
084    
085                    _portletName = portletName;
086                    _servletContext = servletContext;
087                    _portletInstance = portletInstance;
088                    _configurationActionInstance = configurationActionInstance;
089                    _indexerInstances = indexerInstances;
090                    _openSearchInstance = openSearchInstance;
091                    _friendlyURLMapperInstance = friendlyURLMapperInstance;
092                    _urlEncoderInstance = urlEncoderInstance;
093                    _portletDataHandlerInstance = portletDataHandlerInstance;
094                    _stagedModelDataHandlerInstances = stagedModelDataHandlerInstances;
095                    _templateHandlerInstance = templateHandlerInstance;
096                    _portletLayoutListenerInstance = portletLayoutListenerInstance;
097                    _pollerProcessorInstance = pollerProcessorInstance;
098                    _popMessageListenerInstance = popMessageListenerInstance;
099                    _socialActivityInterpreterInstances =
100                            socialActivityInterpreterInstances;
101                    _socialRequestInterpreterInstance = socialRequestInterpreterInstance;
102                    _userNotificationHandlerInstances = userNotificationHandlerInstances;
103                    _webDAVStorageInstance = webDAVStorageInstance;
104                    _xmlRpcMethodInstance = xmlRpcMethodInstance;
105                    _controlPanelEntryInstance = controlPanelEntryInstance;
106                    _assetRendererFactoryInstances = assetRendererFactoryInstances;
107                    _atomCollectionAdapterInstances = atomCollectionAdapters;
108                    _customAttributesDisplayInstances = customAttributesDisplayInstances;
109                    _permissionPropagatorInstance = permissionPropagatorInstance;
110                    _trashHandlerInstances = trashHandlerInstances;
111                    _workflowHandlerInstances = workflowHandlerInstances;
112                    _preferencesValidatorInstance = preferencesValidatorInstance;
113                    _resourceBundles = resourceBundles;
114            }
115    
116            @Override
117            public Object clone() {
118                    return new PortletBagImpl(
119                            getPortletName(), getServletContext(), getPortletInstance(),
120                            getConfigurationActionInstance(), getIndexerInstances(),
121                            getOpenSearchInstance(), getFriendlyURLMapperInstance(),
122                            getURLEncoderInstance(), getPortletDataHandlerInstance(),
123                            getStagedModelDataHandlerInstances(), getTemplateHandlerInstance(),
124                            getPortletLayoutListenerInstance(), getPollerProcessorInstance(),
125                            getPopMessageListenerInstance(),
126                            getSocialActivityInterpreterInstances(),
127                            getSocialRequestInterpreterInstance(),
128                            getUserNotificationHandlerInstances(), getWebDAVStorageInstance(),
129                            getXmlRpcMethodInstance(), getControlPanelEntryInstance(),
130                            getAssetRendererFactoryInstances(),
131                            getAtomCollectionAdapterInstances(),
132                            getCustomAttributesDisplayInstances(),
133                            getPermissionPropagatorInstance(), getTrashHandlerInstances(),
134                            getWorkflowHandlerInstances(), getPreferencesValidatorInstance(),
135                            getResourceBundles());
136            }
137    
138            @Override
139            public List<AssetRendererFactory> getAssetRendererFactoryInstances() {
140                    return _assetRendererFactoryInstances;
141            }
142    
143            @Override
144            public List<AtomCollectionAdapter<?>> getAtomCollectionAdapterInstances() {
145                    return _atomCollectionAdapterInstances;
146            }
147    
148            @Override
149            public ConfigurationAction getConfigurationActionInstance() {
150                    return _configurationActionInstance;
151            }
152    
153            @Override
154            public ControlPanelEntry getControlPanelEntryInstance() {
155                    return _controlPanelEntryInstance;
156            }
157    
158            @Override
159            public List<CustomAttributesDisplay> getCustomAttributesDisplayInstances() {
160                    return _customAttributesDisplayInstances;
161            }
162    
163            @Override
164            public FriendlyURLMapper getFriendlyURLMapperInstance() {
165                    return _friendlyURLMapperInstance;
166            }
167    
168            @Override
169            public List<Indexer> getIndexerInstances() {
170                    return _indexerInstances;
171            }
172    
173            @Override
174            public OpenSearch getOpenSearchInstance() {
175                    return _openSearchInstance;
176            }
177    
178            @Override
179            public PermissionPropagator getPermissionPropagatorInstance() {
180                    return _permissionPropagatorInstance;
181            }
182    
183            @Override
184            public PollerProcessor getPollerProcessorInstance() {
185                    return _pollerProcessorInstance;
186            }
187    
188            @Override
189            public MessageListener getPopMessageListenerInstance() {
190                    return _popMessageListenerInstance;
191            }
192    
193            @Override
194            public PortletDataHandler getPortletDataHandlerInstance() {
195                    return _portletDataHandlerInstance;
196            }
197    
198            @Override
199            public Portlet getPortletInstance() {
200                    return _portletInstance;
201            }
202    
203            @Override
204            public PortletLayoutListener getPortletLayoutListenerInstance() {
205                    return _portletLayoutListenerInstance;
206            }
207    
208            @Override
209            public String getPortletName() {
210                    return _portletName;
211            }
212    
213            @Override
214            public PreferencesValidator getPreferencesValidatorInstance() {
215                    return _preferencesValidatorInstance;
216            }
217    
218            @Override
219            public ResourceBundle getResourceBundle(Locale locale) {
220                    ResourceBundle resourceBundle = _resourceBundles.get(
221                            LocaleUtil.toLanguageId(locale));
222    
223                    if (resourceBundle == null) {
224                            resourceBundle = _resourceBundles.get(locale.getLanguage());
225    
226                            if (resourceBundle == null) {
227                                    resourceBundle = _resourceBundles.get(
228                                            LocaleUtil.toLanguageId(LocaleUtil.getDefault()));
229                            }
230                    }
231    
232                    return resourceBundle;
233            }
234    
235            @Override
236            public Map<String, ResourceBundle> getResourceBundles() {
237                    return _resourceBundles;
238            }
239    
240            @Override
241            public ServletContext getServletContext() {
242                    return _servletContext;
243            }
244    
245            @Override
246            public List<SocialActivityInterpreter>
247                    getSocialActivityInterpreterInstances() {
248    
249                    return _socialActivityInterpreterInstances;
250            }
251    
252            @Override
253            public SocialRequestInterpreter getSocialRequestInterpreterInstance() {
254                    return _socialRequestInterpreterInstance;
255            }
256    
257            @Override
258            public List<StagedModelDataHandler<?>>
259                    getStagedModelDataHandlerInstances() {
260    
261                    return _stagedModelDataHandlerInstances;
262            }
263    
264            @Override
265            public TemplateHandler getTemplateHandlerInstance() {
266                    return _templateHandlerInstance;
267            }
268    
269            @Override
270            public List<TrashHandler> getTrashHandlerInstances() {
271                    return _trashHandlerInstances;
272            }
273    
274            @Override
275            public URLEncoder getURLEncoderInstance() {
276                    return _urlEncoderInstance;
277            }
278    
279            @Override
280            public List<UserNotificationHandler>
281                    getUserNotificationHandlerInstances() {
282    
283                    return _userNotificationHandlerInstances;
284            }
285    
286            @Override
287            public WebDAVStorage getWebDAVStorageInstance() {
288                    return _webDAVStorageInstance;
289            }
290    
291            @Override
292            public List<WorkflowHandler> getWorkflowHandlerInstances() {
293                    return _workflowHandlerInstances;
294            }
295    
296            @Override
297            public Method getXmlRpcMethodInstance() {
298                    return _xmlRpcMethodInstance;
299            }
300    
301            @Override
302            public void setPortletInstance(Portlet portletInstance) {
303                    _portletInstance = portletInstance;
304            }
305    
306            @Override
307            public void setPortletName(String portletName) {
308                    _portletName = portletName;
309            }
310    
311            private List<AssetRendererFactory> _assetRendererFactoryInstances;
312            private List<AtomCollectionAdapter<?>> _atomCollectionAdapterInstances;
313            private ConfigurationAction _configurationActionInstance;
314            private ControlPanelEntry _controlPanelEntryInstance;
315            private List<CustomAttributesDisplay> _customAttributesDisplayInstances;
316            private FriendlyURLMapper _friendlyURLMapperInstance;
317            private List<Indexer> _indexerInstances;
318            private OpenSearch _openSearchInstance;
319            private PermissionPropagator _permissionPropagatorInstance;
320            private PollerProcessor _pollerProcessorInstance;
321            private MessageListener _popMessageListenerInstance;
322            private PortletDataHandler _portletDataHandlerInstance;
323            private Portlet _portletInstance;
324            private PortletLayoutListener _portletLayoutListenerInstance;
325            private String _portletName;
326            private PreferencesValidator _preferencesValidatorInstance;
327            private Map<String, ResourceBundle> _resourceBundles;
328            private ServletContext _servletContext;
329            private List<SocialActivityInterpreter> _socialActivityInterpreterInstances;
330            private SocialRequestInterpreter _socialRequestInterpreterInstance;
331            private List<StagedModelDataHandler<?>> _stagedModelDataHandlerInstances;
332            private TemplateHandler _templateHandlerInstance;
333            private List<TrashHandler> _trashHandlerInstances;
334            private URLEncoder _urlEncoderInstance;
335            private List<UserNotificationHandler>
336                    _userNotificationHandlerInstances;
337            private WebDAVStorage _webDAVStorageInstance;
338            private List<WorkflowHandler> _workflowHandlerInstances;
339            private Method _xmlRpcMethodInstance;
340    
341    }