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      private PortalURL currentURL;
46  
47      HttpServletRequest request;
48  
49      public DynamicInformationProviderImpl(HttpServletRequest request,
50                                            ServletConfig config)
51      {
52          this.request = request;
53          this.config = config;
54  
55          env        = PortalEnvironment.getPortalEnvironment(request);
56          currentURL = env.getRequestedPortalURL();
57      }
58  
59      // DynamicInformationProviderImpl implementation.
60      
61      public PortletMode getPortletMode(PortletWindow portletWindow)
62      {
63          return env.getPortalControlParameter().getMode(portletWindow);
64      }
65  
66      public PortletURLProvider getPortletURLProvider(PortletWindow portletWindow)
67      {
68          return new PortletURLProviderImpl(this, portletWindow);
69      }
70  
71      public ResourceURLProvider getResourceURLProvider(PortletWindow portletWindow)
72      {
73          return new ResourceURLProviderImpl(this, portletWindow);
74      }
75  
76      public PortletActionProvider getPortletActionProvider(PortletWindow portletWindow)
77      {
78          return new PortletActionProviderImpl(request, config, portletWindow);
79      }
80  
81      public PortletMode getPreviousPortletMode(PortletWindow portletWindow)
82      {
83          return env.getPortalControlParameter().getPrevMode(portletWindow);
84      }
85  
86      public WindowState getPreviousWindowState(PortletWindow portletWindow)
87      {
88          return env.getPortalControlParameter().getPrevState(portletWindow);
89      }
90  
91      public String getResponseContentType()
92      {
93          return "text/html";
94      }
95  
96      public Iterator getResponseContentTypes()
97      {
98          HashSet responseMimeTypes = new HashSet(NumberOfKnownMimetypes);
99          responseMimeTypes.add("text/html");
100 
101         return responseMimeTypes.iterator();
102     }
103 
104     public WindowState getWindowState(PortletWindow portletWindow)
105     {
106         return env.getPortalControlParameter().getState(portletWindow);
107     }
108 
109     public boolean isPortletModeAllowed(PortletMode mode)
110     {
111         //checks whether PortletMode is supported as example
112         String[] supportedModes = Config.getParameters().getStrings("supported.portletmode");
113         for (int i = 0; i < supportedModes.length; i++) {
114             if (supportedModes[i].equalsIgnoreCase(mode.toString())) {
115                 return true;
116             }
117         }
118         return false;
119     }
120 
121     public boolean isWindowStateAllowed(WindowState state)
122     {
123         //checks whether WindowState is supported as example
124         String[] supportedStates = Config.getParameters().getStrings("supported.windowstate");
125         for (int i = 0; i < supportedStates.length; i++) {
126             if (supportedStates[i].equalsIgnoreCase(state.toString())) {
127                 return true;
128             }
129         }
130         return false;
131     }
132 
133 }