1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.taglib.ui;
16  
17  import com.liferay.portal.kernel.servlet.PortalIncludeUtil;
18  import com.liferay.portal.kernel.servlet.taglib.BaseBodyTagSupport;
19  import com.liferay.portal.kernel.util.StringPool;
20  import com.liferay.portal.kernel.util.Validator;
21  import com.liferay.util.PwdGenerator;
22  
23  import javax.servlet.http.HttpServletRequest;
24  import javax.servlet.jsp.JspException;
25  
26  /**
27   * <a href="PanelTag.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   */
31  public class PanelTag extends BaseBodyTagSupport {
32  
33      public int doStartTag() {
34          HttpServletRequest request =
35              (HttpServletRequest)pageContext.getRequest();
36  
37          if (Validator.isNull(_id)) {
38              _id = PwdGenerator.getPassword(PwdGenerator.KEY3, 4);
39          }
40  
41          request.setAttribute("liferay-ui:panel:id", _id);
42          request.setAttribute("liferay-ui:panel:title", _title);
43          request.setAttribute(
44              "liferay-ui:panel:collapsible", String.valueOf(_collapsible));
45          request.setAttribute("liferay-ui:panel:defaultState", _defaultState);
46          request.setAttribute(
47              "liferay-ui:panel:persistState", String.valueOf(_persistState));
48          request.setAttribute(
49              "liferay-ui:panel:extended", String.valueOf(_extended));
50          request.setAttribute("liferay-ui:panel:cssClass", _cssClass);
51  
52          return EVAL_BODY_BUFFERED;
53      }
54  
55      public int doEndTag() throws JspException {
56          try {
57              PortalIncludeUtil.include(pageContext, getStartPage());
58  
59              writeBodyContent(pageContext.getOut());
60  
61              PortalIncludeUtil.include(pageContext, getEndPage());
62  
63              return EVAL_PAGE;
64          }
65          catch (Exception e) {
66              throw new JspException(e);
67          }
68      }
69  
70      protected String getStartPage() {
71          if (Validator.isNull(_startPage)) {
72              return _START_PAGE;
73          }
74          else {
75              return _startPage;
76          }
77      }
78  
79      public void setStartPage(String startPage) {
80          _startPage = startPage;
81      }
82  
83      protected String getEndPage() {
84          if (Validator.isNull(_endPage)) {
85              return _END_PAGE;
86          }
87          else {
88              return _endPage;
89          }
90      }
91  
92      public void setEndPage(String endPage) {
93          _endPage = endPage;
94      }
95  
96      public void setId(String id) {
97          _id = id;
98      }
99  
100     public void setTitle(String title) {
101         _title = title;
102     }
103 
104     public void setCollapsible(boolean collapsible) {
105         _collapsible = collapsible;
106     }
107 
108     public void setDefaultState(String defaultState) {
109         _defaultState = defaultState;
110     }
111 
112     public void setPersistState(boolean persistState) {
113         _persistState = persistState;
114     }
115 
116     public void setExtended(boolean extended) {
117         _extended = extended;
118     }
119 
120     public void setCssClass(String cssClass) {
121         _cssClass = cssClass;
122     }
123 
124     private static final String _START_PAGE = "/html/taglib/ui/panel/start.jsp";
125 
126     private static final String _END_PAGE = "/html/taglib/ui/panel/end.jsp";
127 
128     private String _startPage;
129     private String _endPage;
130     private String _id;
131     private String _title;
132     private boolean _collapsible = true;
133     private String _defaultState = "open";
134     private boolean _persistState = true;
135     private boolean _extended;
136     private String _cssClass = StringPool.BLANK;
137 
138 }