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  import com.liferay.taglib.util.IncludeTag;
24  
25  import javax.servlet.jsp.JspException;
26  import javax.servlet.jsp.PageContext;
27  
28  /**
29   * <a href="InputPermissionsTag.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Brian Wing Shun Chan
32   * @author Wilson S. Man
33   */
34  public class InputPermissionsTag extends IncludeTag {
35  
36      public static String doTag(
37              String formName, String modelName, PageContext pageContext)
38          throws Exception {
39  
40          return doTag(_PAGE, formName, modelName, pageContext);
41      }
42  
43      public static String doTag(
44              String page, String formName, String modelName,
45              PageContext pageContext)
46          throws Exception {
47  
48          Object returnObj = null;
49  
50          Thread currentThread = Thread.currentThread();
51  
52          ClassLoader contextClassLoader = currentThread.getContextClassLoader();
53  
54          try {
55              currentThread.setContextClassLoader(
56                  PortalClassLoaderUtil.getClassLoader());
57  
58              MethodWrapper methodWrapper = new MethodWrapper(
59                  _TAG_CLASS, _TAG_DO_END_METHOD,
60                  new Object[] {page, formName, modelName, pageContext});
61  
62              returnObj = MethodInvoker.invoke(methodWrapper);
63          }
64          catch (Exception e) {
65              _log.error(e, e);
66          }
67          finally {
68              currentThread.setContextClassLoader(contextClassLoader);
69          }
70  
71          if (returnObj != null) {
72              return returnObj.toString();
73          }
74          else {
75              return StringPool.BLANK;
76          }
77      }
78  
79      public int doEndTag() throws JspException {
80          try {
81              doTag(getPage(), _formName, _modelName, pageContext);
82  
83              return EVAL_PAGE;
84          }
85          catch (Exception e) {
86              throw new JspException(e);
87          }
88      }
89  
90      public void setFormName(String formName) {
91          _formName = formName;
92      }
93  
94      public void setModelName(String modelName) {
95          _modelName = modelName;
96      }
97  
98      protected String getDefaultPage() {
99          return _PAGE;
100     }
101 
102     private static final String _TAG_CLASS =
103         "com.liferay.portal.servlet.taglib.ui.InputPermissionsTagUtil";
104 
105     private static final String _TAG_DO_END_METHOD = "doEndTag";
106 
107     private static final String _PAGE =
108         "/html/taglib/ui/input_permissions/page.jsp";
109 
110     private static Log _log = LogFactoryUtil.getLog(InputPermissionsTag.class);
111 
112     private String _formName = "fm";
113     private String _modelName = null;
114 
115 }