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 import com.liferay.util.JS;
025
026 import javax.portlet.PortletURL;
027
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 request.setAttribute("liferay-ui:tabs:namesJS", _namesJS);
039 request.setAttribute("liferay-ui:tabs:param", _param);
040 request.setAttribute("liferay-ui:tabs:value", _value);
041
042 include(getEndPage(), false);
043
044 request.removeAttribute("liferay-ui:tabs:backLabel");
045 request.removeAttribute("liferay-ui:tabs:backURL");
046 request.removeAttribute("liferay-ui:tabs:formName");
047 request.removeAttribute("liferay-ui:tabs:names");
048 request.removeAttribute("liferay-ui:tabs:namesJS");
049 request.removeAttribute("liferay-ui:tabs:onClick");
050 request.removeAttribute("liferay-ui:tabs:param");
051 request.removeAttribute("liferay-ui:tabs:portletURL");
052 request.removeAttribute("liferay-ui:tabs:refresh");
053 request.removeAttribute("liferay-ui:tabs:type");
054 request.removeAttribute("liferay-ui:tabs:url");
055 request.removeAttribute("liferay-ui:tabs:urls");
056 request.removeAttribute("liferay-ui:tabs:value");
057 request.removeAttribute("liferay-ui:tabs:values");
058
059 return EVAL_PAGE;
060 }
061 catch (Exception e) {
062 throw new JspException(e);
063 }
064 finally {
065 if (!ServerDetector.isResin()) {
066 _backLabel = null;
067 _backURL = null;
068 _endPage = null;
069 _formName = StringPool.BLANK;
070 _names = null;
071 _namesJS = null;
072 _namesPos = 0;
073 _onClick = null;
074 _param = "tabs1";
075 _portletURL = null;
076 _refresh = true;
077 _startPage = null;
078 _tabsValues = null;
079 _type = null;
080 _url = null;
081 _url0 = null;
082 _url1 = null;
083 _url2 = null;
084 _url3 = null;
085 _url4 = null;
086 _url5 = null;
087 _url6 = null;
088 _url7 = null;
089 _url8 = null;
090 _url9 = null;
091 _urls = null;
092 _value = null;
093 }
094 }
095 }
096
097 @Override
098 public int doStartTag() throws JspException {
099 try {
100 request.setAttribute("liferay-ui:tabs:backLabel", _backLabel);
101 request.setAttribute("liferay-ui:tabs:backURL", _backURL);
102 request.setAttribute("liferay-ui:tabs:formName", _formName);
103 request.setAttribute("liferay-ui:tabs:names", _names);
104
105 _namesJS = JS.toScript(_names);
106
107 request.setAttribute("liferay-ui:tabs:namesJS", _namesJS);
108
109 request.setAttribute(
110 "liferay-ui:tabs:onClick", String.valueOf(_onClick));
111 request.setAttribute("liferay-ui:tabs:param", _param);
112 request.setAttribute("liferay-ui:tabs:portletURL", _portletURL);
113 request.setAttribute(
114 "liferay-ui:tabs:refresh", String.valueOf(_refresh));
115
116 if ((_tabsValues == null) || (_tabsValues.length < _names.length)) {
117 _tabsValues = _names;
118 }
119
120 request.setAttribute("liferay-ui:tabs:values", _tabsValues);
121
122 request.setAttribute("liferay-ui:tabs:type", _type);
123 request.setAttribute("liferay-ui:tabs:url", _url);
124
125 if ((_urls == null) &&
126 ((_url0 != null) || (_url1 != null) || (_url2 != null) ||
127 (_url3 != null) || (_url4 != null) || (_url5 != null) ||
128 (_url6 != null) || (_url7 != null) || (_url8 != null) ||
129 (_url9 != null))) {
130
131 _urls = new String[10];
132
133 if (_url0 != null) {
134 _urls[0] = _url0;
135 }
136
137 if (_url1 != null) {
138 _urls[1] = _url1;
139 }
140
141 if (_url2 != null) {
142 _urls[2] = _url2;
143 }
144
145 if (_url3 != null) {
146 _urls[3] = _url3;
147 }
148
149 if (_url4 != null) {
150 _urls[4] = _url4;
151 }
152
153 if (_url5 != null) {
154 _urls[5] = _url5;
155 }
156
157 if (_url6 != null) {
158 _urls[6] = _url6;
159 }
160
161 if (_url7 != null) {
162 _urls[7] = _url7;
163 }
164
165 if (_url8 != null) {
166 _urls[8] = _url8;
167 }
168
169 if (_url9 != null) {
170 _urls[9] = _url9;
171 }
172 }
173
174 request.setAttribute("liferay-ui:tabs:urls", _urls);
175
176 if (_value == null) {
177 if (_tabsValues.length > 0) {
178 _value = ParamUtil.getString(
179 request, _param, _tabsValues[0]);
180 }
181 }
182
183 if (Validator.isNull(_value)) {
184 if (_tabsValues.length > 0) {
185 _value = _tabsValues[0];
186 }
187 else {
188 _value = StringPool.BLANK;
189 }
190 }
191
192 if (!ArrayUtil.contains(_tabsValues, _value)) {
193 if (_tabsValues.length > 0) {
194 _value = _tabsValues[0];
195 }
196 else {
197 _value = StringPool.BLANK;
198 }
199 }
200
201 if (_value == null) {
202 _value = ParamUtil.getString(request, _param, _tabsValues[0]);
203 }
204
205 request.setAttribute("liferay-ui:tabs:value", _value);
206
207 include(getStartPage(), true);
208
209 return EVAL_BODY_INCLUDE;
210 }
211 catch (Exception e) {
212 throw new JspException(e);
213 }
214 }
215
216 public String getOnClick() {
217 return _onClick;
218 }
219
220 public String getParam() {
221 return _param;
222 }
223
224 public String getSectionName() {
225 if (_names.length > _namesPos) {
226 return _names[_namesPos];
227 }
228 else {
229 return StringPool.BLANK;
230 }
231 }
232
233 public boolean getSectionSelected() {
234 if ((_names.length == 0) ||
235 ((_names.length > _namesPos) &&
236 _names[_namesPos].equals(_value))) {
237
238 return true;
239 }
240 else {
241 return false;
242 }
243 }
244
245 public void incrementSection() {
246 _namesPos++;
247 }
248
249 public boolean isRefresh() {
250 return _refresh;
251 }
252
253 public void setBackLabel(String backLabel) {
254 _backLabel = backLabel;
255 }
256
257 public void setBackURL(String backURL) {
258 _backURL = backURL;
259 }
260
261 public void setEndPage(String endPage) {
262 _endPage = endPage;
263 }
264
265 public void setFormName(String formName) {
266 _formName = formName;
267 }
268
269 public void setNames(String names) {
270 _names = StringUtil.split(names);
271 }
272
273 public void setOnClick(String onClick) {
274 _onClick = onClick;
275 }
276
277 public void setParam(String param) {
278 _param = param;
279 }
280
281 public void setPortletURL(PortletURL portletURL) {
282 _portletURL = portletURL;
283 }
284
285 public void setRefresh(boolean refresh) {
286 _refresh = refresh;
287 }
288
289 public void setStartPage(String startPage) {
290 _startPage = startPage;
291 }
292
293 public void setTabsValues(String tabsValues) {
294 _tabsValues = StringUtil.split(tabsValues);
295 }
296
297 public void setType(String type) {
298 _type = type;
299 }
300
301 public void setUrl(String url) {
302 _url = url;
303 }
304
305
308 @Deprecated
309 public void setUrl0(String url0) {
310 _url0 = url0;
311 }
312
313
316 @Deprecated
317 public void setUrl1(String url1) {
318 _url1 = url1;
319 }
320
321
324 @Deprecated
325 public void setUrl2(String url2) {
326 _url2 = url2;
327 }
328
329
332 @Deprecated
333 public void setUrl3(String url3) {
334 _url3 = url3;
335 }
336
337
340 @Deprecated
341 public void setUrl4(String url4) {
342 _url4 = url4;
343 }
344
345
348 @Deprecated
349 public void setUrl5(String url5) {
350 _url5 = url5;
351 }
352
353
356 @Deprecated
357 public void setUrl6(String url6) {
358 _url6 = url6;
359 }
360
361
364 @Deprecated
365 public void setUrl7(String url7) {
366 _url7 = url7;
367 }
368
369
372 @Deprecated
373 public void setUrl8(String url8) {
374 _url8 = url8;
375 }
376
377
380 @Deprecated
381 public void setUrl9(String url9) {
382 _url9 = url9;
383 }
384
385 public void setUrls(String[] urls) {
386 _urls = urls;
387 }
388
389 public void setValue(String value) {
390 _value = value;
391 }
392
393 @Override
394 protected String getEndPage() {
395 if (Validator.isNull(_endPage)) {
396 return _END_PAGE;
397 }
398 else {
399 return _endPage;
400 }
401 }
402
403 @Override
404 protected String getStartPage() {
405 if (Validator.isNull(_startPage)) {
406 return _START_PAGE;
407 }
408 else {
409 return _startPage;
410 }
411 }
412
413 private static final String _END_PAGE = "/html/taglib/ui/tabs/end.jsp";
414
415 private static final String _START_PAGE = "/html/taglib/ui/tabs/start.jsp";
416
417 private String _backLabel;
418 private String _backURL;
419 private String _endPage;
420 private String _formName;
421 private String[] _names;
422 private String _namesJS;
423 private int _namesPos;
424 private String _onClick;
425 private String _param = "tabs1";
426 private PortletURL _portletURL;
427 private boolean _refresh = true;
428 private String _startPage;
429 private String[] _tabsValues;
430 private String _type;
431 private String _url;
432 private String _url0;
433 private String _url1;
434 private String _url2;
435 private String _url3;
436 private String _url4;
437 private String _url5;
438 private String _url6;
439 private String _url7;
440 private String _url8;
441 private String _url9;
442 private String[] _urls;
443 private String _value;
444
445 }