1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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.ui;
24  
25  import com.liferay.portal.kernel.util.MethodInvoker;
26  import com.liferay.portal.kernel.util.MethodWrapper;
27  import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
28  import com.liferay.portal.kernel.util.StringPool;
29  import com.liferay.taglib.util.IncludeTag;
30  
31  import javax.servlet.jsp.JspException;
32  import javax.servlet.jsp.PageContext;
33  
34  import org.apache.commons.logging.Log;
35  import org.apache.commons.logging.LogFactory;
36  
37  /**
38   * <a href="InputPermissionsTag.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Brian Wing Shun Chan
41   * @author Wilson S. Man
42   *
43   */
44  public class InputPermissionsTag extends IncludeTag {
45  
46      public static String doTag(
47              String formName, String modelName, PageContext pageContext)
48          throws Exception {
49  
50          return doTag(_PAGE, formName, modelName, pageContext);
51      }
52  
53      public static String doTag(
54              String page, String formName, String modelName,
55              PageContext pageContext)
56          throws Exception {
57  
58          Object returnObj = null;
59  
60          Thread currentThread = Thread.currentThread();
61  
62          ClassLoader contextClassLoader = currentThread.getContextClassLoader();
63  
64          try {
65              currentThread.setContextClassLoader(
66                  PortalClassLoaderUtil.getClassLoader());
67  
68              MethodWrapper methodWrapper = new MethodWrapper(
69                  _TAG_CLASS, _TAG_DO_END_METHOD,
70                  new Object[] {page, formName, modelName, pageContext});
71  
72              returnObj = MethodInvoker.invoke(methodWrapper);
73          }
74          catch (Exception e) {
75              _log.error(e, e);
76          }
77          finally {
78              currentThread.setContextClassLoader(contextClassLoader);
79          }
80  
81          if (returnObj != null) {
82              return returnObj.toString();
83          }
84          else {
85              return StringPool.BLANK;
86          }
87      }
88  
89      public int doEndTag() throws JspException {
90          try {
91              doTag(getPage(), _formName, _modelName, pageContext);
92          }
93          catch (Exception e) {
94              if (e instanceof JspException) {
95                  throw (JspException)e;
96              }
97              else {
98                  throw new JspException(e);
99              }
100         }
101 
102         return EVAL_PAGE;
103     }
104 
105     public void setFormName(String formName) {
106         _formName = formName;
107     }
108 
109     public void setModelName(String modelName) {
110         _modelName = modelName;
111     }
112 
113     protected String getDefaultPage() {
114         return _PAGE;
115     }
116 
117     private static final String _TAG_CLASS =
118         "com.liferay.portal.servlet.taglib.ui.InputPermissionsTagUtil";
119 
120     private static final String _TAG_DO_END_METHOD = "doEndTag";
121 
122     private static final String _PAGE =
123         "/html/taglib/ui/input_permissions/page.jsp";
124 
125     private static Log _log = LogFactory.getLog(InputPermissionsTag.class);
126 
127     private String _formName = "fm";
128     private String _modelName = null;
129 
130 }