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.servlet.PortalIncludeUtil;
26  import com.liferay.portal.kernel.util.IntegerWrapper;
27  import com.liferay.portal.kernel.util.StringPool;
28  import com.liferay.portal.kernel.util.Validator;
29  
30  import javax.servlet.http.HttpServletRequest;
31  import javax.servlet.jsp.JspException;
32  import javax.servlet.jsp.tagext.BodyContent;
33  import javax.servlet.jsp.tagext.BodyTagSupport;
34  
35  /**
36   * <a href="PanelFloatingContainerTag.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Brian Wing Shun Chan
39   *
40   */
41  public class PanelFloatingContainerTag extends BodyTagSupport {
42  
43      public int doStartTag() {
44          HttpServletRequest request =
45              (HttpServletRequest)pageContext.getRequest();
46  
47          request.setAttribute(
48              "liferay-ui:panel-floating-container:id", _id);
49          request.setAttribute(
50              "liferay-ui:panel-floating-container:trigger", _trigger);
51          request.setAttribute(
52              "liferay-ui:panel-floating-container:accordion",
53              String.valueOf(_accordion));
54          request.setAttribute(
55              "liferay-ui:panel-floating-container:persistState",
56              String.valueOf(_persistState));
57          request.setAttribute(
58              "liferay-ui:panel-floating-container:paging",
59              String.valueOf(_paging));
60          request.setAttribute(
61              "liferay-ui:panel-floating-container:pagingElements",
62              _pagingElements);
63          request.setAttribute(
64              "liferay-ui:panel-floating-container:resultsPerPage",
65              String.valueOf(_resultsPerPage));
66          request.setAttribute(
67              "liferay-ui:panel-floating-container:width",
68              String.valueOf(_width));
69          request.setAttribute(
70              "liferay-ui:panel-floating-container:extended", _extended);
71          request.setAttribute(
72              "liferay-ui:panel-floating-container:cssClass", _cssClass);
73          request.setAttribute(
74              "liferay-ui:panel-container:panel-count", new IntegerWrapper());
75  
76          return EVAL_BODY_BUFFERED;
77      }
78  
79      public int doAfterBody() {
80          BodyContent bodyContent = getBodyContent();
81  
82          _bodyContentString = bodyContent.getString();
83  
84          HttpServletRequest request =
85              (HttpServletRequest)pageContext.getRequest();
86  
87          IntegerWrapper panelCount = (IntegerWrapper)request.getAttribute(
88              "liferay-ui:panel-container:panel-count");
89  
90          if ((panelCount != null) && (panelCount.getValue() == 1)) {
91  
92              bodyContent.clearBody();
93  
94              return EVAL_BODY_AGAIN;
95          }
96          else {
97              return SKIP_BODY;
98          }
99      }
100 
101     public int doEndTag() throws JspException {
102         try {
103             HttpServletRequest request =
104                 (HttpServletRequest)pageContext.getRequest();
105 
106             IntegerWrapper panelCount = (IntegerWrapper)request.getAttribute(
107                 "liferay-ui:panel-container:panel-count");
108 
109             request.removeAttribute("liferay-ui:panel-container:panel-count");
110 
111             if ((panelCount != null) && (panelCount.getValue() >= 1)) {
112                 PortalIncludeUtil.include(pageContext, getStartPage());
113             }
114 
115             pageContext.getOut().print(_bodyContentString);
116 
117             if ((panelCount != null) && (panelCount.getValue() >= 1)) {
118                 PortalIncludeUtil.include(pageContext, getEndPage());
119             }
120 
121             request.removeAttribute("liferay-ui:panel-floating-container:id");
122             request.removeAttribute(
123                 "liferay-ui:panel-floating-container:trigger");
124             request.removeAttribute(
125                 "liferay-ui:panel-floating-container:accordion");
126             request.removeAttribute(
127                 "liferay-ui:panel-floating-container:persistState");
128             request.removeAttribute(
129                 "liferay-ui:panel-floating-container:paging");
130             request.removeAttribute(
131                 "liferay-ui:panel-floating-container:pagingElements");
132             request.removeAttribute(
133                 "liferay-ui:panel-floating-container:resultsPerPage");
134             request.removeAttribute(
135                 "liferay-ui:panel-floating-container:width");
136             request.removeAttribute(
137                 "liferay-ui:panel-floating-container:extended");
138             request.removeAttribute(
139                 "liferay-ui:panel-floating-container:cssClass");
140 
141             return EVAL_PAGE;
142         }
143         catch (Exception e) {
144             throw new JspException(e);
145         }
146     }
147 
148     public String getStartPage() {
149         if (Validator.isNull(_startPage)) {
150             return _START_PAGE;
151         }
152         else {
153             return _startPage;
154         }
155     }
156 
157     public void setStartPage(String startPage) {
158         _startPage = startPage;
159     }
160 
161     public String getEndPage() {
162         if (Validator.isNull(_endPage)) {
163             return _END_PAGE;
164         }
165         else {
166             return _endPage;
167         }
168     }
169 
170     public void setEndPage(String endPage) {
171         _endPage = endPage;
172     }
173 
174     public void setId(String id) {
175         _id = id;
176     }
177 
178     public void setTrigger(String trigger) {
179         _trigger = trigger;
180     }
181 
182     public void setAccordion(boolean accordion) {
183         _accordion = accordion;
184     }
185 
186     public void setPersistState(boolean persistState) {
187         _persistState = persistState;
188     }
189 
190     public void setPaging(boolean paging) {
191         _paging = paging;
192     }
193 
194     public void setPagingElements(String pagingElements) {
195         _pagingElements = pagingElements;
196     }
197 
198     public void setResultsPerPage(int resultsPerPage) {
199         _resultsPerPage = resultsPerPage;
200     }
201 
202     public void setWidth(int width) {
203         _width = width;
204     }
205 
206     public void setExtended(Boolean extended) {
207         _extended = extended;
208     }
209 
210     public void setCssClass(String cssClass) {
211         _cssClass = cssClass;
212     }
213 
214     private static final String _START_PAGE =
215         "/html/taglib/ui/panel_floating_container/start.jsp";
216 
217     private static final String _END_PAGE =
218         "/html/taglib/ui/panel_floating_container/end.jsp";
219 
220     private String _startPage;
221     private String _endPage;
222     private String _id;
223     private String _trigger;
224     private boolean _accordion;
225     private boolean _persistState;
226     private boolean _paging;
227     private String _pagingElements = "ul";
228     private int _resultsPerPage = 1;
229     private int _width = 300;
230     private Boolean _extended;
231     private String _cssClass = StringPool.BLANK;
232     private String _bodyContentString = StringPool.BLANK;
233 
234 }