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