1
19
20 package com.liferay.taglib.ui;
21
22 import com.liferay.portal.kernel.util.ParamUtil;
23 import com.liferay.portal.kernel.util.StringPool;
24 import com.liferay.portal.kernel.util.StringUtil;
25 import com.liferay.portal.kernel.util.Validator;
26 import com.liferay.taglib.util.ParamAndPropertyAncestorTagImpl;
27
28 import javax.portlet.PortletURL;
29
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.jsp.JspException;
32
33
39 public class TabsTag extends ParamAndPropertyAncestorTagImpl {
40
41 public int doStartTag() throws JspException {
42 try {
43 HttpServletRequest request = getServletRequest();
44
45 request.setAttribute("liferay-ui:tabs:names", _names);
46
47 if ((_tabsValues == null) || (_tabsValues.length < _names.length)) {
48 _tabsValues = _names;
49 }
50
51 request.setAttribute("liferay-ui:tabs:values", _tabsValues);
52
53 request.setAttribute("liferay-ui:tabs:formName", _formName);
54 request.setAttribute("liferay-ui:tabs:param", _param);
55
56 if (_value == null) {
57 if (_tabsValues.length > 0) {
58 _value = ParamUtil.getString(
59 request, _param, _tabsValues[0]);
60 }
61 }
62
63 if (Validator.isNull(_value)) {
64 if (_tabsValues.length > 0) {
65 _value = _tabsValues[0];
66 }
67 else {
68 _value = StringPool.BLANK;
69 }
70 }
71
72 boolean match = false;
73
74 for (int i = 0; i < _tabsValues.length; i++) {
75 if (_value.equals(_tabsValues[i])) {
76 match = true;
77 }
78 }
79
80 if (!match) {
81 if (_tabsValues.length > 0) {
82 _value = _tabsValues[0];
83 }
84 else {
85 _value = StringPool.BLANK;
86 }
87 }
88
89 request.setAttribute("liferay-ui:tabs:value", _value);
90 request.setAttribute("liferay-ui:tabs:portletURL", _portletURL);
91 request.setAttribute("liferay-ui:tabs:url", _url);
92
93 if (_url0 != null) {
94 request.setAttribute("liferay-ui:tabs:url0", _url0);
95 }
96
97 if (_url1 != null) {
98 request.setAttribute("liferay-ui:tabs:url1", _url1);
99 }
100
101 if (_url2 != null) {
102 request.setAttribute("liferay-ui:tabs:url2", _url2);
103 }
104
105 if (_url3 != null) {
106 request.setAttribute("liferay-ui:tabs:url3", _url3);
107 }
108
109 if (_url4 != null) {
110 request.setAttribute("liferay-ui:tabs:url4", _url4);
111 }
112
113 if (_url5 != null) {
114 request.setAttribute("liferay-ui:tabs:url5", _url5);
115 }
116
117 if (_url6 != null) {
118 request.setAttribute("liferay-ui:tabs:url6", _url6);
119 }
120
121 if (_url7 != null) {
122 request.setAttribute("liferay-ui:tabs:url7", _url7);
123 }
124
125 if (_url8 != null) {
126 request.setAttribute("liferay-ui:tabs:url8", _url8);
127 }
128
129 if (_url9 != null) {
130 request.setAttribute("liferay-ui:tabs:url9", _url9);
131 }
132
133 request.setAttribute("liferay-ui:tabs:backURL", _backURL);
134 request.setAttribute(
135 "liferay-ui:tabs:refresh", String.valueOf(_refresh));
136 request.setAttribute(
137 "liferay-ui:tabs:onClick", String.valueOf(_onClick));
138
139 include(getStartPage());
140
141 return EVAL_BODY_INCLUDE;
142 }
143 catch (Exception e) {
144 throw new JspException(e);
145 }
146 }
147
148 public int doEndTag() throws JspException {
149 try {
150 HttpServletRequest request =
151 (HttpServletRequest)pageContext.getRequest();
152
153 include(getEndPage());
154
155 request.removeAttribute("liferay-ui:tabs:names");
156 request.removeAttribute("liferay-ui:tabs:values");
157 request.removeAttribute("liferay-ui:tabs:formName");
158 request.removeAttribute("liferay-ui:tabs:param");
159 request.removeAttribute("liferay-ui:tabs:value");
160 request.removeAttribute("liferay-ui:tabs:portletURL");
161 request.removeAttribute("liferay-ui:tabs:url");
162 request.removeAttribute("liferay-ui:tabs:url0");
163 request.removeAttribute("liferay-ui:tabs:url1");
164 request.removeAttribute("liferay-ui:tabs:url2");
165 request.removeAttribute("liferay-ui:tabs:url3");
166 request.removeAttribute("liferay-ui:tabs:url4");
167 request.removeAttribute("liferay-ui:tabs:url5");
168 request.removeAttribute("liferay-ui:tabs:url6");
169 request.removeAttribute("liferay-ui:tabs:url7");
170 request.removeAttribute("liferay-ui:tabs:url8");
171 request.removeAttribute("liferay-ui:tabs:url9");
172 request.removeAttribute("liferay-ui:tabs:backURL");
173 request.removeAttribute("liferay-ui:tabs:refresh");
174 request.removeAttribute("liferay-ui:tabs:onClick");
175
176 return EVAL_PAGE;
177 }
178 catch (Exception e) {
179 throw new JspException(e);
180 }
181 finally {
182 _startPage = null;
183 _endPage = null;
184 _names = null;
185 _namesPos = 0;
186 _tabsValues = null;
187 _formName = StringPool.BLANK;
188 _param = "tabs1";
189 _value = null;
190 _portletURL = null;
191 _url = null;
192 _url0 = null;
193 _url1 = null;
194 _url2 = null;
195 _url3 = null;
196 _url4 = null;
197 _url5 = null;
198 _url6 = null;
199 _url7 = null;
200 _url8 = null;
201 _url9 = null;
202 _backURL = null;
203 _refresh = true;
204 _onClick = null;
205 }
206 }
207
208 public 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 public 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 setBackURL(String backURL) {
307 _backURL = backURL;
308 }
309
310 public boolean isRefresh() {
311 return _refresh;
312 }
313
314 public void setRefresh(boolean refresh) {
315 _refresh = refresh;
316 }
317
318 public String getOnClick() {
319 return _onClick;
320 }
321
322 public void setOnClick(String onClick) {
323 _onClick = onClick;
324 }
325
326 public String getSectionName() {
327 if (_names.length > _namesPos) {
328 return _names[_namesPos];
329 }
330 else {
331 return StringPool.BLANK;
332 }
333 }
334
335 public boolean getSectionSelected() {
336 if ((_names.length == 0) ||
337 ((_names.length > _namesPos) &&
338 (_names[_namesPos].equals(_value)))) {
339
340 return true;
341 }
342 else {
343 return false;
344 }
345 }
346
347 public void incrementSection() {
348 _namesPos++;
349 }
350
351 private static final String _START_PAGE = "/html/taglib/ui/tabs/start.jsp";
352
353 private static final String _END_PAGE = "/html/taglib/ui/tabs/end.jsp";
354
355 private String _startPage;
356 private String _endPage;
357 private String[] _names;
358 private int _namesPos;
359 private String[] _tabsValues;
360 private String _formName;
361 private String _param = "tabs1";
362 private String _value;
363 private PortletURL _portletURL;
364 private String _url;
365 private String _url0;
366 private String _url1;
367 private String _url2;
368 private String _url3;
369 private String _url4;
370 private String _url5;
371 private String _url6;
372 private String _url7;
373 private String _url8;
374 private String _url9;
375 private String _backURL;
376 private boolean _refresh = true;
377 private String _onClick;
378
379 }