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.util.ServerDetector;
18  import com.liferay.portal.kernel.util.Validator;
19  import com.liferay.taglib.util.ParamAndPropertyAncestorTagImpl;
20  
21  import javax.servlet.http.HttpServletRequest;
22  import javax.servlet.jsp.JspException;
23  
24  /**
25   * <a href="ToggleAreaTag.java.html"><b><i>View Source</i></b></a>
26   *
27   * @author Raymond Augé
28   */
29  public class ToggleAreaTag extends ParamAndPropertyAncestorTagImpl {
30  
31      public int doStartTag() throws JspException {
32          try {
33              HttpServletRequest request =
34                  (HttpServletRequest)pageContext.getRequest();
35  
36              request.setAttribute("liferay-ui:toggle-area:id", _id);
37              request.setAttribute(
38                  "liferay-ui:toggle-area:showImage", _showImage);
39              request.setAttribute(
40                  "liferay-ui:toggle-area:hideImage", _hideImage);
41              request.setAttribute(
42                  "liferay-ui:toggle-area:showMessage", _showMessage);
43              request.setAttribute(
44                  "liferay-ui:toggle-area:hideMessage", _hideMessage);
45              request.setAttribute(
46                  "liferay-ui:toggle-area:defaultShowContent",
47                  String.valueOf(_defaultShowContent));
48              request.setAttribute("liferay-ui:toggle-area:stateVar", _stateVar);
49              request.setAttribute("liferay-ui:toggle-area:align", _align);
50  
51              include(getStartPage());
52  
53              return EVAL_BODY_INCLUDE;
54          }
55          catch (Exception e) {
56              throw new JspException(e);
57          }
58      }
59  
60      public int doEndTag() throws JspException {
61          try {
62              include(getEndPage());
63  
64              return EVAL_PAGE;
65          }
66          catch (Exception e) {
67              throw new JspException(e);
68          }
69          finally {
70              if (!ServerDetector.isResin()) {
71                  _startPage = null;
72                  _endPage = null;
73                  _id = null;
74                  _showMessage = null;
75                  _hideMessage = null;
76                  _defaultShowContent = true;
77                  _stateVar = null;
78                  _align = "left";
79              }
80          }
81      }
82  
83      public String getStartPage() {
84          if (Validator.isNull(_startPage)) {
85              return _START_PAGE;
86          }
87          else {
88              return _startPage;
89          }
90      }
91  
92      public void setStartPage(String startPage) {
93          _startPage = startPage;
94      }
95  
96      public String getEndPage() {
97          if (Validator.isNull(_endPage)) {
98              return _END_PAGE;
99          }
100         else {
101             return _endPage;
102         }
103     }
104 
105     public void setEndPage(String endPage) {
106         _endPage = endPage;
107     }
108 
109     public void setId(String id) {
110         _id = id;
111     }
112 
113     public void setShowImage(String showImage) {
114         _showImage = showImage;
115     }
116 
117     public void setHideImage(String hideImage) {
118         _hideImage = hideImage;
119     }
120 
121     public void setShowMessage(String showMessage) {
122         _showMessage = showMessage;
123     }
124 
125     public void setHideMessage(String hideMessage) {
126         _hideMessage = hideMessage;
127     }
128 
129     public void setDefaultShowContent(boolean defaultShowContent) {
130         _defaultShowContent = defaultShowContent;
131     }
132 
133     public void setStateVar(String stateVar) {
134         _stateVar = stateVar;
135     }
136 
137     public void setAlign(String align) {
138         _align = align;
139     }
140 
141     private static final String _START_PAGE =
142         "/html/taglib/ui/toggle_area/start.jsp";
143 
144     private static final String _END_PAGE =
145         "/html/taglib/ui/toggle_area/end.jsp";
146 
147     private String _startPage;
148     private String _endPage;
149     private String _id;
150     private String _showImage;
151     private String _hideImage;
152     private String _showMessage;
153     private String _hideMessage;
154     private boolean _defaultShowContent = true;
155     private String _stateVar;
156     private String _align = "left";
157 
158 }