1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.apache.bridges.struts;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.kernel.util.HttpUtil;
20  import com.liferay.portlet.PortletResponseImpl;
21  import com.liferay.portlet.PortletURLImplWrapper;
22  
23  import org.apache.portals.bridges.struts.StrutsPortletURL;
24  
25  /**
26   * <a href="LiferayStrutsPortletURLImpl.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Michael Young
29   */
30  public class LiferayStrutsPortletURLImpl extends PortletURLImplWrapper {
31  
32      public LiferayStrutsPortletURLImpl(
33          PortletResponseImpl portletResponseImpl, long plid, String lifecycle) {
34  
35          super(portletResponseImpl, plid, lifecycle);
36      }
37  
38      public void setParameter(String name, String value) {
39          super.setParameter(name, value);
40  
41          // Add parameters from the query string because bridges passes these
42          // through instead of setting them on the portlet URL
43  
44          String decodedValue = HttpUtil.decodeURL(value);
45  
46          try {
47              if (name.equals(StrutsPortletURL.PAGE)) {
48                  String[] urlComponents = decodedValue.split("\\?", 2);
49  
50                  if (urlComponents.length != 2) {
51                      return;
52                  }
53  
54                  String[] nameValue = urlComponents[1].split("\\&");
55  
56                  for (int i = 0; i < nameValue.length; i++) {
57                      String[] nameValuePair = nameValue[i].split("\\=", 2);
58  
59                      if (nameValuePair.length == 2) {
60                          super.setParameter(nameValuePair[0], nameValuePair[1]);
61                      }
62                      else if (nameValuePair.length == 1) {
63                          super.setParameter(nameValuePair[0], "true");
64                      }
65                  }
66              }
67          }
68          catch (Throwable t) {
69              _log.error("Could not parse Struts page query string " + value, t);
70          }
71      }
72  
73      private static Log _log = LogFactoryUtil.getLog(
74          LiferayStrutsPortletURLImpl.class);
75  
76  }