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