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.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  public class PanelTag extends BodyTagSupport {
40  
41      public int doStartTag() {
42          HttpServletRequest request =
43              (HttpServletRequest)pageContext.getRequest();
44  
45          request.setAttribute("liferay-ui:panel:id", _id);
46          request.setAttribute("liferay-ui:panel:title", _title);
47          request.setAttribute(
48              "liferay-ui:panel:collapsible", String.valueOf(_collapsible));
49          request.setAttribute("liferay-ui:panel:defaultState", _defaultState);
50          request.setAttribute(
51              "liferay-ui:panel:persistState", String.valueOf(_persistState));
52          request.setAttribute(
53              "liferay-ui:panel:extended", String.valueOf(_extended));
54          request.setAttribute("liferay-ui:panel:cssClass", _cssClass);
55  
56          return EVAL_BODY_BUFFERED;
57      }
58  
59      public int doAfterBody() {
60          BodyContent bodyContent = getBodyContent();
61  
62          _bodyContentString = bodyContent.getString();
63  
64          return SKIP_BODY;
65      }
66  
67      public int doEndTag() throws JspException {
68          try {
69              PortalIncludeUtil.include(pageContext, getStartPage());
70  
71              pageContext.getOut().print(_bodyContentString);
72  
73              PortalIncludeUtil.include(pageContext, getEndPage());
74  
75              return EVAL_PAGE;
76          }
77          catch (Exception e) {
78              throw new JspException(e);
79          }
80      }
81  
82      public String getStartPage() {
83          if (Validator.isNull(_startPage)) {
84              return _START_PAGE;
85          }
86          else {
87              return _startPage;
88          }
89      }
90  
91      public void setStartPage(String startPage) {
92          _startPage = startPage;
93      }
94  
95      public String getEndPage() {
96          if (Validator.isNull(_endPage)) {
97              return _END_PAGE;
98          }
99          else {
100             return _endPage;
101         }
102     }
103 
104     public void setEndPage(String endPage) {
105         _endPage = endPage;
106     }
107 
108     public void setId(String id) {
109         _id = id;
110     }
111 
112     public void setTitle(String title) {
113         _title = title;
114     }
115 
116     public void setCollapsible(boolean collapsible) {
117         _collapsible = collapsible;
118     }
119 
120     public void setDefaultState(String defaultState) {
121         _defaultState = defaultState;
122     }
123 
124     public void setPersistState(boolean persistState) {
125         _persistState = persistState;
126     }
127 
128     public void setExtended(boolean extended) {
129         _extended = extended;
130     }
131 
132     public void setCssClass(String cssClass) {
133         _cssClass = cssClass;
134     }
135 
136     private static final String _START_PAGE = "/html/taglib/ui/panel/start.jsp";
137 
138     private static final String _END_PAGE = "/html/taglib/ui/panel/end.jsp";
139 
140     private String _startPage;
141     private String _endPage;
142     private String _id;
143     private String _title;
144     private boolean _collapsible = true;
145     private String _defaultState = "open";
146     private boolean _persistState = true;
147     private boolean _extended;
148     private String _cssClass = StringPool.BLANK;
149     private String _bodyContentString = StringPool.BLANK;
150 
151 }