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