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="PanelContainerTag.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   */
32  public class PanelContainerTag extends BodyTagSupport {
33  
34      public int doStartTag() {
35          HttpServletRequest request =
36              (HttpServletRequest)pageContext.getRequest();
37  
38          request.setAttribute(
39              "liferay-ui:panel-container:id", _id);
40          request.setAttribute(
41              "liferay-ui:panel-container:accordion", String.valueOf(_accordion));
42          request.setAttribute(
43              "liferay-ui:panel-container:persistState",
44              String.valueOf(_persistState));
45          request.setAttribute("liferay-ui:panel-container:extended", _extended);
46          request.setAttribute("liferay-ui:panel-container:cssClass", _cssClass);
47          request.setAttribute(
48              "liferay-ui:panel-container:panel-count", new IntegerWrapper());
49  
50          return EVAL_BODY_BUFFERED;
51      }
52  
53      public int doAfterBody() {
54          BodyContent bodyContent = getBodyContent();
55  
56          _bodyContentString = bodyContent.getString();
57  
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              pageContext.getOut().print(_bodyContentString);
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     public 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     public 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     private String _bodyContentString = StringPool.BLANK;
168 
169 }