001
014
015 package com.liferay.taglib.ui;
016
017 import com.liferay.portal.kernel.util.IntegerWrapper;
018 import com.liferay.portal.kernel.util.ServerDetector;
019 import com.liferay.portal.kernel.util.StringUtil;
020 import com.liferay.portal.kernel.util.Validator;
021 import com.liferay.taglib.BaseBodyTagSupport;
022 import com.liferay.taglib.util.PortalIncludeUtil;
023
024 import javax.servlet.http.HttpServletRequest;
025 import javax.servlet.jsp.JspException;
026 import javax.servlet.jsp.tagext.BodyTag;
027
028
031 public class PanelContainerTag extends BaseBodyTagSupport implements BodyTag {
032
033 @Override
034 public int doAfterBody() {
035 HttpServletRequest request =
036 (HttpServletRequest)pageContext.getRequest();
037
038 IntegerWrapper panelCount = (IntegerWrapper)request.getAttribute(
039 "liferay-ui:panel-container:panelCount" + _id);
040
041 if ((panelCount != null) && (panelCount.getValue() == 1)) {
042 bodyContent.clearBody();
043
044 return EVAL_BODY_AGAIN;
045 }
046 else {
047 return SKIP_BODY;
048 }
049 }
050
051 @Override
052 public int doEndTag() throws JspException {
053 try {
054 HttpServletRequest request =
055 (HttpServletRequest)pageContext.getRequest();
056
057 IntegerWrapper panelCount = (IntegerWrapper)request.getAttribute(
058 "liferay-ui:panel-container:panelCount" + _id);
059
060 request.removeAttribute(
061 "liferay-ui:panel-container:panelCount" + _id);
062
063 if ((panelCount != null) && (panelCount.getValue() >= 1)) {
064 PortalIncludeUtil.include(pageContext, getStartPage());
065 }
066
067 writeBodyContent(pageContext.getOut());
068
069 if ((panelCount != null) && (panelCount.getValue() >= 1)) {
070 PortalIncludeUtil.include(pageContext, getEndPage());
071 }
072
073 request.removeAttribute("liferay-ui:panel-container:id");
074 request.removeAttribute("liferay-ui:panel-container:accordion");
075 request.removeAttribute("liferay-ui:panel-container:persistState");
076 request.removeAttribute("liferay-ui:panel-container:extended");
077 request.removeAttribute("liferay-ui:panel-container:cssClass");
078
079 return EVAL_PAGE;
080 }
081 catch (Exception e) {
082 throw new JspException(e);
083 }
084 finally {
085 if (!ServerDetector.isResin()) {
086 cleanUp();
087 }
088 }
089 }
090
091 @Override
092 public int doStartTag() {
093 HttpServletRequest request =
094 (HttpServletRequest)pageContext.getRequest();
095
096 if (Validator.isNull(_id)) {
097 _id = StringUtil.randomId();
098 }
099
100 request.setAttribute("liferay-ui:panel-container:id", _id);
101 request.setAttribute(
102 "liferay-ui:panel-container:accordion", String.valueOf(_accordion));
103 request.setAttribute(
104 "liferay-ui:panel-container:persistState",
105 String.valueOf(_persistState));
106 request.setAttribute("liferay-ui:panel-container:extended", _extended);
107 request.setAttribute("liferay-ui:panel-container:cssClass", _cssClass);
108 request.setAttribute(
109 "liferay-ui:panel-container:panelCount" + _id,
110 new IntegerWrapper());
111
112 return EVAL_BODY_BUFFERED;
113 }
114
115 public String getId() {
116 return _id;
117 }
118
119 public boolean isAccordion() {
120 return _accordion;
121 }
122
123 public void setAccordion(boolean accordion) {
124 _accordion = accordion;
125 }
126
127 public void setCssClass(String cssClass) {
128 _cssClass = cssClass;
129 }
130
131 public void setEndPage(String endPage) {
132 _endPage = endPage;
133 }
134
135 public void setExtended(Boolean extended) {
136 _extended = extended;
137 }
138
139 public void setId(String id) {
140 _id = id;
141 }
142
143 public void setMarkupView(String markupView) {
144 _markupView = markupView;
145 }
146
147 public void setPersistState(boolean persistState) {
148 _persistState = persistState;
149 }
150
151 public void setStartPage(String startPage) {
152 _startPage = startPage;
153 }
154
155 protected void cleanUp() {
156 _accordion = false;
157 _cssClass = null;
158 _endPage = null;
159 _extended = false;
160 _id = null;
161 _persistState = false;
162 _startPage = null;
163 }
164
165 protected String getEndPage() {
166 if (Validator.isNull(_endPage)) {
167 if (Validator.isNotNull(_markupView)) {
168 return "/html/taglib/ui/panel_container/" + _markupView +
169 "/end.jsp";
170 }
171
172 return "/html/taglib/ui/panel_container/end.jsp";
173 }
174 else {
175 return _endPage;
176 }
177 }
178
179 protected String getStartPage() {
180 if (Validator.isNull(_startPage)) {
181 if (Validator.isNotNull(_markupView)) {
182 return "/html/taglib/ui/panel_container/" + _markupView +
183 "/start.jsp";
184 }
185
186 return "/html/taglib/ui/panel_container/start.jsp";
187 }
188 else {
189 return _startPage;
190 }
191 }
192
193 private boolean _accordion;
194 private String _cssClass;
195 private String _endPage;
196 private Boolean _extended;
197 private String _id;
198 private String _markupView;
199 private boolean _persistState;
200 private String _startPage;
201
202 }