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