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