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.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  }