1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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.portal.servlet;
24  
25  import com.liferay.portal.job.Scheduler;
26  import com.liferay.portal.kernel.lar.PortletDataHandler;
27  import com.liferay.portal.kernel.portlet.ConfigurationAction;
28  import com.liferay.portal.kernel.portlet.FriendlyURLMapper;
29  import com.liferay.portal.kernel.portlet.PortletLayoutListener;
30  import com.liferay.portal.kernel.search.Indexer;
31  import com.liferay.portal.kernel.servlet.URLEncoder;
32  import com.liferay.portal.kernel.smtp.MessageListener;
33  import com.liferay.portal.kernel.util.LocaleUtil;
34  
35  import java.util.Locale;
36  import java.util.Map;
37  import java.util.ResourceBundle;
38  
39  import javax.portlet.Portlet;
40  import javax.portlet.PreferencesValidator;
41  
42  import javax.servlet.ServletContext;
43  
44  /**
45   * <a href="PortletContextWrapper.java.html"><b><i>View Source</i></b></a>
46   *
47   * @author Brian Wing Shun Chan
48   *
49   */
50  public class PortletContextWrapper {
51  
52      public PortletContextWrapper(
53          String portletName, ServletContext  servletContext,
54          Portlet portletInstance,
55          ConfigurationAction configurationActionInstance,
56          Indexer indexerInstance, Scheduler schedulerInstance,
57          FriendlyURLMapper friendlyURLMapperInstance,
58          URLEncoder urlEncoderInstance,
59          PortletDataHandler portletDataHandlerInstance,
60          PortletLayoutListener portletLayoutListenerInstance,
61          MessageListener smtpMessageListenerInstance,
62          PreferencesValidator prefsValidatorInstance, Map resourceBundles,
63          Map customUserAttributes) {
64  
65          _portletName = portletName;
66          _servletContext = servletContext;
67          _portletInstance = portletInstance;
68          _configurationActionInstance = configurationActionInstance;
69          _indexerInstance = indexerInstance;
70          _schedulerInstance = schedulerInstance;
71          _friendlyURLMapperInstance = friendlyURLMapperInstance;
72          _urlEncoderInstance = urlEncoderInstance;
73          _portletDataHandlerInstance = portletDataHandlerInstance;
74          _portletLayoutListenerInstance = portletLayoutListenerInstance;
75          _smtpMessageListenerInstance = smtpMessageListenerInstance;
76          _prefsValidatorInstance = prefsValidatorInstance;
77          _resourceBundles = resourceBundles;
78          _customUserAttributes = customUserAttributes;
79      }
80  
81      public String getPortletName() {
82          return _portletName;
83      }
84  
85      public ServletContext getServletContext() {
86          return _servletContext;
87      }
88  
89      public Portlet getPortletInstance() {
90          return _portletInstance;
91      }
92  
93      public void removePortletInstance() {
94          _portletInstance = null;
95      }
96  
97      public ConfigurationAction getConfigurationActionInstance() {
98          return _configurationActionInstance;
99      }
100 
101     public Indexer getIndexerInstance() {
102         return _indexerInstance;
103     }
104 
105     public Scheduler getSchedulerInstance() {
106         return _schedulerInstance;
107     }
108 
109     public FriendlyURLMapper getFriendlyURLMapperInstance() {
110         return _friendlyURLMapperInstance;
111     }
112 
113     public URLEncoder getURLEncoderInstance() {
114         return _urlEncoderInstance;
115     }
116 
117     public PortletDataHandler getPortletDataHandlerInstance() {
118         return _portletDataHandlerInstance;
119     }
120 
121     public PortletLayoutListener getPortletLayoutListenerInstance() {
122         return _portletLayoutListenerInstance;
123     }
124 
125     public MessageListener getSmtpMessageListenerInstance() {
126         return _smtpMessageListenerInstance;
127     }
128 
129     public PreferencesValidator getPreferencesValidatorInstance() {
130         return _prefsValidatorInstance;
131     }
132 
133     public ResourceBundle getResourceBundle(Locale locale) {
134         ResourceBundle resourceBundle = (ResourceBundle)_resourceBundles.get(
135             LocaleUtil.toLanguageId(locale));
136 
137         if (resourceBundle == null) {
138             resourceBundle = (ResourceBundle)_resourceBundles.get(
139                 locale.getLanguage());
140 
141             if (resourceBundle == null) {
142                 resourceBundle = (ResourceBundle)_resourceBundles.get(
143                     LocaleUtil.toLanguageId(LocaleUtil.getDefault()));
144             }
145         }
146 
147         return resourceBundle;
148     }
149 
150     public Map getCustomUserAttributes() {
151         return _customUserAttributes;
152     }
153 
154     private String _portletName;
155     private ServletContext _servletContext;
156     private Portlet _portletInstance;
157     private ConfigurationAction _configurationActionInstance;
158     private Indexer _indexerInstance;
159     private Scheduler _schedulerInstance;
160     private FriendlyURLMapper _friendlyURLMapperInstance;
161     private URLEncoder _urlEncoderInstance;
162     private PortletDataHandler _portletDataHandlerInstance;
163     private PortletLayoutListener _portletLayoutListenerInstance;
164     private MessageListener _smtpMessageListenerInstance;
165     private PreferencesValidator _prefsValidatorInstance;
166     private Map _resourceBundles;
167     private Map _customUserAttributes;
168 
169 }