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() {
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          return SKIP_BODY;
66      }
67  
68      public int doEndTag() throws JspException {
69          try {
70              PortalIncludeUtil.include(pageContext, getStartPage());
71  
72              pageContext.getOut().print(_bodyContentString);
73  
74              PortalIncludeUtil.include(pageContext, getEndPage());
75  
76              return EVAL_PAGE;
77          }
78          catch (Exception e) {
79              throw new JspException(e);
80          }
81      }
82  
83      public String getStartPage() {
84          if (Validator.isNull(_startPage)) {
85              return _START_PAGE;
86          }
87          else {
88              return _startPage;
89          }
90      }
91  
92      public void setStartPage(String startPage) {
93          _startPage = startPage;
94      }
95  
96      public String getEndPage() {
97          if (Validator.isNull(_endPage)) {
98              return _END_PAGE;
99          }
100         else {
101             return _endPage;
102         }
103     }
104 
105     public void setEndPage(String endPage) {
106         _endPage = endPage;
107     }
108 
109     public void setId(String id) {
110         _id = id;
111     }
112 
113     public void setTitle(String title) {
114         _title = title;
115     }
116 
117     public void setCollapsible(boolean collapsible) {
118         _collapsible = collapsible;
119     }
120 
121     public void setDefaultState(String defaultState) {
122         _defaultState = defaultState;
123     }
124 
125     public void setPersistState(boolean persistState) {
126         _persistState = persistState;
127     }
128 
129     public void setExtended(boolean extended) {
130         _extended = extended;
131     }
132 
133     public void setCssClass(String cssClass) {
134         _cssClass = cssClass;
135     }
136 
137     private static final String _START_PAGE = "/html/taglib/ui/panel/start.jsp";
138 
139     private static final String _END_PAGE = "/html/taglib/ui/panel/end.jsp";
140 
141     private String _startPage;
142     private String _endPage;
143     private String _id;
144     private String _title;
145     private boolean _collapsible = true;
146     private String _defaultState = "open";
147     private boolean _persistState = true;
148     private boolean _extended;
149     private String _cssClass = StringPool.BLANK;
150     private String _bodyContentString = StringPool.BLANK;
151 
152 }