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