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