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