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