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