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