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.struts;
16  
17  import com.liferay.portal.kernel.util.StringPool;
18  import com.liferay.portal.model.Portlet;
19  import com.liferay.portlet.PortletResponseImpl;
20  import com.liferay.portlet.PortletURLImplWrapper;
21  
22  import java.util.Map;
23  
24  /**
25   * <a href="StrutsActionPortletURL.java.html"><b><i>View Source</i></b></a>
26   *
27   * @author Brian Wing Shun Chan
28   */
29  public class StrutsActionPortletURL extends PortletURLImplWrapper {
30  
31      public StrutsActionPortletURL(
32          PortletResponseImpl portletResponseImpl, long plid, String lifecycle) {
33  
34          super(portletResponseImpl, plid, lifecycle);
35  
36          _portlet = portletResponseImpl.getPortlet();
37          _strutsPath =
38              StringPool.SLASH + _portlet.getStrutsPath() + StringPool.SLASH;
39      }
40  
41      public void setParameter(String name, String value) {
42          if (name.equals("struts_action")) {
43              if (!value.startsWith(_strutsPath)) {
44                  int pos = value.lastIndexOf(StringPool.SLASH);
45  
46                  value = _strutsPath + value.substring(pos + 1, value.length());
47              }
48          }
49  
50          super.setParameter(name, value);
51      }
52  
53      public void setParameters(Map<String, String[]> params) {
54          for (Map.Entry<String, String[]> entry : params.entrySet()) {
55              String name = entry.getKey();
56              String[] values = entry.getValue();
57  
58              if (name.equals("struts_action")) {
59                  for (int i = 0; i < values.length; i++) {
60                      String value = values[i];
61  
62                      if (!value.startsWith(_strutsPath)) {
63                          int pos = value.lastIndexOf(StringPool.SLASH);
64  
65                          value =
66                              _strutsPath +
67                                  value.substring(pos + 1, value.length());
68  
69                          values[i] = value;
70                      }
71                  }
72              }
73          }
74  
75          super.setParameters(params);
76      }
77  
78      private Portlet _portlet;
79      private String _strutsPath;
80  
81  }