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.aui;
16  
17  import com.liferay.portal.kernel.util.ServerDetector;
18  
19  import javax.servlet.jsp.JspException;
20  import javax.servlet.jsp.tagext.BodyTagSupport;
21  
22  /**
23   * <a href="ModelContextTag.java.html"><b><i>View Source</i></b></a>
24   *
25   * @author Jorge Ferrer
26   * @author Brian Wing Shun Chan
27   */
28  public class ModelContextTag extends BodyTagSupport {
29  
30      public int doEndTag() throws JspException {
31          try{
32              return super.doEndTag();
33          }
34          catch (Exception e) {
35              throw new JspException(e);
36          }
37          finally {
38              if (!ServerDetector.isResin()) {
39                  _bean = null;
40                  _model = null;
41              }
42          }
43      }
44  
45      public int doStartTag() {
46          if (_model != null) {
47              pageContext.setAttribute("aui:model-context:bean", _bean);
48              pageContext.setAttribute("aui:model-context:model", _model);
49          }
50          else {
51              pageContext.removeAttribute("aui:model-context:bean");
52              pageContext.removeAttribute("aui:model-context::model");
53          }
54  
55          return SKIP_BODY;
56      }
57  
58      public void setBean(Object bean) {
59          _bean = bean;
60      }
61  
62      public void setModel(Class<?> model) {
63          _model = model;
64      }
65  
66      private Object _bean;
67      private Class<?> _model;
68  
69  }