1
19
20 package com.liferay.portlet;
21
22 import com.liferay.portal.kernel.portlet.LiferayPortletURL;
23
24 import java.util.Enumeration;
25
26 import javax.portlet.MimeResponse;
27 import javax.portlet.PortletException;
28 import javax.portlet.PortletMode;
29 import javax.portlet.PortletRequest;
30 import javax.portlet.PortletURL;
31 import javax.portlet.WindowState;
32
33
39 public class PortletURLUtil {
40
41 public static PortletURL getCurrent(
42 PortletRequest portletRequest, MimeResponse mimeResponse) {
43
44 PortletURL portletURL = mimeResponse.createRenderURL();
45
46 Enumeration<String> enu = portletRequest.getParameterNames();
47
48 while (enu.hasMoreElements()) {
49 String param = enu.nextElement();
50 String[] values = portletRequest.getParameterValues(param);
51
52 boolean addParam = true;
53
54
56 for (int i = 0; i < values.length; i++) {
57 if (values[i].length() > _CURRENT_URL_PARAMETER_THRESHOLD) {
58 addParam = false;
59
60 break;
61 }
62 }
63
64 if (addParam) {
65 portletURL.setParameter(param, values);
66 }
67 }
68
69 return portletURL;
70 }
71
72 public static PortletURL clone(
73 PortletURL portletURL, MimeResponse mimeResponse)
74 throws PortletException {
75
76 LiferayPortletURL liferayPortletURL = (LiferayPortletURL)portletURL;
77
78 return clone(
79 liferayPortletURL, liferayPortletURL.getLifecycle(), mimeResponse);
80 }
81
82 public static PortletURL clone(
83 PortletURL portletURL, String lifecycle, MimeResponse mimeResponse)
84 throws PortletException {
85
86 LiferayPortletURL liferayPortletURL = (LiferayPortletURL)portletURL;
87
88 return clone(liferayPortletURL, lifecycle, mimeResponse);
89 }
90
91 public static PortletURL clone(
92 LiferayPortletURL liferayPortletURL, String lifecycle,
93 MimeResponse mimeResponse)
94 throws PortletException {
95
96 LiferayPortletURL newURLImpl = null;
97
98 if (lifecycle.equals(PortletRequest.ACTION_PHASE)) {
99 newURLImpl = (LiferayPortletURL)mimeResponse.createActionURL();
100 }
101 else if (lifecycle.equals(PortletRequest.RENDER_PHASE)) {
102 newURLImpl = (LiferayPortletURL)mimeResponse.createRenderURL();
103 }
104
105 newURLImpl.setPortletId(liferayPortletURL.getPortletId());
106
107 WindowState windowState = liferayPortletURL.getWindowState();
108
109 if (windowState != null) {
110 newURLImpl.setWindowState(windowState);
111 }
112
113 PortletMode portletMode = liferayPortletURL.getPortletMode();
114
115 if (portletMode != null) {
116 newURLImpl.setPortletMode(portletMode);
117 }
118
119 newURLImpl.setParameters(liferayPortletURL.getParameterMap());
120
121 return newURLImpl;
122 }
123
124 private static final int _CURRENT_URL_PARAMETER_THRESHOLD = 32768;
125
126 }