001
014
015 package com.liferay.taglib.ui;
016
017 import com.liferay.portal.kernel.util.ArrayUtil;
018 import com.liferay.portal.kernel.util.ParamUtil;
019 import com.liferay.portal.kernel.util.ServerDetector;
020 import com.liferay.portal.kernel.util.StringPool;
021 import com.liferay.portal.kernel.util.StringUtil;
022 import com.liferay.portal.kernel.util.Validator;
023 import com.liferay.taglib.util.IncludeTag;
024
025 import javax.portlet.PortletURL;
026
027 import javax.servlet.http.HttpServletRequest;
028 import javax.servlet.jsp.JspException;
029
030
033 public class TabsTag extends IncludeTag {
034
035 @Override
036 public int doEndTag() throws JspException {
037 try {
038 HttpServletRequest request =
039 (HttpServletRequest)pageContext.getRequest();
040
041 include(getEndPage());
042
043 request.removeAttribute("liferay-ui:tabs:names");
044 request.removeAttribute("liferay-ui:tabs:values");
045 request.removeAttribute("liferay-ui:tabs:formName");
046 request.removeAttribute("liferay-ui:tabs:param");
047 request.removeAttribute("liferay-ui:tabs:value");
048 request.removeAttribute("liferay-ui:tabs:portletURL");
049 request.removeAttribute("liferay-ui:tabs:url");
050 request.removeAttribute("liferay-ui:tabs:url0");
051 request.removeAttribute("liferay-ui:tabs:url1");
052 request.removeAttribute("liferay-ui:tabs:url2");
053 request.removeAttribute("liferay-ui:tabs:url3");
054 request.removeAttribute("liferay-ui:tabs:url4");
055 request.removeAttribute("liferay-ui:tabs:url5");
056 request.removeAttribute("liferay-ui:tabs:url6");
057 request.removeAttribute("liferay-ui:tabs:url7");
058 request.removeAttribute("liferay-ui:tabs:url8");
059 request.removeAttribute("liferay-ui:tabs:url9");
060 request.removeAttribute("liferay-ui:tabs:backLabel");
061 request.removeAttribute("liferay-ui:tabs:backURL");
062 request.removeAttribute("liferay-ui:tabs:refresh");
063 request.removeAttribute("liferay-ui:tabs:onClick");
064
065 return EVAL_PAGE;
066 }
067 catch (Exception e) {
068 throw new JspException(e);
069 }
070 finally {
071 if (!ServerDetector.isResin()) {
072 _startPage = null;
073 _endPage = null;
074 _names = null;
075 _namesPos = 0;
076 _tabsValues = null;
077 _formName = StringPool.BLANK;
078 _param = "tabs1";
079 _value = null;
080 _portletURL = null;
081 _url = null;
082 _url0 = null;
083 _url1 = null;
084 _url2 = null;
085 _url3 = null;
086 _url4 = null;
087 _url5 = null;
088 _url6 = null;
089 _url7 = null;
090 _url8 = null;
091 _url9 = null;
092 _backLabel = null;
093 _backURL = null;
094 _refresh = true;
095 _onClick = null;
096 }
097 }
098 }
099
100 @Override
101 public int doStartTag() throws JspException {
102 try {
103 HttpServletRequest request = getServletRequest();
104
105 request.setAttribute("liferay-ui:tabs:names", _names);
106
107 if ((_tabsValues == null) || (_tabsValues.length < _names.length)) {
108 _tabsValues = _names;
109 }
110
111 request.setAttribute("liferay-ui:tabs:values", _tabsValues);
112
113 request.setAttribute("liferay-ui:tabs:formName", _formName);
114 request.setAttribute("liferay-ui:tabs:param", _param);
115
116 if (_value == null) {
117 if (_tabsValues.length > 0) {
118 _value = ParamUtil.getString(
119 request, _param, _tabsValues[0]);
120 }
121 }
122
123 if (Validator.isNull(_value)) {
124 if (_tabsValues.length > 0) {
125 _value = _tabsValues[0];
126 }
127 else {
128 _value = StringPool.BLANK;
129 }
130 }
131
132 boolean match = false;
133
134 if (ArrayUtil.contains(_tabsValues, _value)) {
135 match = true;
136 }
137
138 if (!match) {
139 if (_tabsValues.length > 0) {
140 _value = _tabsValues[0];
141 }
142 else {
143 _value = StringPool.BLANK;
144 }
145 }
146
147 request.setAttribute("liferay-ui:tabs:value", _value);
148 request.setAttribute("liferay-ui:tabs:portletURL", _portletURL);
149 request.setAttribute("liferay-ui:tabs:url", _url);
150
151 if (_url0 != null) {
152 request.setAttribute("liferay-ui:tabs:url0", _url0);
153 }
154
155 if (_url1 != null) {
156 request.setAttribute("liferay-ui:tabs:url1", _url1);
157 }
158
159 if (_url2 != null) {
160 request.setAttribute("liferay-ui:tabs:url2", _url2);
161 }
162
163 if (_url3 != null) {
164 request.setAttribute("liferay-ui:tabs:url3", _url3);
165 }
166
167 if (_url4 != null) {
168 request.setAttribute("liferay-ui:tabs:url4", _url4);
169 }
170
171 if (_url5 != null) {
172 request.setAttribute("liferay-ui:tabs:url5", _url5);
173 }
174
175 if (_url6 != null) {
176 request.setAttribute("liferay-ui:tabs:url6", _url6);
177 }
178
179 if (_url7 != null) {
180 request.setAttribute("liferay-ui:tabs:url7", _url7);
181 }
182
183 if (_url8 != null) {
184 request.setAttribute("liferay-ui:tabs:url8", _url8);
185 }
186
187 if (_url9 != null) {
188 request.setAttribute("liferay-ui:tabs:url9", _url9);
189 }
190
191 request.setAttribute("liferay-ui:tabs:backLabel", _backLabel);
192 request.setAttribute("liferay-ui:tabs:backURL", _backURL);
193 request.setAttribute(
194 "liferay-ui:tabs:refresh", String.valueOf(_refresh));
195 request.setAttribute(
196 "liferay-ui:tabs:onClick", String.valueOf(_onClick));
197
198 include(getStartPage());
199
200 return EVAL_BODY_INCLUDE;
201 }
202 catch (Exception e) {
203 throw new JspException(e);
204 }
205 }
206
207 public String getOnClick() {
208 return _onClick;
209 }
210
211 public String getParam() {
212 return _param;
213 }
214
215 public String getSectionName() {
216 if (_names.length > _namesPos) {
217 return _names[_namesPos];
218 }
219 else {
220 return StringPool.BLANK;
221 }
222 }
223
224 public boolean getSectionSelected() {
225 if ((_names.length == 0) ||
226 ((_names.length > _namesPos) &&
227 _names[_namesPos].equals(_value))) {
228
229 return true;
230 }
231 else {
232 return false;
233 }
234 }
235
236 public void incrementSection() {
237 _namesPos++;
238 }
239
240 public boolean isRefresh() {
241 return _refresh;
242 }
243
244 public void setBackLabel(String backLabel) {
245 _backLabel = backLabel;
246 }
247
248 public void setBackURL(String backURL) {
249 _backURL = backURL;
250 }
251
252 public void setEndPage(String endPage) {
253 _endPage = endPage;
254 }
255
256 public void setFormName(String formName) {
257 _formName = formName;
258 }
259
260 public void setNames(String names) {
261 _names = StringUtil.split(names);
262 }
263
264 public void setOnClick(String onClick) {
265 _onClick = onClick;
266 }
267
268 public void setParam(String param) {
269 _param = param;
270 }
271
272 public void setPortletURL(PortletURL portletURL) {
273 _portletURL = portletURL;
274 }
275
276 public void setRefresh(boolean refresh) {
277 _refresh = refresh;
278 }
279
280 public void setStartPage(String startPage) {
281 _startPage = startPage;
282 }
283
284 public void setTabsValues(String tabsValues) {
285 _tabsValues = StringUtil.split(tabsValues);
286 }
287
288 public void setUrl(String url) {
289 _url = url;
290 }
291
292 public void setUrl0(String url0) {
293 _url0 = url0;
294 }
295
296 public void setUrl1(String url1) {
297 _url1 = url1;
298 }
299
300 public void setUrl2(String url2) {
301 _url2 = url2;
302 }
303
304 public void setUrl3(String url3) {
305 _url3 = url3;
306 }
307
308 public void setUrl4(String url4) {
309 _url4 = url4;
310 }
311
312 public void setUrl5(String url5) {
313 _url5 = url5;
314 }
315
316 public void setUrl6(String url6) {
317 _url6 = url6;
318 }
319
320 public void setUrl7(String url7) {
321 _url7 = url7;
322 }
323
324 public void setUrl8(String url8) {
325 _url8 = url8;
326 }
327
328 public void setUrl9(String url9) {
329 _url9 = url9;
330 }
331
332 public void setValue(String value) {
333 _value = value;
334 }
335
336 @Override
337 protected String getEndPage() {
338 if (Validator.isNull(_endPage)) {
339 return _END_PAGE;
340 }
341 else {
342 return _endPage;
343 }
344 }
345
346 @Override
347 protected String getStartPage() {
348 if (Validator.isNull(_startPage)) {
349 return _START_PAGE;
350 }
351 else {
352 return _startPage;
353 }
354 }
355
356 private static final String _END_PAGE = "/html/taglib/ui/tabs/end.jsp";
357
358 private static final String _START_PAGE = "/html/taglib/ui/tabs/start.jsp";
359
360 private String _backLabel;
361 private String _backURL;
362 private String _endPage;
363 private String _formName;
364 private String[] _names;
365 private int _namesPos;
366 private String _onClick;
367 private String _param = "tabs1";
368 private PortletURL _portletURL;
369 private boolean _refresh = true;
370 private String _startPage;
371 private String[] _tabsValues;
372 private String _url;
373 private String _url0;
374 private String _url1;
375 private String _url2;
376 private String _url3;
377 private String _url4;
378 private String _url5;
379 private String _url6;
380 private String _url7;
381 private String _url8;
382 private String _url9;
383 private String _value;
384
385 }