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.Iterator;
23  import java.util.Map;
24  
25  import javax.portlet.PortletMode;
26  import javax.portlet.WindowState;
27  
28  import org.apache.pluto.om.window.PortletWindow;
29  import org.apache.pluto.services.information.PortletURLProvider;
30  
31  public class PortletURLProviderImpl implements PortletURLProvider {
32  
33      private DynamicInformationProviderImpl provider;
34      private PortletWindow portletWindow;
35      private PortletMode mode;
36      private WindowState state;
37      private boolean action;
38      private boolean secure;
39      private boolean clearParameters;
40      private Map parameters;
41  
42      public PortletURLProviderImpl(DynamicInformationProviderImpl provider,
43                                    PortletWindow portletWindow)
44      {
45          this.provider = provider;
46          this.portletWindow = portletWindow;
47      }
48  
49      // PortletURLProvider implementation.
50  
51      public void setPortletMode(PortletMode mode)
52      {
53          this.mode = mode;
54      }
55  
56      public void setWindowState(WindowState state)
57      {
58          this.state = state;
59      }
60  
61      public void setAction()
62      {
63          action = true;
64      }
65  
66      public void setSecure()
67      {
68          secure = true;
69      }
70  
71      public void clearParameters()
72      {
73          clearParameters = true;
74      }
75  
76      public void setParameters(Map parameters)
77      {
78          this.parameters = parameters;
79      }
80  
81      public String toString()
82      {
83          PortalURL url = PortalEnvironment.getPortalEnvironment(provider.request).getRequestedPortalURL();
84  
85          PortalControlParameter controlURL = new PortalControlParameter(url);
86  
87          if (mode != null) {
88              controlURL.setMode(portletWindow, mode);
89          }
90  
91          if (state != null) {
92              controlURL.setState(portletWindow, state);
93          }
94  
95          if (clearParameters) {
96              controlURL.clearRenderParameters(portletWindow);
97          }
98  
99          // set portlet id for associated request parms
100         controlURL.setPortletId(portletWindow);
101         if (action) {
102             controlURL.setAction(portletWindow);
103         }
104 
105 
106         if (parameters != null) {
107             Iterator names = parameters.keySet().iterator();
108             while (names.hasNext()) {
109                 String name = (String)names.next();
110                 Object value = parameters.get(name);
111                 String[] values = value instanceof String ? new String[] {(String)value} : (String[])value;
112                 if (action) {
113                     //					controlURL.setRequestParam(NamespaceMapperAccess.getNamespaceMapper().encode(portletWindow.getId(), name),values);
114                     controlURL.setRequestParam(name,values);
115                 } else {
116                     controlURL.setRenderParam(portletWindow, name, values );
117                 }
118             }
119         }
120 
121         return url.toString(controlURL,new Boolean(secure));
122     }
123 
124 }