1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.taglib.ui;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.kernel.util.MethodInvoker;
20  import com.liferay.portal.kernel.util.MethodWrapper;
21  import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
22  import com.liferay.portal.kernel.util.StringPool;
23  
24  import javax.servlet.jsp.JspException;
25  import javax.servlet.jsp.PageContext;
26  import javax.servlet.jsp.tagext.TagSupport;
27  
28  /**
29   * <a href="InputPermissionsParamsTag.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Brian Wing Shun Chan
32   * @author Jorge Ferrer
33   */
34  public class InputPermissionsParamsTag extends TagSupport {
35  
36      public static String doTag(
37              String modelName, PageContext pageContext)
38          throws Exception {
39  
40          Object returnObj = null;
41  
42          Thread currentThread = Thread.currentThread();
43  
44          ClassLoader contextClassLoader = currentThread.getContextClassLoader();
45  
46          try {
47              currentThread.setContextClassLoader(
48                  PortalClassLoaderUtil.getClassLoader());
49  
50              MethodWrapper methodWrapper = new MethodWrapper(
51                  _TAG_CLASS, _TAG_DO_END_METHOD,
52                  new Object[] {modelName, pageContext}
53              );
54  
55              returnObj = MethodInvoker.invoke(methodWrapper);
56          }
57          catch (Exception e) {
58              _log.error(e, e);
59          }
60          finally {
61              currentThread.setContextClassLoader(contextClassLoader);
62          }
63  
64          if (returnObj != null) {
65              return returnObj.toString();
66          }
67          else {
68              return StringPool.BLANK;
69          }
70      }
71  
72      public int doEndTag() throws JspException {
73          try {
74              doTag(_modelName, pageContext);
75  
76              return EVAL_PAGE;
77          }
78          catch (Exception e) {
79              throw new JspException(e);
80          }
81      }
82  
83      public void setModelName(String modelName) {
84          _modelName = modelName;
85      }
86  
87      private static final String _TAG_CLASS =
88          "com.liferay.portal.servlet.taglib.ui.InputPermissionsParamsTagUtil";
89  
90      private static final String _TAG_DO_END_METHOD = "doEndTag";
91  
92      private static Log _log = LogFactoryUtil.getLog(
93          InputPermissionsParamsTag.class);
94  
95      private String _modelName;
96  
97  }