1
22
23
41
42 package com.liferay.portal.servlet.taglib.portlet;
43
44 import com.liferay.portal.kernel.portlet.LiferayPortletURL;
45 import com.liferay.portal.kernel.util.JavaConstants;
46 import com.liferay.portal.portletcontainer.LiferayPortletURLImpl;
47 import com.liferay.portal.theme.ThemeDisplay;
48 import com.liferay.portal.util.PropsValues;
49 import com.liferay.portal.util.WebKeys;
50 import com.liferay.portlet.PortletConfigImpl;
51 import com.liferay.portlet.PortletResponseImpl;
52
53 import javax.portlet.PortletRequest;
54
55 import javax.servlet.http.HttpServletRequest;
56
57
63 public class TagUtil {
64
65 public static LiferayPortletURL getLiferayPortletURL(
66 HttpServletRequest request, String portletName, String lifecycle) {
67
68 PortletRequest portletRequest = (PortletRequest)request.getAttribute(
69 JavaConstants.JAVAX_PORTLET_REQUEST);
70
71 if (portletRequest == null) {
72 return null;
73 }
74
75 LiferayPortletURL portletURL = null;
76
77 if (PropsValues.PORTLET_CONTAINER_IMPL_SUN &&
78 _isWARFile(portletRequest)) {
79
80 portletURL = new LiferayPortletURLImpl(
81 request, portletName, portletRequest.getWindowState(),
82 portletRequest.getPortletMode(), _getPlid(request), lifecycle);
83 }
84 else {
85 PortletResponseImpl portletResponse =
86 (PortletResponseImpl)request.getAttribute(
87 JavaConstants.JAVAX_PORTLET_RESPONSE);
88
89 portletURL = portletResponse.createPortletURLImpl(
90 portletName, lifecycle);
91 }
92
93 return portletURL;
94 }
95
96 public static String getPortletName(HttpServletRequest request) {
97 PortletRequest portletRequest = (PortletRequest)request.getAttribute(
98 JavaConstants.JAVAX_PORTLET_REQUEST);
99
100 if (portletRequest == null) {
101 return null;
102 }
103
104 String portletName = null;
105
106 if (PropsValues.PORTLET_CONTAINER_IMPL_SUN &&
107 _isWARFile(portletRequest)) {
108
109 portletName = (String)portletRequest.getAttribute(
110 _PORTLET_CONTAINER_WINDOW_NAME);
111 }
112 else {
113 PortletConfigImpl portletConfig =
114 (PortletConfigImpl)request.getAttribute(
115 JavaConstants.JAVAX_PORTLET_CONFIG);
116
117 portletName = portletConfig.getPortletId();
118 }
119
120 return portletName;
121 }
122
123 private static long _getPlid(HttpServletRequest request) {
124 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
125 WebKeys.THEME_DISPLAY);
126
127 return themeDisplay.getPlid();
128 }
129
130 private static boolean _isWARFile(PortletRequest portletRequest) {
131 Object portletWindowName = portletRequest.getAttribute(
132 _PORTLET_CONTAINER_WINDOW_NAME);
133
134 if (portletWindowName == null) {
135 return false;
136 }
137 else {
138 return true;
139 }
140 }
141
142 private static final String _PORTLET_CONTAINER_WINDOW_NAME =
143 "javax.portlet.portletc.portletWindowName";
144
145 }