1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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  }