1
22
23 package com.liferay.portal.servlet.taglib.portlet;
24
25 import com.liferay.portal.kernel.portlet.LiferayPortletURL;
26 import com.liferay.portal.kernel.util.JavaConstants;
27 import com.liferay.portal.kernel.util.ParamUtil;
28 import com.liferay.portal.kernel.util.StringPool;
29 import com.liferay.portal.kernel.util.Validator;
30 import com.liferay.portlet.PortletConfigImpl;
31 import com.liferay.portlet.RenderResponseImpl;
32 import com.liferay.util.MapUtil;
33
34 import java.util.Map;
35
36 import javax.portlet.PortletMode;
37 import javax.portlet.WindowState;
38
39 import javax.servlet.http.HttpServletRequest;
40 import javax.servlet.jsp.JspException;
41 import javax.servlet.jsp.PageContext;
42
43 import org.apache.commons.logging.Log;
44 import org.apache.commons.logging.LogFactory;
45
46
52 public class ActionURLTagUtil {
53
54 public static String doEndTag(
55 boolean action, String windowState, String portletMode, String var,
56 String varImpl, Boolean secure, String portletName, Boolean anchor,
57 Boolean encrypt, long doAsUserId, Boolean portletConfiguration,
58 Map params, boolean writeOutput, PageContext pageContext)
59 throws JspException {
60
61 try {
62 HttpServletRequest req =
63 (HttpServletRequest)pageContext.getRequest();
64
65 if (portletName == null) {
66 PortletConfigImpl portletConfig =
67 (PortletConfigImpl)req.getAttribute(
68 JavaConstants.JAVAX_PORTLET_CONFIG);
69
70 portletName = portletConfig.getPortletId();
71 }
72
73 RenderResponseImpl renderResponse =
74 (RenderResponseImpl)req.getAttribute(
75 JavaConstants.JAVAX_PORTLET_RESPONSE);
76
77 if (renderResponse == null) {
78 _log.error(
79 "Render response is null because this tag is not being " +
80 "called within the context of a portlet");
81
82 return StringPool.BLANK;
83 }
84
85 LiferayPortletURL portletURL = null;
86
87 if (action) {
88 portletURL = (LiferayPortletURL)renderResponse.createActionURL(
89 portletName);
90 }
91 else {
92 portletURL = (LiferayPortletURL)renderResponse.createRenderURL(
93 portletName);
94 }
95
96 if (Validator.isNotNull(windowState)) {
97 portletURL.setWindowState(new WindowState(windowState));
98 }
99
100 if (Validator.isNotNull(portletMode)) {
101 portletURL.setPortletMode(new PortletMode(portletMode));
102 }
103
104 if (secure != null) {
105 portletURL.setSecure(secure.booleanValue());
106 }
107 else {
108 portletURL.setSecure(req.isSecure());
109 }
110
111 if (anchor != null) {
112 portletURL.setAnchor(anchor.booleanValue());
113 }
114
115 if (encrypt != null) {
116 portletURL.setEncrypt(encrypt.booleanValue());
117 }
118
119 if (doAsUserId > 0) {
120 portletURL.setDoAsUserId(doAsUserId);
121 }
122
123 if ((portletConfiguration != null) &&
124 portletConfiguration.booleanValue()) {
125
126 String returnToFullPageURL = ParamUtil.getString(
127 req, "returnToFullPageURL");
128 String portletResource = ParamUtil.getString(
129 req, "portletResource");
130 String previewWidth = ParamUtil.getString(req, "previewWidth");
131
132 portletURL.setParameter(
133 "struts_action",
134 "/portlet_configuration/edit_configuration");
135 portletURL.setParameter(
136 "returnToFullPageURL", returnToFullPageURL);
137 portletURL.setParameter("portletResource", portletResource);
138 portletURL.setParameter("previewWidth", previewWidth);
139 }
140
141 if (params != null) {
142 MapUtil.merge(portletURL.getParameterMap(), params);
143
144 portletURL.setParameters(params);
145 }
146
147 if (Validator.isNotNull(var)) {
148 pageContext.setAttribute(var, portletURL.toString());
149 }
150 else if (Validator.isNotNull(varImpl)) {
151 pageContext.setAttribute(varImpl, portletURL);
152 }
153 else if (writeOutput) {
154 pageContext.getOut().print(portletURL.toString());
155 }
156
157 return portletURL.toString();
158 }
159 catch (Exception e) {
160 _log.error(e, e);
161
162 throw new JspException(e);
163 }
164 }
165
166 private static Log _log = LogFactory.getLog(ActionURLTagUtil.class);
167
168 }