1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.taglib.ui;
21  
22  import com.liferay.portal.kernel.log.Log;
23  import com.liferay.portal.kernel.log.LogFactoryUtil;
24  import com.liferay.portal.kernel.util.MethodInvoker;
25  import com.liferay.portal.kernel.util.MethodWrapper;
26  import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
27  
28  import javax.servlet.http.HttpServletRequest;
29  import javax.servlet.jsp.JspTagException;
30  import javax.servlet.jsp.PageContext;
31  import javax.servlet.jsp.tagext.TagSupport;
32  
33  /**
34   * <a href="ToggleValueTag.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   *
38   */
39  public class ToggleValueTag extends TagSupport {
40  
41      public static void doTag(
42              String id, PageContext pageContext, HttpServletRequest request)
43          throws Exception {
44  
45          Thread currentThread = Thread.currentThread();
46  
47          ClassLoader contextClassLoader = currentThread.getContextClassLoader();
48  
49          try {
50              currentThread.setContextClassLoader(
51                  PortalClassLoaderUtil.getClassLoader());
52  
53              MethodWrapper methodWrapper = new MethodWrapper(
54                  _TAG_CLASS, _TAG_DO_END_METHOD,
55                  new Object[] {id, pageContext, request});
56  
57              MethodInvoker.invoke(methodWrapper);
58          }
59          catch (Exception e) {
60              _log.error(e, e);
61  
62              throw e;
63          }
64          finally {
65              currentThread.setContextClassLoader(contextClassLoader);
66          }
67      }
68  
69      public int doEndTag() throws JspTagException {
70          try {
71              HttpServletRequest request =
72                  (HttpServletRequest)pageContext.getRequest();
73  
74              doTag(_id, pageContext, request);
75  
76              return EVAL_PAGE;
77          }
78          catch (Exception e) {
79              throw new JspTagException(e.getMessage());
80          }
81      }
82  
83      public void setId(String id) {
84          _id = id;
85      }
86  
87      private static final String _TAG_CLASS =
88          "com.liferay.portal.servlet.taglib.ui.ToggleValueTagUtil";
89  
90      private static final String _TAG_DO_END_METHOD = "doEndTag";
91  
92      private static Log _log = LogFactoryUtil.getLog(ToggleValueTag.class);
93  
94      private String _id;
95  
96  }