KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > portal > information > PortletURLProviderIG


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23 package org.infoglue.deliver.portal.information;
24
25 import java.util.Iterator JavaDoc;
26 import java.util.Map JavaDoc;
27
28 import javax.portlet.PortletMode;
29 import javax.portlet.WindowState;
30
31 import org.apache.pluto.om.window.PortletWindow;
32 import org.apache.pluto.services.information.PortletURLProvider;
33 import org.infoglue.deliver.portal.PortalControlURL;
34
35 /**
36  *
37  * @author jand
38  *
39  */

40 public class PortletURLProviderIG implements PortletURLProvider {
41     // TODO why can't I create a logger here?
42
// this will throw an commons-logger exception
43
//private static final Log log = LogFactory.getLog(PortletURLProviderIG.class);
44

45     private DynamicInformationProviderIG provider;
46     private PortletWindow portletWindow;
47     private PortletMode mode;
48     private WindowState state;
49     private boolean action;
50     private boolean secure;
51     private boolean clearParameters;
52     private Map JavaDoc parameters;
53
54     public PortletURLProviderIG(
55         DynamicInformationProviderIG provider,
56         PortletWindow portletWindow) {
57         this.provider = provider;
58         this.portletWindow = portletWindow;
59     }
60
61     // PortletURLProvider implementation.
62

63     public void setPortletMode(PortletMode mode) {
64         this.mode = mode;
65     }
66
67     public void setWindowState(WindowState state) {
68         this.state = state;
69     }
70
71     public void setAction() {
72         action = true;
73     }
74
75     public void setSecure() {
76         secure = true;
77     }
78
79     public void clearParameters() {
80         clearParameters = true;
81     }
82
83     public void setParameters(Map JavaDoc parameters) {
84         this.parameters = parameters;
85     }
86
87     public String JavaDoc toString() {
88         PortalControlURL url = provider.getPortalURL();
89
90         if (mode != null) {
91             url.setPortletMode(portletWindow, mode);
92         }
93         if (state != null) {
94             url.setPortletWindowState(portletWindow, state);
95         }
96
97         if (clearParameters) {
98             url.clearRenderParameters(portletWindow);
99         }
100
101         /*
102          * If the request does not contain a _pid or an _ac parameter
103          * it is a general request from infoglue. The parameters on the query
104          * is then assumed to be infoglue parameters such as siteNodeId..
105          */

106         // Render request... set _ig parameters
107
if (!url.isTargeted()) {
108             Map JavaDoc params = url.getQueryParameterMap();
109             for (Iterator JavaDoc it = params.keySet().iterator(); it.hasNext();) {
110                 String JavaDoc name = (String JavaDoc) it.next();
111                 String JavaDoc[] values = (String JavaDoc[]) params.get(name);
112                 url.setPathParameter(PortalControlURL.IG + name, values);
113             }
114         }
115         
116         // set portlet id for associated request parms
117
url.clearActionParameter();
118         if (action) {
119             url.setActionParameter(portletWindow);
120         } else {
121             url.setPortletId(portletWindow);
122         }
123
124         url.clearQueryParameters();
125
126         if (parameters != null) {
127             Iterator JavaDoc names = parameters.keySet().iterator();
128             while (names.hasNext()) {
129                 String JavaDoc name = (String JavaDoc) names.next();
130                 Object JavaDoc value = parameters.get(name);
131                 String JavaDoc[] values = value instanceof String JavaDoc ? new String JavaDoc[] {(String JavaDoc) value }
132                 : (String JavaDoc[]) value;
133                 if (action) {
134                     url.setQueryParameter(portletWindow, name, values);
135                 } else {
136                     url.setRenderParameter(portletWindow, name, values);
137                 }
138             }
139         }
140         String JavaDoc str = url.toString();
141         //log.debug("Generated URL: " + str);
142
return str;
143     }
144
145 }
146
Popular Tags