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