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 backURL = ParamUtil.getString(req, "backURL");
127 String portletResource = ParamUtil.getString(
128 req, "portletResource");
129 String previewWidth = ParamUtil.getString(req, "previewWidth");
130
131 portletURL.setParameter(
132 "struts_action",
133 "/portlet_configuration/edit_configuration");
134 portletURL.setParameter("backURL", backURL);
135 portletURL.setParameter("portletResource", portletResource);
136 portletURL.setParameter("previewWidth", previewWidth);
137 }
138
139 if (params != null) {
140 MapUtil.merge(portletURL.getParameterMap(), params);
141
142 portletURL.setParameters(params);
143 }
144
145 if (Validator.isNotNull(var)) {
146 pageContext.setAttribute(var, portletURL.toString());
147 }
148 else if (Validator.isNotNull(varImpl)) {
149 pageContext.setAttribute(varImpl, portletURL);
150 }
151 else if (writeOutput) {
152 pageContext.getOut().print(portletURL.toString());
153 }
154
155 return portletURL.toString();
156 }
157 catch (Exception e) {
158 _log.error(e, e);
159
160 throw new JspException(e);
161 }
162 }
163
164 private static Log _log = LogFactory.getLog(ActionURLTagUtil.class);
165
166 }