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