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.servlet.taglib.BaseBodyTagSupport;
19  import com.liferay.portal.kernel.util.IntegerWrapper;
20  import com.liferay.portal.kernel.util.StringPool;
21  import com.liferay.portal.kernel.util.Validator;
22  import com.liferay.util.PwdGenerator;
23  
24  import javax.servlet.http.HttpServletRequest;
25  import javax.servlet.jsp.JspException;
26  
27  /**
28   * <a href="PanelContainerTag.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   */
32  public class PanelContainerTag extends BaseBodyTagSupport {
33  
34      public int doStartTag() {
35          HttpServletRequest request =
36              (HttpServletRequest)pageContext.getRequest();
37  
38          if (Validator.isNull(_id)) {
39              _id = PwdGenerator.getPassword(PwdGenerator.KEY3, 4);
40          }
41  
42          request.setAttribute(
43              "liferay-ui:panel-container:id", _id);
44          request.setAttribute(
45              "liferay-ui:panel-container:accordion", String.valueOf(_accordion));
46          request.setAttribute(
47              "liferay-ui:panel-container:persistState",
48              String.valueOf(_persistState));
49          request.setAttribute("liferay-ui:panel-container:extended", _extended);
50          request.setAttribute("liferay-ui:panel-container:cssClass", _cssClass);
51          request.setAttribute(
52              "liferay-ui:panel-container:panel-count", new IntegerWrapper());
53  
54          return EVAL_BODY_BUFFERED;
55      }
56  
57      public int doAfterBody() {
58          HttpServletRequest request =
59              (HttpServletRequest)pageContext.getRequest();
60  
61          IntegerWrapper panelCount = (IntegerWrapper)request.getAttribute(
62              "liferay-ui:panel-container:panel-count");
63  
64          if ((panelCount != null) && (panelCount.getValue() == 1)) {
65  
66              bodyContent.clearBody();
67  
68              return EVAL_BODY_AGAIN;
69          }
70          else {
71              return SKIP_BODY;
72          }
73      }
74  
75      public int doEndTag() throws JspException {
76          try {
77              HttpServletRequest request =
78                  (HttpServletRequest)pageContext.getRequest();
79  
80              IntegerWrapper panelCount = (IntegerWrapper)request.getAttribute(
81                  "liferay-ui:panel-container:panel-count");
82  
83              request.removeAttribute("liferay-ui:panel-container:panel-count");
84  
85              if ((panelCount != null) && (panelCount.getValue() >= 1)) {
86                  PortalIncludeUtil.include(pageContext, getStartPage());
87              }
88  
89              writeBodyContent(pageContext.getOut());
90  
91              if ((panelCount != null) && (panelCount.getValue() >= 1)) {
92                  PortalIncludeUtil.include(pageContext, getEndPage());
93              }
94  
95              request.removeAttribute("liferay-ui:panel-container:id");
96              request.removeAttribute("liferay-ui:panel-container:accordion");
97              request.removeAttribute("liferay-ui:panel-container:persistState");
98              request.removeAttribute("liferay-ui:panel-container:extended");
99              request.removeAttribute("liferay-ui:panel-container:cssClass");
100 
101             return EVAL_PAGE;
102         }
103         catch (Exception e) {
104             throw new JspException(e);
105         }
106     }
107 
108     protected String getStartPage() {
109         if (Validator.isNull(_startPage)) {
110             return _START_PAGE;
111         }
112         else {
113             return _startPage;
114         }
115     }
116 
117     public void setStartPage(String startPage) {
118         _startPage = startPage;
119     }
120 
121     protected String getEndPage() {
122         if (Validator.isNull(_endPage)) {
123             return _END_PAGE;
124         }
125         else {
126             return _endPage;
127         }
128     }
129 
130     public void setEndPage(String endPage) {
131         _endPage = endPage;
132     }
133 
134     public void setId(String id) {
135         _id = id;
136     }
137 
138     public void setAccordion(boolean accordion) {
139         _accordion = accordion;
140     }
141 
142     public void setPersistState(boolean persistState) {
143         _persistState = persistState;
144     }
145 
146     public void setExtended(Boolean extended) {
147         _extended = extended;
148     }
149 
150     public void setCssClass(String cssClass) {
151         _cssClass = cssClass;
152     }
153 
154     private static final String _START_PAGE =
155         "/html/taglib/ui/panel_container/start.jsp";
156 
157     private static final String _END_PAGE =
158         "/html/taglib/ui/panel_container/end.jsp";
159 
160     private String _startPage;
161     private String _endPage;
162     private String _id;
163     private boolean _accordion;
164     private boolean _persistState;
165     private Boolean _extended;
166     private String _cssClass = StringPool.BLANK;
167 
168 }