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.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            public List<AssetRendererFactory> getAssetRendererFactoryInstances() {
123                    return _assetRendererFactoryInstances;
124            }
125    
126            public List<AtomCollectionAdapter<?>> getAtomCollectionAdapterInstances() {
127                    return _atomCollectionAdapterInstances;
128            }
129    
130            public ConfigurationAction getConfigurationActionInstance() {
131                    return _configurationActionInstance;
132            }
133    
134            public ControlPanelEntry getControlPanelEntryInstance() {
135                    return _controlPanelEntryInstance;
136            }
137    
138            public List<CustomAttributesDisplay> getCustomAttributesDisplayInstances() {
139                    return _customAttributesDisplayInstances;
140            }
141    
142            public FriendlyURLMapper getFriendlyURLMapperInstance() {
143                    return _friendlyURLMapperInstance;
144            }
145    
146            public List<Indexer> getIndexerInstances() {
147                    return _indexerInstances;
148            }
149    
150            public OpenSearch getOpenSearchInstance() {
151                    return _openSearchInstance;
152            }
153    
154            public PermissionPropagator getPermissionPropagatorInstance() {
155                    return _permissionPropagatorInstance;
156            }
157    
158            public PollerProcessor getPollerProcessorInstance() {
159                    return _pollerProcessorInstance;
160            }
161    
162            public MessageListener getPopMessageListenerInstance() {
163                    return _popMessageListenerInstance;
164            }
165    
166            public PortletDataHandler getPortletDataHandlerInstance() {
167                    return _portletDataHandlerInstance;
168            }
169    
170            public Portlet getPortletInstance() {
171                    return _portletInstance;
172            }
173    
174            public PortletLayoutListener getPortletLayoutListenerInstance() {
175                    return _portletLayoutListenerInstance;
176            }
177    
178            public String getPortletName() {
179                    return _portletName;
180            }
181    
182            public PreferencesValidator getPreferencesValidatorInstance() {
183                    return _preferencesValidatorInstance;
184            }
185    
186            public ResourceBundle getResourceBundle(Locale locale) {
187                    ResourceBundle resourceBundle = _resourceBundles.get(
188                            LocaleUtil.toLanguageId(locale));
189    
190                    if (resourceBundle == null) {
191                            resourceBundle = _resourceBundles.get(locale.getLanguage());
192    
193                            if (resourceBundle == null) {
194                                    resourceBundle = _resourceBundles.get(
195                                            LocaleUtil.toLanguageId(LocaleUtil.getDefault()));
196                            }
197                    }
198    
199                    return resourceBundle;
200            }
201    
202            public Map<String, ResourceBundle> getResourceBundles() {
203                    return _resourceBundles;
204            }
205    
206            public ServletContext getServletContext() {
207                    return _servletContext;
208            }
209    
210            public SocialActivityInterpreter getSocialActivityInterpreterInstance() {
211                    return _socialActivityInterpreterInstance;
212            }
213    
214            public SocialRequestInterpreter getSocialRequestInterpreterInstance() {
215                    return _socialRequestInterpreterInstance;
216            }
217    
218            public URLEncoder getURLEncoderInstance() {
219                    return _urlEncoderInstance;
220            }
221    
222            public WebDAVStorage getWebDAVStorageInstance() {
223                    return _webDAVStorageInstance;
224            }
225    
226            public List<WorkflowHandler> getWorkflowHandlerInstances() {
227                    return _workflowHandlerInstances;
228            }
229    
230            public Method getXmlRpcMethodInstance() {
231                    return _xmlRpcMethodInstance;
232            }
233    
234            public void setPortletInstance(Portlet portletInstance) {
235                    _portletInstance = portletInstance;
236            }
237    
238            public void setPortletName(String portletName) {
239                    _portletName = portletName;
240            }
241    
242            private List<AssetRendererFactory> _assetRendererFactoryInstances;
243            private List<AtomCollectionAdapter<?>> _atomCollectionAdapterInstances;
244            private ConfigurationAction _configurationActionInstance;
245            private ControlPanelEntry _controlPanelEntryInstance;
246            private List<CustomAttributesDisplay> _customAttributesDisplayInstances;
247            private FriendlyURLMapper _friendlyURLMapperInstance;
248            private List<Indexer> _indexerInstances;
249            private OpenSearch _openSearchInstance;
250            private PermissionPropagator _permissionPropagatorInstance;
251            private PollerProcessor _pollerProcessorInstance;
252            private MessageListener _popMessageListenerInstance;
253            private PortletDataHandler _portletDataHandlerInstance;
254            private Portlet _portletInstance;
255            private PortletLayoutListener _portletLayoutListenerInstance;
256            private String _portletName;
257            private PreferencesValidator _preferencesValidatorInstance;
258            private Map<String, ResourceBundle> _resourceBundles;
259            private ServletContext _servletContext;
260            private SocialActivityInterpreter _socialActivityInterpreterInstance;
261            private SocialRequestInterpreter _socialRequestInterpreterInstance;
262            private URLEncoder _urlEncoderInstance;
263            private WebDAVStorage _webDAVStorageInstance;
264            private List<WorkflowHandler> _workflowHandlerInstances;
265            private Method _xmlRpcMethodInstance;
266    
267    }