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