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) && _names[_namesPos].equals(_value))) {
236
237 return true;
238 }
239 else {
240 return false;
241 }
242 }
243
244 public void incrementSection() {
245 _namesPos++;
246 }
247
248 public boolean isRefresh() {
249 return _refresh;
250 }
251
252 public void setBackLabel(String backLabel) {
253 _backLabel = backLabel;
254 }
255
256 public void setBackURL(String backURL) {
257 _backURL = backURL;
258 }
259
260 public void setEndPage(String endPage) {
261 _endPage = endPage;
262 }
263
264 public void setFormName(String formName) {
265 _formName = formName;
266 }
267
268 public void setNames(String names) {
269 _names = StringUtil.split(names);
270 }
271
272 public void setOnClick(String onClick) {
273 _onClick = onClick;
274 }
275
276 public void setParam(String param) {
277 _param = param;
278 }
279
280 public void setPortletURL(PortletURL portletURL) {
281 _portletURL = portletURL;
282 }
283
284 public void setRefresh(boolean refresh) {
285 _refresh = refresh;
286 }
287
288 public void setStartPage(String startPage) {
289 _startPage = startPage;
290 }
291
292 public void setTabsValues(String tabsValues) {
293 _tabsValues = StringUtil.split(tabsValues);
294 }
295
296 public void setType(String type) {
297 _type = type;
298 }
299
300 public void setUrl(String url) {
301 _url = url;
302 }
303
304
307 @Deprecated
308 public void setUrl0(String url0) {
309 _url0 = url0;
310 }
311
312
315 @Deprecated
316 public void setUrl1(String url1) {
317 _url1 = url1;
318 }
319
320
323 @Deprecated
324 public void setUrl2(String url2) {
325 _url2 = url2;
326 }
327
328
331 @Deprecated
332 public void setUrl3(String url3) {
333 _url3 = url3;
334 }
335
336
339 @Deprecated
340 public void setUrl4(String url4) {
341 _url4 = url4;
342 }
343
344
347 @Deprecated
348 public void setUrl5(String url5) {
349 _url5 = url5;
350 }
351
352
355 @Deprecated
356 public void setUrl6(String url6) {
357 _url6 = url6;
358 }
359
360
363 @Deprecated
364 public void setUrl7(String url7) {
365 _url7 = url7;
366 }
367
368
371 @Deprecated
372 public void setUrl8(String url8) {
373 _url8 = url8;
374 }
375
376
379 @Deprecated
380 public void setUrl9(String url9) {
381 _url9 = url9;
382 }
383
384 public void setUrls(String[] urls) {
385 _urls = urls;
386 }
387
388 public void setValue(String value) {
389 _value = value;
390 }
391
392 @Override
393 protected String getEndPage() {
394 if (Validator.isNull(_endPage)) {
395 return _END_PAGE;
396 }
397 else {
398 return _endPage;
399 }
400 }
401
402 @Override
403 protected String getStartPage() {
404 if (Validator.isNull(_startPage)) {
405 return _START_PAGE;
406 }
407 else {
408 return _startPage;
409 }
410 }
411
412 private static final String _END_PAGE = "/html/taglib/ui/tabs/end.jsp";
413
414 private static final String _START_PAGE = "/html/taglib/ui/tabs/start.jsp";
415
416 private String _backLabel;
417 private String _backURL;
418 private String _endPage;
419 private String _formName;
420 private String[] _names;
421 private String _namesJS;
422 private int _namesPos;
423 private String _onClick;
424 private String _param = "tabs1";
425 private PortletURL _portletURL;
426 private boolean _refresh = true;
427 private String _startPage;
428 private String[] _tabsValues;
429 private String _type;
430 private String _url;
431 private String _url0;
432 private String _url1;
433 private String _url2;
434 private String _url3;
435 private String _url4;
436 private String _url5;
437 private String _url6;
438 private String _url7;
439 private String _url8;
440 private String _url9;
441 private String[] _urls;
442 private String _value;
443
444 }