1   /**
2    * Copyright (c) 2000-2008 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.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.PortletLayoutListener;
31  import com.liferay.portal.kernel.search.Indexer;
32  import com.liferay.portal.kernel.servlet.URLEncoder;
33  import com.liferay.portal.kernel.util.LocaleUtil;
34  import com.liferay.portal.model.ActivityTrackerInterpreter;
35  
36  import java.util.Locale;
37  import java.util.Map;
38  import java.util.ResourceBundle;
39  
40  import javax.portlet.Portlet;
41  import javax.portlet.PreferencesValidator;
42  
43  import javax.servlet.ServletContext;
44  
45  /**
46   * <a href="PortletContextWrapper.java.html"><b><i>View Source</i></b></a>
47   *
48   * @author Brian Wing Shun Chan
49   *
50   */
51  public class PortletContextWrapper {
52  
53      public PortletContextWrapper(
54          String portletName, ServletContext  servletContext,
55          Portlet portletInstance,
56          ConfigurationAction configurationActionInstance,
57          Indexer indexerInstance, Scheduler schedulerInstance,
58          FriendlyURLMapper friendlyURLMapperInstance,
59          URLEncoder urlEncoderInstance,
60          PortletDataHandler portletDataHandlerInstance,
61          PortletLayoutListener portletLayoutListenerInstance,
62          ActivityTrackerInterpreter activityTrackerInterpreterInstance,
63          MessageListener popMessageListenerInstance,
64          PreferencesValidator prefsValidatorInstance, Map resourceBundles,
65          Map customUserAttributes) {
66  
67          _portletName = portletName;
68          _servletContext = servletContext;
69          _portletInstance = portletInstance;
70          _configurationActionInstance = configurationActionInstance;
71          _indexerInstance = indexerInstance;
72          _schedulerInstance = schedulerInstance;
73          _friendlyURLMapperInstance = friendlyURLMapperInstance;
74          _urlEncoderInstance = urlEncoderInstance;
75          _portletDataHandlerInstance = portletDataHandlerInstance;
76          _portletLayoutListenerInstance = portletLayoutListenerInstance;
77          _activityTrackerInterpreterInstance =
78              activityTrackerInterpreterInstance;
79          _popMessageListenerInstance = popMessageListenerInstance;
80          _prefsValidatorInstance = prefsValidatorInstance;
81          _resourceBundles = resourceBundles;
82          _customUserAttributes = customUserAttributes;
83      }
84  
85      public String getPortletName() {
86          return _portletName;
87      }
88  
89      public ServletContext getServletContext() {
90          return _servletContext;
91      }
92  
93      public Portlet getPortletInstance() {
94          return _portletInstance;
95      }
96  
97      public void removePortletInstance() {
98          _portletInstance = null;
99      }
100 
101     public ConfigurationAction getConfigurationActionInstance() {
102         return _configurationActionInstance;
103     }
104 
105     public Indexer getIndexerInstance() {
106         return _indexerInstance;
107     }
108 
109     public Scheduler getSchedulerInstance() {
110         return _schedulerInstance;
111     }
112 
113     public FriendlyURLMapper getFriendlyURLMapperInstance() {
114         return _friendlyURLMapperInstance;
115     }
116 
117     public URLEncoder getURLEncoderInstance() {
118         return _urlEncoderInstance;
119     }
120 
121     public PortletDataHandler getPortletDataHandlerInstance() {
122         return _portletDataHandlerInstance;
123     }
124 
125     public PortletLayoutListener getPortletLayoutListenerInstance() {
126         return _portletLayoutListenerInstance;
127     }
128 
129     public ActivityTrackerInterpreter getActivityTrackerInterpreterInstance() {
130         return _activityTrackerInterpreterInstance;
131     }
132 
133     public MessageListener getPopMessageListenerInstance() {
134         return _popMessageListenerInstance;
135     }
136 
137     public PreferencesValidator getPreferencesValidatorInstance() {
138         return _prefsValidatorInstance;
139     }
140 
141     public ResourceBundle getResourceBundle(Locale locale) {
142         ResourceBundle resourceBundle = (ResourceBundle)_resourceBundles.get(
143             LocaleUtil.toLanguageId(locale));
144 
145         if (resourceBundle == null) {
146             resourceBundle = (ResourceBundle)_resourceBundles.get(
147                 locale.getLanguage());
148 
149             if (resourceBundle == null) {
150                 resourceBundle = (ResourceBundle)_resourceBundles.get(
151                     LocaleUtil.toLanguageId(LocaleUtil.getDefault()));
152             }
153         }
154 
155         return resourceBundle;
156     }
157 
158     public Map getCustomUserAttributes() {
159         return _customUserAttributes;
160     }
161 
162     private String _portletName;
163     private ServletContext _servletContext;
164     private Portlet _portletInstance;
165     private ConfigurationAction _configurationActionInstance;
166     private Indexer _indexerInstance;
167     private Scheduler _schedulerInstance;
168     private FriendlyURLMapper _friendlyURLMapperInstance;
169     private URLEncoder _urlEncoderInstance;
170     private PortletDataHandler _portletDataHandlerInstance;
171     private PortletLayoutListener _portletLayoutListenerInstance;
172     private ActivityTrackerInterpreter _activityTrackerInterpreterInstance;
173     private MessageListener _popMessageListenerInstance;
174     private PreferencesValidator _prefsValidatorInstance;
175     private Map _resourceBundles;
176     private Map _customUserAttributes;
177 
178 }