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