001    /**
002     * Copyright (c) 2000-2012 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.poller.PollerProcessor;
021    import com.liferay.portal.kernel.pop.MessageListener;
022    import com.liferay.portal.kernel.portlet.ConfigurationAction;
023    import com.liferay.portal.kernel.portlet.FriendlyURLMapper;
024    import com.liferay.portal.kernel.portlet.PortletBag;
025    import com.liferay.portal.kernel.portlet.PortletLayoutListener;
026    import com.liferay.portal.kernel.portletdisplaytemplate.PortletDisplayTemplateHandler;
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.trash.TrashHandler;
031    import com.liferay.portal.kernel.util.LocaleUtil;
032    import com.liferay.portal.kernel.webdav.WebDAVStorage;
033    import com.liferay.portal.kernel.workflow.WorkflowHandler;
034    import com.liferay.portal.kernel.xmlrpc.Method;
035    import com.liferay.portal.security.permission.PermissionPropagator;
036    import com.liferay.portlet.asset.model.AssetRendererFactory;
037    import com.liferay.portlet.expando.model.CustomAttributesDisplay;
038    import com.liferay.portlet.social.model.SocialActivityInterpreter;
039    import com.liferay.portlet.social.model.SocialRequestInterpreter;
040    
041    import java.util.List;
042    import java.util.Locale;
043    import java.util.Map;
044    import java.util.ResourceBundle;
045    
046    import javax.portlet.Portlet;
047    import javax.portlet.PreferencesValidator;
048    
049    import javax.servlet.ServletContext;
050    
051    /**
052     * @author Brian Wing Shun Chan
053     * @author Jorge Ferrer
054     */
055    public class PortletBagImpl implements PortletBag {
056    
057            public PortletBagImpl(
058                    String portletName, ServletContext servletContext,
059                    Portlet portletInstance,
060                    ConfigurationAction configurationActionInstance,
061                    List<Indexer> indexerInstances, OpenSearch openSearchInstance,
062                    FriendlyURLMapper friendlyURLMapperInstance,
063                    URLEncoder urlEncoderInstance,
064                    PortletDataHandler portletDataHandlerInstance,
065                    List<StagedModelDataHandler<?>> stagedModelDataHandlerInstances,
066                    PortletDisplayTemplateHandler portletDisplayTemplateHandlerInstance,
067                    PortletLayoutListener portletLayoutListenerInstance,
068                    PollerProcessor pollerProcessorInstance,
069                    MessageListener popMessageListenerInstance,
070                    SocialActivityInterpreter socialActivityInterpreterInstance,
071                    SocialRequestInterpreter socialRequestInterpreterInstance,
072                    WebDAVStorage webDAVStorageInstance, Method xmlRpcMethodInstance,
073                    ControlPanelEntry controlPanelEntryInstance,
074                    List<AssetRendererFactory> assetRendererFactoryInstances,
075                    List<AtomCollectionAdapter<?>> atomCollectionAdapters,
076                    List<CustomAttributesDisplay> customAttributesDisplayInstances,
077                    PermissionPropagator permissionPropagatorInstance,
078                    List<TrashHandler> trashHandlerInstances,
079                    List<WorkflowHandler> workflowHandlerInstances,
080                    PreferencesValidator preferencesValidatorInstance,
081                    Map<String, ResourceBundle> resourceBundles) {
082    
083                    _portletName = portletName;
084                    _servletContext = servletContext;
085                    _portletInstance = portletInstance;
086                    _configurationActionInstance = configurationActionInstance;
087                    _indexerInstances = indexerInstances;
088                    _openSearchInstance = openSearchInstance;
089                    _friendlyURLMapperInstance = friendlyURLMapperInstance;
090                    _urlEncoderInstance = urlEncoderInstance;
091                    _portletDataHandlerInstance = portletDataHandlerInstance;
092                    _stagedModelDataHandlerInstances = stagedModelDataHandlerInstances;
093                    _portletDisplayTemplateHandlerInstance =
094                            portletDisplayTemplateHandlerInstance;
095                    _portletLayoutListenerInstance = portletLayoutListenerInstance;
096                    _pollerProcessorInstance = pollerProcessorInstance;
097                    _popMessageListenerInstance = popMessageListenerInstance;
098                    _socialActivityInterpreterInstance = socialActivityInterpreterInstance;
099                    _socialRequestInterpreterInstance = socialRequestInterpreterInstance;
100                    _webDAVStorageInstance = webDAVStorageInstance;
101                    _xmlRpcMethodInstance = xmlRpcMethodInstance;
102                    _controlPanelEntryInstance = controlPanelEntryInstance;
103                    _assetRendererFactoryInstances = assetRendererFactoryInstances;
104                    _atomCollectionAdapterInstances = atomCollectionAdapters;
105                    _customAttributesDisplayInstances = customAttributesDisplayInstances;
106                    _permissionPropagatorInstance = permissionPropagatorInstance;
107                    _trashHandlerInstances = trashHandlerInstances;
108                    _workflowHandlerInstances = workflowHandlerInstances;
109                    _preferencesValidatorInstance = preferencesValidatorInstance;
110                    _resourceBundles = resourceBundles;
111            }
112    
113            @Override
114            public Object clone() {
115                    return new PortletBagImpl(
116                            getPortletName(), getServletContext(), getPortletInstance(),
117                            getConfigurationActionInstance(), getIndexerInstances(),
118                            getOpenSearchInstance(), getFriendlyURLMapperInstance(),
119                            getURLEncoderInstance(), getPortletDataHandlerInstance(),
120                            getStagedModelDataHandlerInstances(),
121                            getPortletDisplayTemplateHandlerInstance(),
122                            getPortletLayoutListenerInstance(), getPollerProcessorInstance(),
123                            getPopMessageListenerInstance(),
124                            getSocialActivityInterpreterInstance(),
125                            getSocialRequestInterpreterInstance(), getWebDAVStorageInstance(),
126                            getXmlRpcMethodInstance(), getControlPanelEntryInstance(),
127                            getAssetRendererFactoryInstances(),
128                            getAtomCollectionAdapterInstances(),
129                            getCustomAttributesDisplayInstances(),
130                            getPermissionPropagatorInstance(), getTrashHandlerInstances(),
131                            getWorkflowHandlerInstances(), getPreferencesValidatorInstance(),
132                            getResourceBundles());
133            }
134    
135            public List<AssetRendererFactory> getAssetRendererFactoryInstances() {
136                    return _assetRendererFactoryInstances;
137            }
138    
139            public List<AtomCollectionAdapter<?>> getAtomCollectionAdapterInstances() {
140                    return _atomCollectionAdapterInstances;
141            }
142    
143            public ConfigurationAction getConfigurationActionInstance() {
144                    return _configurationActionInstance;
145            }
146    
147            public ControlPanelEntry getControlPanelEntryInstance() {
148                    return _controlPanelEntryInstance;
149            }
150    
151            public List<CustomAttributesDisplay> getCustomAttributesDisplayInstances() {
152                    return _customAttributesDisplayInstances;
153            }
154    
155            public FriendlyURLMapper getFriendlyURLMapperInstance() {
156                    return _friendlyURLMapperInstance;
157            }
158    
159            public List<Indexer> getIndexerInstances() {
160                    return _indexerInstances;
161            }
162    
163            public OpenSearch getOpenSearchInstance() {
164                    return _openSearchInstance;
165            }
166    
167            public PermissionPropagator getPermissionPropagatorInstance() {
168                    return _permissionPropagatorInstance;
169            }
170    
171            public PollerProcessor getPollerProcessorInstance() {
172                    return _pollerProcessorInstance;
173            }
174    
175            public MessageListener getPopMessageListenerInstance() {
176                    return _popMessageListenerInstance;
177            }
178    
179            public PortletDataHandler getPortletDataHandlerInstance() {
180                    return _portletDataHandlerInstance;
181            }
182    
183            public PortletDisplayTemplateHandler
184                    getPortletDisplayTemplateHandlerInstance() {
185    
186                    return _portletDisplayTemplateHandlerInstance;
187            }
188    
189            public Portlet getPortletInstance() {
190                    return _portletInstance;
191            }
192    
193            public PortletLayoutListener getPortletLayoutListenerInstance() {
194                    return _portletLayoutListenerInstance;
195            }
196    
197            public String getPortletName() {
198                    return _portletName;
199            }
200    
201            public PreferencesValidator getPreferencesValidatorInstance() {
202                    return _preferencesValidatorInstance;
203            }
204    
205            public ResourceBundle getResourceBundle(Locale locale) {
206                    ResourceBundle resourceBundle = _resourceBundles.get(
207                            LocaleUtil.toLanguageId(locale));
208    
209                    if (resourceBundle == null) {
210                            resourceBundle = _resourceBundles.get(locale.getLanguage());
211    
212                            if (resourceBundle == null) {
213                                    resourceBundle = _resourceBundles.get(
214                                            LocaleUtil.toLanguageId(LocaleUtil.getDefault()));
215                            }
216                    }
217    
218                    return resourceBundle;
219            }
220    
221            public Map<String, ResourceBundle> getResourceBundles() {
222                    return _resourceBundles;
223            }
224    
225            public ServletContext getServletContext() {
226                    return _servletContext;
227            }
228    
229            public SocialActivityInterpreter getSocialActivityInterpreterInstance() {
230                    return _socialActivityInterpreterInstance;
231            }
232    
233            public SocialRequestInterpreter getSocialRequestInterpreterInstance() {
234                    return _socialRequestInterpreterInstance;
235            }
236    
237            public List<StagedModelDataHandler<?>>
238                    getStagedModelDataHandlerInstances() {
239    
240                    return _stagedModelDataHandlerInstances;
241            }
242    
243            public List<TrashHandler> getTrashHandlerInstances() {
244                    return _trashHandlerInstances;
245            }
246    
247            public URLEncoder getURLEncoderInstance() {
248                    return _urlEncoderInstance;
249            }
250    
251            public WebDAVStorage getWebDAVStorageInstance() {
252                    return _webDAVStorageInstance;
253            }
254    
255            public List<WorkflowHandler> getWorkflowHandlerInstances() {
256                    return _workflowHandlerInstances;
257            }
258    
259            public Method getXmlRpcMethodInstance() {
260                    return _xmlRpcMethodInstance;
261            }
262    
263            public void setPortletInstance(Portlet portletInstance) {
264                    _portletInstance = portletInstance;
265            }
266    
267            public void setPortletName(String portletName) {
268                    _portletName = portletName;
269            }
270    
271            private List<AssetRendererFactory> _assetRendererFactoryInstances;
272            private List<AtomCollectionAdapter<?>> _atomCollectionAdapterInstances;
273            private ConfigurationAction _configurationActionInstance;
274            private ControlPanelEntry _controlPanelEntryInstance;
275            private List<CustomAttributesDisplay> _customAttributesDisplayInstances;
276            private FriendlyURLMapper _friendlyURLMapperInstance;
277            private List<Indexer> _indexerInstances;
278            private OpenSearch _openSearchInstance;
279            private PermissionPropagator _permissionPropagatorInstance;
280            private PollerProcessor _pollerProcessorInstance;
281            private MessageListener _popMessageListenerInstance;
282            private PortletDataHandler _portletDataHandlerInstance;
283            private PortletDisplayTemplateHandler
284                    _portletDisplayTemplateHandlerInstance;
285            private Portlet _portletInstance;
286            private PortletLayoutListener _portletLayoutListenerInstance;
287            private String _portletName;
288            private PreferencesValidator _preferencesValidatorInstance;
289            private Map<String, ResourceBundle> _resourceBundles;
290            private ServletContext _servletContext;
291            private SocialActivityInterpreter _socialActivityInterpreterInstance;
292            private SocialRequestInterpreter _socialRequestInterpreterInstance;
293            private List<StagedModelDataHandler<?>> _stagedModelDataHandlerInstances;
294            private List<TrashHandler> _trashHandlerInstances;
295            private URLEncoder _urlEncoderInstance;
296            private WebDAVStorage _webDAVStorageInstance;
297            private List<WorkflowHandler> _workflowHandlerInstances;
298            private Method _xmlRpcMethodInstance;
299    
300    }