1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet;
24  
25  import com.liferay.portal.kernel.job.Scheduler;
26  import com.liferay.portal.kernel.poller.PollerProcessor;
27  import com.liferay.portal.kernel.pop.MessageListener;
28  import com.liferay.portal.kernel.portlet.ConfigurationAction;
29  import com.liferay.portal.kernel.portlet.FriendlyURLMapper;
30  import com.liferay.portal.kernel.portlet.PortletBag;
31  import com.liferay.portal.kernel.portlet.PortletLayoutListener;
32  import com.liferay.portal.kernel.search.Indexer;
33  import com.liferay.portal.kernel.search.OpenSearch;
34  import com.liferay.portal.kernel.servlet.URLEncoder;
35  import com.liferay.portal.kernel.util.LocaleUtil;
36  import com.liferay.portal.lar.PortletDataHandler;
37  import com.liferay.portlet.social.model.SocialActivityInterpreter;
38  import com.liferay.portlet.social.model.SocialRequestInterpreter;
39  
40  import java.util.Locale;
41  import java.util.Map;
42  import java.util.ResourceBundle;
43  
44  import javax.portlet.Portlet;
45  import javax.portlet.PreferencesValidator;
46  
47  import javax.servlet.ServletContext;
48  
49  /**
50   * <a href="PortletBagImpl.java.html"><b><i>View Source</i></b></a>
51   *
52   * @author Brian Wing Shun Chan
53   */
54  public class PortletBagImpl implements PortletBag {
55  
56      public PortletBagImpl(
57          String portletName, ServletContext servletContext,
58          Portlet portletInstance,
59          ConfigurationAction configurationActionInstance,
60          Indexer indexerInstance, OpenSearch openSearchInstance,
61          Scheduler schedulerInstance,
62          FriendlyURLMapper friendlyURLMapperInstance,
63          URLEncoder urlEncoderInstance,
64          PortletDataHandler portletDataHandlerInstance,
65          PortletLayoutListener portletLayoutListenerInstance,
66          PollerProcessor pollerProcessorInstance,
67          MessageListener popMessageListenerInstance,
68          SocialActivityInterpreter socialActivityInterpreterInstance,
69          SocialRequestInterpreter socialRequestInterpreterInstance,
70          PreferencesValidator prefsValidatorInstance,
71          Map<String, ResourceBundle> resourceBundles) {
72  
73          _portletName = portletName;
74          _servletContext = servletContext;
75          _portletInstance = portletInstance;
76          _configurationActionInstance = configurationActionInstance;
77          _indexerInstance = indexerInstance;
78          _openSearchInstance = openSearchInstance;
79          _schedulerInstance = schedulerInstance;
80          _friendlyURLMapperInstance = friendlyURLMapperInstance;
81          _urlEncoderInstance = urlEncoderInstance;
82          _portletDataHandlerInstance = portletDataHandlerInstance;
83          _portletLayoutListenerInstance = portletLayoutListenerInstance;
84          _pollerProcessorInstance = pollerProcessorInstance;
85          _popMessageListenerInstance = popMessageListenerInstance;
86          _socialActivityInterpreterInstance = socialActivityInterpreterInstance;
87          _socialRequestInterpreterInstance = socialRequestInterpreterInstance;
88          _prefsValidatorInstance = prefsValidatorInstance;
89          _resourceBundles = resourceBundles;
90      }
91  
92      public Object clone() {
93          return new PortletBagImpl(
94              getPortletName(), getServletContext(), getPortletInstance(),
95              getConfigurationActionInstance(), getIndexerInstance(),
96              getOpenSearchInstance(), getSchedulerInstance(),
97              getFriendlyURLMapperInstance(), getURLEncoderInstance(),
98              getPortletDataHandlerInstance(), getPortletLayoutListenerInstance(),
99              getPollerProcessorInstance(), getPopMessageListenerInstance(),
100             getSocialActivityInterpreterInstance(),
101             getSocialRequestInterpreterInstance(),
102             getPreferencesValidatorInstance(), getResourceBundles());
103     }
104 
105     public ConfigurationAction getConfigurationActionInstance() {
106         return _configurationActionInstance;
107     }
108 
109     public FriendlyURLMapper getFriendlyURLMapperInstance() {
110         return _friendlyURLMapperInstance;
111     }
112 
113     public Indexer getIndexerInstance() {
114         return _indexerInstance;
115     }
116 
117     public OpenSearch getOpenSearchInstance() {
118         return _openSearchInstance;
119     }
120 
121     public PollerProcessor getPollerProcessorInstance() {
122         return _pollerProcessorInstance;
123     }
124 
125     public MessageListener getPopMessageListenerInstance() {
126         return _popMessageListenerInstance;
127     }
128 
129     public PortletDataHandler getPortletDataHandlerInstance() {
130         return _portletDataHandlerInstance;
131     }
132 
133     public Portlet getPortletInstance() {
134         return _portletInstance;
135     }
136 
137     public PortletLayoutListener getPortletLayoutListenerInstance() {
138         return _portletLayoutListenerInstance;
139     }
140 
141     public String getPortletName() {
142         return _portletName;
143     }
144 
145     public PreferencesValidator getPreferencesValidatorInstance() {
146         return _prefsValidatorInstance;
147     }
148 
149     public ResourceBundle getResourceBundle(Locale locale) {
150         ResourceBundle resourceBundle = _resourceBundles.get(
151             LocaleUtil.toLanguageId(locale));
152 
153         if (resourceBundle == null) {
154             resourceBundle = _resourceBundles.get(locale.getLanguage());
155 
156             if (resourceBundle == null) {
157                 resourceBundle = _resourceBundles.get(
158                     LocaleUtil.toLanguageId(LocaleUtil.getDefault()));
159             }
160         }
161 
162         return resourceBundle;
163     }
164 
165     public Map<String, ResourceBundle> getResourceBundles() {
166         return _resourceBundles;
167     }
168 
169     public Scheduler getSchedulerInstance() {
170         return _schedulerInstance;
171     }
172 
173     public ServletContext getServletContext() {
174         return _servletContext;
175     }
176 
177     public SocialActivityInterpreter getSocialActivityInterpreterInstance() {
178         return _socialActivityInterpreterInstance;
179     }
180 
181     public SocialRequestInterpreter getSocialRequestInterpreterInstance() {
182         return _socialRequestInterpreterInstance;
183     }
184 
185     public URLEncoder getURLEncoderInstance() {
186         return _urlEncoderInstance;
187     }
188 
189     public void setPortletInstance(Portlet portletInstance) {
190         _portletInstance = portletInstance;
191     }
192 
193     public void setPortletName(String portletName) {
194         _portletName = portletName;
195     }
196 
197     private ConfigurationAction _configurationActionInstance;
198     private FriendlyURLMapper _friendlyURLMapperInstance;
199     private Indexer _indexerInstance;
200     private OpenSearch _openSearchInstance;
201     private PollerProcessor _pollerProcessorInstance;
202     private MessageListener _popMessageListenerInstance;
203     private PortletDataHandler _portletDataHandlerInstance;
204     private Portlet _portletInstance;
205     private PortletLayoutListener _portletLayoutListenerInstance;
206     private String _portletName;
207     private PreferencesValidator _prefsValidatorInstance;
208     private Map<String, ResourceBundle> _resourceBundles;
209     private Scheduler _schedulerInstance;
210     private ServletContext _servletContext;
211     private SocialActivityInterpreter _socialActivityInterpreterInstance;
212     private SocialRequestInterpreter _socialRequestInterpreterInstance;
213     private URLEncoder _urlEncoderInstance;
214 
215 }