1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.taglib.portlet;
24  
25  import com.liferay.portal.kernel.log.Log;
26  import com.liferay.portal.kernel.log.LogFactoryUtil;
27  import com.liferay.portal.kernel.util.BooleanWrapper;
28  import com.liferay.portal.kernel.util.LongWrapper;
29  import com.liferay.portal.kernel.util.MethodInvoker;
30  import com.liferay.portal.kernel.util.MethodWrapper;
31  import com.liferay.portal.kernel.util.NullWrapper;
32  import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
33  import com.liferay.portal.kernel.util.StringPool;
34  import com.liferay.portal.model.LayoutConstants;
35  import com.liferay.taglib.util.ParamAndPropertyAncestorTagImpl;
36  
37  import java.util.Map;
38  
39  import javax.portlet.PortletRequest;
40  
41  import javax.servlet.jsp.JspException;
42  import javax.servlet.jsp.PageContext;
43  
44  /**
45   * <a href="ActionURLTag.java.html"><b><i>View Source</i></b></a>
46   *
47   * @author Brian Wing Shun Chan
48   */
49  public class ActionURLTag extends ParamAndPropertyAncestorTagImpl {
50  
51      public static String doTag(
52              String lifecycle, String windowState, String portletMode,
53              String var, String varImpl, Boolean secure,
54              Boolean copyCurrentRenderParameters, Boolean escapeXml, String name,
55              String resourceID, String cacheability, long plid,
56              String portletName, Boolean anchor, Boolean encrypt,
57              long doAsUserId, Boolean portletConfiguration,
58              Map<String, String[]> params, boolean writeOutput,
59              PageContext pageContext)
60          throws Exception {
61  
62          Object returnObj = null;
63  
64          Thread currentThread = Thread.currentThread();
65  
66          ClassLoader contextClassLoader = currentThread.getContextClassLoader();
67  
68          try {
69              currentThread.setContextClassLoader(
70                  PortalClassLoaderUtil.getClassLoader());
71  
72              Object windowStateWrapper = windowState;
73  
74              if (windowStateWrapper == null) {
75                  windowStateWrapper = new NullWrapper(String.class.getName());
76              }
77  
78              Object portletModeWrapper = portletMode;
79  
80              if (portletModeWrapper == null) {
81                  portletModeWrapper = new NullWrapper(String.class.getName());
82              }
83  
84              Object varWrapper = var;
85  
86              if (varWrapper == null) {
87                  varWrapper = new NullWrapper(String.class.getName());
88              }
89  
90              Object varImplWrapper = varImpl;
91  
92              if (varImplWrapper == null) {
93                  varImplWrapper = new NullWrapper(String.class.getName());
94              }
95  
96              Object secureWrapper = secure;
97  
98              if (secureWrapper == null) {
99                  secureWrapper = new NullWrapper(Boolean.class.getName());
100             }
101 
102             Object copyCurrentRenderParametersWrapper =
103                 copyCurrentRenderParameters;
104 
105             if (copyCurrentRenderParametersWrapper == null) {
106                 copyCurrentRenderParametersWrapper = new NullWrapper(
107                     Boolean.class.getName());
108             }
109 
110             Object escapeXmlWrapper = escapeXml;
111 
112             if (escapeXmlWrapper == null) {
113                 escapeXmlWrapper = new NullWrapper(Boolean.class.getName());
114             }
115 
116             Object nameWrapper = name;
117 
118             if (nameWrapper == null) {
119                 nameWrapper = new NullWrapper(String.class.getName());
120             }
121 
122             Object resourceIDWrapper = resourceID;
123 
124             if (resourceIDWrapper == null) {
125                 resourceIDWrapper = new NullWrapper(String.class.getName());
126             }
127 
128             Object cacheabilityWrapper = cacheability;
129 
130             if (cacheabilityWrapper == null) {
131                 cacheabilityWrapper = new NullWrapper(String.class.getName());
132             }
133 
134             Object portletNameWrapper = portletName;
135 
136             if (portletNameWrapper == null) {
137                 portletNameWrapper = new NullWrapper(String.class.getName());
138             }
139 
140             Object anchorWrapper = anchor;
141 
142             if (anchorWrapper == null) {
143                 anchorWrapper = new NullWrapper(Boolean.class.getName());
144             }
145 
146             Object encryptWrapper = encrypt;
147 
148             if (encryptWrapper == null) {
149                 encryptWrapper = new NullWrapper(Boolean.class.getName());
150             }
151 
152             Object portletConfigurationWrapper = portletConfiguration;
153 
154             if (portletConfigurationWrapper == null) {
155                 portletConfigurationWrapper = new NullWrapper(
156                     Boolean.class.getName());
157             }
158 
159             Object paramsWrapper = params;
160 
161             if (paramsWrapper == null) {
162                 paramsWrapper = new NullWrapper(Map.class.getName());
163             }
164 
165             MethodWrapper methodWrapper = new MethodWrapper(
166                 _TAG_CLASS, _TAG_DO_END_METHOD,
167                 new Object[] {
168                     lifecycle, windowStateWrapper, portletModeWrapper,
169                     varWrapper, varImplWrapper, secureWrapper,
170                     copyCurrentRenderParametersWrapper, escapeXmlWrapper,
171                     nameWrapper, resourceIDWrapper, cacheabilityWrapper,
172                     new LongWrapper(plid), portletNameWrapper, anchorWrapper,
173                     encryptWrapper, new LongWrapper(doAsUserId),
174                     portletConfigurationWrapper, paramsWrapper,
175                     new BooleanWrapper(writeOutput), pageContext
176                 });
177 
178             returnObj = MethodInvoker.invoke(methodWrapper);
179         }
180         catch (Exception e) {
181             _log.error(e, e);
182 
183             throw e;
184         }
185         finally {
186             currentThread.setContextClassLoader(contextClassLoader);
187         }
188 
189         if (returnObj != null) {
190             return returnObj.toString();
191         }
192         else {
193             return StringPool.BLANK;
194         }
195     }
196 
197     public int doEndTag() throws JspException {
198         try {
199             doTag(
200                 getLifecycle(), _windowState, _portletMode, _var, _varImpl,
201                 _secure, _copyCurrentRenderParameters, _escapeXml, _name,
202                 _resourceID, _cacheability, _plid, _portletName, _anchor,
203                 _encrypt, _doAsUserId, _portletConfiguration, getParams(), true,
204                 pageContext);
205         }
206         catch (Exception e) {
207             if (e instanceof JspException) {
208                 throw (JspException)e;
209             }
210             else {
211                 throw new JspException(e);
212             }
213         }
214         finally {
215             clearParams();
216             clearProperties();
217 
218             _plid = LayoutConstants.DEFAULT_PLID;
219         }
220 
221         return EVAL_PAGE;
222     }
223 
224     public String getLifecycle() {
225         return PortletRequest.ACTION_PHASE;
226     }
227 
228     public void setWindowState(String windowState) {
229         _windowState = windowState;
230     }
231 
232     public void setPortletMode(String portletMode) {
233         _portletMode = portletMode;
234     }
235 
236     public void setVar(String var) {
237         _var = var;
238     }
239 
240     public void setVarImpl(String varImpl) {
241         _varImpl = varImpl;
242     }
243 
244     public void setSecure(boolean secure) {
245         _secure = Boolean.valueOf(secure);
246     }
247 
248     public void setCopyCurrentRenderParameters(
249         boolean copyCurrentRenderParameters) {
250 
251         _copyCurrentRenderParameters = Boolean.valueOf(
252             copyCurrentRenderParameters);
253     }
254 
255     public void setEscapeXml(boolean escapeXml) {
256         _escapeXml = Boolean.valueOf(escapeXml);
257     }
258 
259     public void setName(String name) {
260         _name = name;
261     }
262 
263     public void setId(String resourceID) {
264         _resourceID = resourceID;
265     }
266 
267     public void setCacheability(String cacheability) {
268         _cacheability = cacheability;
269     }
270 
271     public void setPlid(long plid) {
272         _plid = plid;
273     }
274 
275     public void setPortletName(String portletName) {
276         _portletName = portletName;
277     }
278 
279     public void setAnchor(boolean anchor) {
280         _anchor = Boolean.valueOf(anchor);
281     }
282 
283     public void setEncrypt(boolean encrypt) {
284         _encrypt = Boolean.valueOf(encrypt);
285     }
286 
287     public void setDoAsUserId(long doAsUserId) {
288         _doAsUserId = doAsUserId;
289     }
290 
291     public void setPortletConfiguration(boolean portletConfiguration) {
292         _portletConfiguration = Boolean.valueOf(portletConfiguration);
293     }
294 
295     private static final String _TAG_CLASS =
296         "com.liferay.portal.servlet.taglib.portlet.ActionURLTagUtil";
297 
298     private static final String _TAG_DO_END_METHOD = "doEndTag";
299 
300     private static Log _log = LogFactoryUtil.getLog(ActionURLTag.class);
301 
302     private String _windowState;
303     private String _portletMode;
304     private String _var;
305     private String _varImpl;
306     private Boolean _secure;
307     private Boolean _copyCurrentRenderParameters;
308     private Boolean _escapeXml;
309     private String  _name;
310     private String _resourceID;
311     private String _cacheability;
312     private long _plid = LayoutConstants.DEFAULT_PLID;
313     private String _portletName;
314     private Boolean _anchor;
315     private Boolean _encrypt;
316     private long _doAsUserId;
317     private Boolean _portletConfiguration;
318 
319 }