1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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.StringPool;
27  import com.liferay.portal.kernel.util.Validator;
28  
29  import javax.servlet.http.HttpServletRequest;
30  import javax.servlet.jsp.JspException;
31  import javax.servlet.jsp.tagext.BodyContent;
32  import javax.servlet.jsp.tagext.BodyTagSupport;
33  
34  /**
35   * <a href="PanelTag.java.html"><b><i>View Source</i></b></a>
36   *
37   * @author Brian Wing Shun Chan
38   *
39   */
40  public class PanelTag extends BodyTagSupport {
41  
42      public int doStartTag() throws JspException {
43          HttpServletRequest request =
44              (HttpServletRequest)pageContext.getRequest();
45  
46          request.setAttribute("liferay-ui:panel:id", _id);
47          request.setAttribute("liferay-ui:panel:title", _title);
48          request.setAttribute(
49              "liferay-ui:panel:collapsible", String.valueOf(_collapsible));
50          request.setAttribute("liferay-ui:panel:defaultState", _defaultState);
51          request.setAttribute(
52              "liferay-ui:panel:persistState", String.valueOf(_persistState));
53          request.setAttribute(
54              "liferay-ui:panel:extended", String.valueOf(_extended));
55          request.setAttribute("liferay-ui:panel:cssClass", _cssClass);
56  
57          return EVAL_BODY_BUFFERED;
58      }
59  
60      public int doAfterBody() {
61          BodyContent bodyContent = getBodyContent();
62  
63          _bodyContentString = bodyContent.getString();
64  
65          HttpServletRequest request =
66              (HttpServletRequest)pageContext.getRequest();
67  
68          return SKIP_BODY;
69      }
70  
71      public int doEndTag() throws JspException {
72          try {
73              HttpServletRequest request =
74                  (HttpServletRequest)pageContext.getRequest();
75  
76              PortalIncludeUtil.include(pageContext, getStartPage());
77  
78              pageContext.getOut().print(_bodyContentString);
79  
80              PortalIncludeUtil.include(pageContext, getEndPage());
81  
82              return EVAL_PAGE;
83          }
84          catch (Exception e) {
85              throw new JspException(e);
86          }
87      }
88  
89      public String getStartPage() {
90          if (Validator.isNull(_startPage)) {
91              return _START_PAGE;
92          }
93          else {
94              return _startPage;
95          }
96      }
97  
98      public void setStartPage(String startPage) {
99          _startPage = startPage;
100     }
101 
102     public String getEndPage() {
103         if (Validator.isNull(_endPage)) {
104             return _END_PAGE;
105         }
106         else {
107             return _endPage;
108         }
109     }
110 
111     public void setEndPage(String endPage) {
112         _endPage = endPage;
113     }
114 
115     public void setId(String id) {
116         _id = id;
117     }
118 
119     public void setTitle(String title) {
120         _title = title;
121     }
122 
123     public void setCollapsible(boolean collapsible) {
124         _collapsible = collapsible;
125     }
126 
127     public void setDefaultState(String defaultState) {
128         _defaultState = defaultState;
129     }
130 
131     public void setPersistState(boolean persistState) {
132         _persistState = persistState;
133     }
134 
135     public void setExtended(boolean extended) {
136         _extended = extended;
137     }
138 
139     public void setCssClass(String cssClass) {
140         _cssClass = cssClass;
141     }
142 
143     private static final String _START_PAGE = "/html/taglib/ui/panel/start.jsp";
144 
145     private static final String _END_PAGE = "/html/taglib/ui/panel/end.jsp";
146 
147     private String _startPage;
148     private String _endPage;
149     private String _id;
150     private String _title;
151     private boolean _collapsible = true;
152     private String _defaultState = "open";
153     private boolean _persistState = true;
154     private boolean _extended;
155     private String _cssClass = StringPool.BLANK;
156     private String _bodyContentString = StringPool.BLANK;
157 
158 }