View Javadoc

1   /*
2    * Copyright 2003,2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  /* 
17  
18   */
19  
20  package org.apache.pluto.portalImpl.core;
21  
22  import java.util.HashSet;
23  import java.util.Iterator;
24  
25  import javax.portlet.PortletMode;
26  import javax.portlet.WindowState;
27  import javax.servlet.ServletConfig;
28  import javax.servlet.http.HttpServletRequest;
29  
30  import org.apache.pluto.om.window.PortletWindow;
31  import org.apache.pluto.portalImpl.services.config.Config;
32  import org.apache.pluto.services.information.DynamicInformationProvider;
33  import org.apache.pluto.services.information.PortletActionProvider;
34  import org.apache.pluto.services.information.PortletURLProvider;
35  import org.apache.pluto.services.information.ResourceURLProvider;
36  
37  
38  public class DynamicInformationProviderImpl implements DynamicInformationProvider {
39  
40      private final static int NumberOfKnownMimetypes = 15;
41  
42      private ServletConfig config;
43  
44      private PortalEnvironment env;
45  
46      HttpServletRequest request;
47  
48      public DynamicInformationProviderImpl(HttpServletRequest request,
49                                            ServletConfig config)
50      {
51          this.request = request;
52          this.config = config;
53  
54          env        = PortalEnvironment.getPortalEnvironment(request);
55      }
56  
57      // DynamicInformationProviderImpl implementation.
58      
59      public PortletMode getPortletMode(PortletWindow portletWindow)
60      {
61          return env.getPortalControlParameter().getMode(portletWindow);
62      }
63  
64      public PortletURLProvider getPortletURLProvider(PortletWindow portletWindow)
65      {
66          return new PortletURLProviderImpl(this, portletWindow);
67      }
68  
69      public ResourceURLProvider getResourceURLProvider(PortletWindow portletWindow)
70      {
71          return new ResourceURLProviderImpl(this, portletWindow);
72      }
73  
74      public PortletActionProvider getPortletActionProvider(PortletWindow portletWindow)
75      {
76          return new PortletActionProviderImpl(request, config, portletWindow);
77      }
78  
79      public PortletMode getPreviousPortletMode(PortletWindow portletWindow)
80      {
81          return env.getPortalControlParameter().getPrevMode(portletWindow);
82      }
83  
84      public WindowState getPreviousWindowState(PortletWindow portletWindow)
85      {
86          return env.getPortalControlParameter().getPrevState(portletWindow);
87      }
88  
89      public String getResponseContentType()
90      {
91          return "text/html";
92      }
93  
94      public Iterator getResponseContentTypes()
95      {
96          HashSet responseMimeTypes = new HashSet(NumberOfKnownMimetypes);
97          responseMimeTypes.add("text/html");
98  
99          return responseMimeTypes.iterator();
100     }
101 
102     public WindowState getWindowState(PortletWindow portletWindow)
103     {
104         return env.getPortalControlParameter().getState(portletWindow);
105     }
106 
107     public boolean isPortletModeAllowed(PortletMode mode)
108     {
109         //checks whether PortletMode is supported as example
110         String[] supportedModes = Config.getParameters().getStrings("supported.portletmode");
111         for (int i = 0; i < supportedModes.length; i++) {
112             if (supportedModes[i].equalsIgnoreCase(mode.toString())) {
113                 return true;
114             }
115         }
116         return false;
117     }
118 
119     public boolean isWindowStateAllowed(WindowState state)
120     {
121         //checks whether WindowState is supported as example
122         String[] supportedStates = Config.getParameters().getStrings("supported.windowstate");
123         for (int i = 0; i < supportedStates.length; i++) {
124             if (supportedStates[i].equalsIgnoreCase(state.toString())) {
125                 return true;
126             }
127         }
128         return false;
129     }
130 
131 }