View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.jetspeed.services.information;
18  
19  import java.util.Iterator;
20  import java.util.HashSet;
21  import javax.servlet.ServletConfig;
22  import javax.servlet.http.HttpServletRequest;
23  import javax.portlet.WindowState;
24  import javax.portlet.PortletMode;
25  
26  import org.apache.pluto.services.information.DynamicInformationProvider;
27  import org.apache.pluto.services.information.PortletActionProvider;
28  import org.apache.pluto.services.information.ResourceURLProvider;
29  import org.apache.pluto.om.window.PortletWindow;
30  import org.apache.pluto.services.information.PortletURLProvider;
31  import org.apache.jetspeed.container.state.MutableNavigationalState;
32  import org.apache.jetspeed.container.state.NavigationalState;
33  import org.apache.jetspeed.engine.core.PortletActionProviderImpl;
34  import org.apache.jetspeed.request.RequestContext;
35  import org.apache.jetspeed.request.RequestContextComponent;
36  import org.apache.jetspeed.Jetspeed;
37  
38  /***
39   * Provides dynamic information to Pluto Container:
40   * 
41   * 1.  getPortletURL
42   * 2.  getRequestMimetype
43   * 3.  getResponseMimetype
44   * 4.  getResponseMimetypes
45   * 5.  getPortletMode
46   * 6.  getPreviousPortletMode
47   * 7.  getWindowState
48   * 8.  getPreviousWindowState
49   * 9.  isPortletModeAllowed
50   * 10. isWindowStateAllowed
51   * 11. getSupportedPortletModes
52   * 12. getSupportedWindowStates
53   * 13. getAllParameters
54   *
55   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
56   * @version $Id: DynamicInformationProviderImpl.java 517719 2007-03-13 15:05:48Z ate $
57   */
58  public class DynamicInformationProviderImpl implements DynamicInformationProvider
59  {
60      HttpServletRequest request = null;
61      ServletConfig config = null;
62  
63      RequestContext context;
64      
65      public DynamicInformationProviderImpl(HttpServletRequest request,
66                                            ServletConfig config)
67      {
68          this.request = request;
69          this.config = config;
70          
71          // TODO: assemble this dependency when this provider is converted to a component
72          RequestContextComponent rcc = (RequestContextComponent)Jetspeed.getComponentManager().getComponent(RequestContextComponent.class);
73          this.context = rcc.getRequestContext(request);
74      }
75  
76      public PortletURLProvider getPortletURLProvider(PortletWindow portletWindow)
77      {
78          return new PortletURLProviderImpl(this.context, portletWindow);
79      }
80  
81       public String getRequestContentType()
82       {
83           return context.getMimeType().toString();
84       }
85  
86       public String getResponseContentType()
87       {
88           return context.getMimeType().toString();
89       }
90  
91       public Iterator getResponseContentTypes()
92       {
93          HashSet responseMimeTypes = new HashSet(NumberOfKnownMimetypes);
94          // TODO: need to integrate with capability code       
95          responseMimeTypes.add("text/html");
96   
97          return responseMimeTypes.iterator();
98       }
99  
100      public PortletMode getPortletMode(PortletWindow portletWindow)
101      {
102          NavigationalState navState = context.getPortalURL().getNavigationalState();
103          return navState.getMode(portletWindow);
104      }
105 
106      public WindowState getWindowState(PortletWindow portletWindow)
107      {
108          NavigationalState navState = context.getPortalURL().getNavigationalState();         
109          return navState.getState(portletWindow);
110      }
111 
112     public boolean isPortletModeAllowed(PortletMode mode)
113     {
114         return Jetspeed.getContext().isPortletModeAllowed(mode);
115     }
116 
117     public boolean isWindowStateAllowed(WindowState state)
118     {
119         return Jetspeed.getContext().isWindowStateAllowed(state);
120     }
121     
122     public String getBasePortalURL()
123     {
124          return context.getPortalURL().getBaseURL();
125     }
126 
127     /*
128     private Map getAllParameters(PortletWindow portletWindow)
129     {
130         Enumeration parameters = request.getParameterNames();
131 
132         Map portletParameters = new HashMap();
133 
134         NamespaceMapper namespaceMapper = ((NamespaceMapperFactory) Jetspeed.getComponentManager().getComponent(
135                 org.apache.pluto.util.NamespaceMapper.class)).getNamespaceMapper();
136         while (parameters.hasMoreElements())
137         {
138             String name = (String)parameters.nextElement();
139 
140             String portletParameter = namespaceMapper.decode(portletWindow.getId(),name);
141 
142             if (portletParameter!=null) // it is in the portlet's namespace
143             {
144                 portletParameters.put(portletParameter, request.getParameterValues(name) );
145             }
146         }
147 
148         PortalURL url = context.getPortalURL();
149         
150         Iterator iterator = url.getNavigationalState().getParameterNames(portletWindow);
151         while (iterator.hasNext())
152         {
153             String name = (String)iterator.next();
154 
155             String[] values = url.getNavigationalState().getParameterValues(portletWindow, name);
156 
157             portletParameters.put(name, values );
158 
159         }
160 
161         return portletParameters;
162     }
163     */
164 
165     private final static int NumberOfKnownMimetypes = 15;
166 
167     
168     /*** 
169      * <p>
170      * getPortletActionProvider
171      * </p>
172      * 
173      * @see org.apache.pluto.services.information.DynamicInformationProvider#getPortletActionProvider(org.apache.pluto.om.window.PortletWindow)
174      * @param arg0
175      * @return
176      */
177     public PortletActionProvider getPortletActionProvider(PortletWindow window)
178     {        
179         return new PortletActionProviderImpl((MutableNavigationalState)context.getPortalURL().getNavigationalState(), window);
180     }
181 
182     /*** 
183      * <p>
184      * getResourceURLProvider
185      * </p>
186      * 
187      * @see org.apache.pluto.services.information.DynamicInformationProvider#getResourceURLProvider(org.apache.pluto.om.window.PortletWindow)
188      * @param arg0
189      * @return
190      */
191     public ResourceURLProvider getResourceURLProvider(PortletWindow window)
192     {
193         
194         return new ResourceURLProviderImpl(this.context, window);
195     }
196 
197 }