1
14
15 package com.liferay.taglib.ui;
16
17 import com.liferay.portal.kernel.util.ParamUtil;
18 import com.liferay.portal.kernel.util.ServerDetector;
19 import com.liferay.portal.kernel.util.StringPool;
20 import com.liferay.portal.kernel.util.StringUtil;
21 import com.liferay.portal.kernel.util.Validator;
22 import com.liferay.taglib.util.IncludeTag;
23
24 import javax.portlet.PortletURL;
25
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.jsp.JspException;
28
29
34 public class TabsTag extends IncludeTag {
35
36 public int doStartTag() throws JspException {
37 try {
38 HttpServletRequest request = getServletRequest();
39
40 request.setAttribute("liferay-ui:tabs:names", _names);
41
42 if ((_tabsValues == null) || (_tabsValues.length < _names.length)) {
43 _tabsValues = _names;
44 }
45
46 request.setAttribute("liferay-ui:tabs:values", _tabsValues);
47
48 request.setAttribute("liferay-ui:tabs:formName", _formName);
49 request.setAttribute("liferay-ui:tabs:param", _param);
50
51 if (_value == null) {
52 if (_tabsValues.length > 0) {
53 _value = ParamUtil.getString(
54 request, _param, _tabsValues[0]);
55 }
56 }
57
58 if (Validator.isNull(_value)) {
59 if (_tabsValues.length > 0) {
60 _value = _tabsValues[0];
61 }
62 else {
63 _value = StringPool.BLANK;
64 }
65 }
66
67 boolean match = false;
68
69 for (int i = 0; i < _tabsValues.length; i++) {
70 if (_value.equals(_tabsValues[i])) {
71 match = true;
72 }
73 }
74
75 if (!match) {
76 if (_tabsValues.length > 0) {
77 _value = _tabsValues[0];
78 }
79 else {
80 _value = StringPool.BLANK;
81 }
82 }
83
84 request.setAttribute("liferay-ui:tabs:value", _value);
85 request.setAttribute("liferay-ui:tabs:portletURL", _portletURL);
86 request.setAttribute("liferay-ui:tabs:url", _url);
87
88 if (_url0 != null) {
89 request.setAttribute("liferay-ui:tabs:url0", _url0);
90 }
91
92 if (_url1 != null) {
93 request.setAttribute("liferay-ui:tabs:url1", _url1);
94 }
95
96 if (_url2 != null) {
97 request.setAttribute("liferay-ui:tabs:url2", _url2);
98 }
99
100 if (_url3 != null) {
101 request.setAttribute("liferay-ui:tabs:url3", _url3);
102 }
103
104 if (_url4 != null) {
105 request.setAttribute("liferay-ui:tabs:url4", _url4);
106 }
107
108 if (_url5 != null) {
109 request.setAttribute("liferay-ui:tabs:url5", _url5);
110 }
111
112 if (_url6 != null) {
113 request.setAttribute("liferay-ui:tabs:url6", _url6);
114 }
115
116 if (_url7 != null) {
117 request.setAttribute("liferay-ui:tabs:url7", _url7);
118 }
119
120 if (_url8 != null) {
121 request.setAttribute("liferay-ui:tabs:url8", _url8);
122 }
123
124 if (_url9 != null) {
125 request.setAttribute("liferay-ui:tabs:url9", _url9);
126 }
127
128 request.setAttribute("liferay-ui:tabs:backLabel", _backLabel);
129 request.setAttribute("liferay-ui:tabs:backURL", _backURL);
130 request.setAttribute(
131 "liferay-ui:tabs:refresh", String.valueOf(_refresh));
132 request.setAttribute(
133 "liferay-ui:tabs:onClick", String.valueOf(_onClick));
134
135 include(getStartPage());
136
137 return EVAL_BODY_INCLUDE;
138 }
139 catch (Exception e) {
140 throw new JspException(e);
141 }
142 }
143
144 public int doEndTag() throws JspException {
145 try {
146 HttpServletRequest request =
147 (HttpServletRequest)pageContext.getRequest();
148
149 include(getEndPage());
150
151 request.removeAttribute("liferay-ui:tabs:names");
152 request.removeAttribute("liferay-ui:tabs:values");
153 request.removeAttribute("liferay-ui:tabs:formName");
154 request.removeAttribute("liferay-ui:tabs:param");
155 request.removeAttribute("liferay-ui:tabs:value");
156 request.removeAttribute("liferay-ui:tabs:portletURL");
157 request.removeAttribute("liferay-ui:tabs:url");
158 request.removeAttribute("liferay-ui:tabs:url0");
159 request.removeAttribute("liferay-ui:tabs:url1");
160 request.removeAttribute("liferay-ui:tabs:url2");
161 request.removeAttribute("liferay-ui:tabs:url3");
162 request.removeAttribute("liferay-ui:tabs:url4");
163 request.removeAttribute("liferay-ui:tabs:url5");
164 request.removeAttribute("liferay-ui:tabs:url6");
165 request.removeAttribute("liferay-ui:tabs:url7");
166 request.removeAttribute("liferay-ui:tabs:url8");
167 request.removeAttribute("liferay-ui:tabs:url9");
168 request.removeAttribute("liferay-ui:tabs:backLabel");
169 request.removeAttribute("liferay-ui:tabs:backURL");
170 request.removeAttribute("liferay-ui:tabs:refresh");
171 request.removeAttribute("liferay-ui:tabs:onClick");
172
173 return EVAL_PAGE;
174 }
175 catch (Exception e) {
176 throw new JspException(e);
177 }
178 finally {
179 if (!ServerDetector.isResin()) {
180 _startPage = null;
181 _endPage = null;
182 _names = null;
183 _namesPos = 0;
184 _tabsValues = null;
185 _formName = StringPool.BLANK;
186 _param = "tabs1";
187 _value = null;
188 _portletURL = null;
189 _url = null;
190 _url0 = null;
191 _url1 = null;
192 _url2 = null;
193 _url3 = null;
194 _url4 = null;
195 _url5 = null;
196 _url6 = null;
197 _url7 = null;
198 _url8 = null;
199 _url9 = null;
200 _backLabel = null;
201 _backURL = null;
202 _refresh = true;
203 _onClick = null;
204 }
205 }
206 }
207
208 protected String getStartPage() {
209 if (Validator.isNull(_startPage)) {
210 return _START_PAGE;
211 }
212 else {
213 return _startPage;
214 }
215 }
216
217 public void setStartPage(String startPage) {
218 _startPage = startPage;
219 }
220
221 protected String getEndPage() {
222 if (Validator.isNull(_endPage)) {
223 return _END_PAGE;
224 }
225 else {
226 return _endPage;
227 }
228 }
229
230 public void setEndPage(String endPage) {
231 _endPage = endPage;
232 }
233
234 public void setNames(String names) {
235 _names = StringUtil.split(names);
236 }
237
238 public void setTabsValues(String tabsValues) {
239 _tabsValues = StringUtil.split(tabsValues);
240 }
241
242 public void setFormName(String formName) {
243 _formName = formName;
244 }
245
246 public String getParam() {
247 return _param;
248 }
249
250 public void setParam(String param) {
251 _param = param;
252 }
253
254 public void setValue(String value) {
255 _value = value;
256 }
257
258 public void setPortletURL(PortletURL portletURL) {
259 _portletURL = portletURL;
260 }
261
262 public void setUrl(String url) {
263 _url = url;
264 }
265
266 public void setUrl0(String url0) {
267 _url0 = url0;
268 }
269
270 public void setUrl1(String url1) {
271 _url1 = url1;
272 }
273
274 public void setUrl2(String url2) {
275 _url2 = url2;
276 }
277
278 public void setUrl3(String url3) {
279 _url3 = url3;
280 }
281
282 public void setUrl4(String url4) {
283 _url4 = url4;
284 }
285
286 public void setUrl5(String url5) {
287 _url5 = url5;
288 }
289
290 public void setUrl6(String url6) {
291 _url6 = url6;
292 }
293
294 public void setUrl7(String url7) {
295 _url7 = url7;
296 }
297
298 public void setUrl8(String url8) {
299 _url8 = url8;
300 }
301
302 public void setUrl9(String url9) {
303 _url9 = url9;
304 }
305
306 public void setBackLabel(String backLabel) {
307 _backLabel = backLabel;
308 }
309
310 public void setBackURL(String backURL) {
311 _backURL = backURL;
312 }
313
314 public boolean isRefresh() {
315 return _refresh;
316 }
317
318 public void setRefresh(boolean refresh) {
319 _refresh = refresh;
320 }
321
322 public String getOnClick() {
323 return _onClick;
324 }
325
326 public void setOnClick(String onClick) {
327 _onClick = onClick;
328 }
329
330 public String getSectionName() {
331 if (_names.length > _namesPos) {
332 return _names[_namesPos];
333 }
334 else {
335 return StringPool.BLANK;
336 }
337 }
338
339 public boolean getSectionSelected() {
340 if ((_names.length == 0) ||
341 ((_names.length > _namesPos) &&
342 (_names[_namesPos].equals(_value)))) {
343
344 return true;
345 }
346 else {
347 return false;
348 }
349 }
350
351 public void incrementSection() {
352 _namesPos++;
353 }
354
355 private static final String _START_PAGE = "/html/taglib/ui/tabs/start.jsp";
356
357 private static final String _END_PAGE = "/html/taglib/ui/tabs/end.jsp";
358
359 private String _startPage;
360 private String _endPage;
361 private String[] _names;
362 private int _namesPos;
363 private String[] _tabsValues;
364 private String _formName;
365 private String _param = "tabs1";
366 private String _value;
367 private PortletURL _portletURL;
368 private String _url;
369 private String _url0;
370 private String _url1;
371 private String _url2;
372 private String _url3;
373 private String _url4;
374 private String _url5;
375 private String _url6;
376 private String _url7;
377 private String _url8;
378 private String _url9;
379 private String _backLabel;
380 private String _backURL;
381 private boolean _refresh = true;
382 private String _onClick;
383
384 }