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