001
014
015 package com.liferay.taglib.ui;
016
017 import com.liferay.portal.kernel.util.ArrayUtil;
018 import com.liferay.portal.kernel.util.ParamUtil;
019 import com.liferay.portal.kernel.util.ServerDetector;
020 import com.liferay.portal.kernel.util.StringPool;
021 import com.liferay.portal.kernel.util.StringUtil;
022 import com.liferay.portal.kernel.util.Validator;
023 import com.liferay.taglib.util.IncludeTag;
024
025 import javax.portlet.PortletURL;
026
027 import javax.servlet.http.HttpServletRequest;
028 import javax.servlet.jsp.JspException;
029
030
033 public class TabsTag extends IncludeTag {
034
035 @Override
036 public int doEndTag() throws JspException {
037 try {
038 HttpServletRequest request =
039 (HttpServletRequest)pageContext.getRequest();
040
041 include(getEndPage());
042
043 request.removeAttribute("liferay-ui:tabs:backLabel");
044 request.removeAttribute("liferay-ui:tabs:backURL");
045 request.removeAttribute("liferay-ui:tabs:formName");
046 request.removeAttribute("liferay-ui:tabs:names");
047 request.removeAttribute("liferay-ui:tabs:onClick");
048 request.removeAttribute("liferay-ui:tabs:param");
049 request.removeAttribute("liferay-ui:tabs:portletURL");
050 request.removeAttribute("liferay-ui:tabs:refresh");
051 request.removeAttribute("liferay-ui:tabs:type");
052 request.removeAttribute("liferay-ui:tabs:url");
053 request.removeAttribute("liferay-ui:tabs:url0");
054 request.removeAttribute("liferay-ui:tabs:url1");
055 request.removeAttribute("liferay-ui:tabs:url2");
056 request.removeAttribute("liferay-ui:tabs:url3");
057 request.removeAttribute("liferay-ui:tabs:url4");
058 request.removeAttribute("liferay-ui:tabs:url5");
059 request.removeAttribute("liferay-ui:tabs:url6");
060 request.removeAttribute("liferay-ui:tabs:url7");
061 request.removeAttribute("liferay-ui:tabs:url8");
062 request.removeAttribute("liferay-ui:tabs:url9");
063 request.removeAttribute("liferay-ui:tabs:value");
064 request.removeAttribute("liferay-ui:tabs:values");
065
066 return EVAL_PAGE;
067 }
068 catch (Exception e) {
069 throw new JspException(e);
070 }
071 finally {
072 if (!ServerDetector.isResin()) {
073 _backLabel = null;
074 _backURL = null;
075 _endPage = null;
076 _formName = StringPool.BLANK;
077 _names = null;
078 _namesPos = 0;
079 _onClick = null;
080 _param = "tabs1";
081 _portletURL = null;
082 _refresh = true;
083 _startPage = null;
084 _tabsValues = null;
085 _type = null;
086 _url = null;
087 _url0 = null;
088 _url1 = null;
089 _url2 = null;
090 _url3 = null;
091 _url4 = null;
092 _url5 = null;
093 _url6 = null;
094 _url7 = null;
095 _url8 = null;
096 _url9 = null;
097 _value = null;
098 }
099 }
100 }
101
102 @Override
103 public int doStartTag() throws JspException {
104 try {
105 request.setAttribute("liferay-ui:tabs:names", _names);
106
107 if ((_tabsValues == null) || (_tabsValues.length < _names.length)) {
108 _tabsValues = _names;
109 }
110
111 request.setAttribute("liferay-ui:tabs:param", _param);
112 request.setAttribute("liferay-ui:tabs:values", _tabsValues);
113
114 if (_value == null) {
115 if (_tabsValues.length > 0) {
116 _value = ParamUtil.getString(
117 request, _param, _tabsValues[0]);
118 }
119 }
120
121 if (Validator.isNull(_value)) {
122 if (_tabsValues.length > 0) {
123 _value = _tabsValues[0];
124 }
125 else {
126 _value = StringPool.BLANK;
127 }
128 }
129
130 boolean match = false;
131
132 if (ArrayUtil.contains(_tabsValues, _value)) {
133 match = true;
134 }
135
136 if (!match) {
137 if (_tabsValues.length > 0) {
138 _value = _tabsValues[0];
139 }
140 else {
141 _value = StringPool.BLANK;
142 }
143 }
144
145 request.setAttribute("liferay-ui:tabs:backLabel", _backLabel);
146 request.setAttribute("liferay-ui:tabs:backURL", _backURL);
147 request.setAttribute("liferay-ui:tabs:formName", _formName);
148 request.setAttribute(
149 "liferay-ui:tabs:onClick", String.valueOf(_onClick));
150 request.setAttribute("liferay-ui:tabs:portletURL", _portletURL);
151 request.setAttribute(
152 "liferay-ui:tabs:refresh", String.valueOf(_refresh));
153 request.setAttribute("liferay-ui:tabs:type", _type);
154 request.setAttribute("liferay-ui:tabs:url", _url);
155
156 if (_url0 != null) {
157 request.setAttribute("liferay-ui:tabs:url0", _url0);
158 }
159
160 if (_url1 != null) {
161 request.setAttribute("liferay-ui:tabs:url1", _url1);
162 }
163
164 if (_url2 != null) {
165 request.setAttribute("liferay-ui:tabs:url2", _url2);
166 }
167
168 if (_url3 != null) {
169 request.setAttribute("liferay-ui:tabs:url3", _url3);
170 }
171
172 if (_url4 != null) {
173 request.setAttribute("liferay-ui:tabs:url4", _url4);
174 }
175
176 if (_url5 != null) {
177 request.setAttribute("liferay-ui:tabs:url5", _url5);
178 }
179
180 if (_url6 != null) {
181 request.setAttribute("liferay-ui:tabs:url6", _url6);
182 }
183
184 if (_url7 != null) {
185 request.setAttribute("liferay-ui:tabs:url7", _url7);
186 }
187
188 if (_url8 != null) {
189 request.setAttribute("liferay-ui:tabs:url8", _url8);
190 }
191
192 if (_url9 != null) {
193 request.setAttribute("liferay-ui:tabs:url9", _url9);
194 }
195
196 request.setAttribute("liferay-ui:tabs:value", _value);
197
198 include(getStartPage());
199
200 return EVAL_BODY_INCLUDE;
201 }
202 catch (Exception e) {
203 throw new JspException(e);
204 }
205 }
206
207 public String getOnClick() {
208 return _onClick;
209 }
210
211 public String getParam() {
212 return _param;
213 }
214
215 public String getSectionName() {
216 if (_names.length > _namesPos) {
217 return _names[_namesPos];
218 }
219 else {
220 return StringPool.BLANK;
221 }
222 }
223
224 public boolean getSectionSelected() {
225 if ((_names.length == 0) ||
226 ((_names.length > _namesPos) &&
227 _names[_namesPos].equals(_value))) {
228
229 return true;
230 }
231 else {
232 return false;
233 }
234 }
235
236 public void incrementSection() {
237 _namesPos++;
238 }
239
240 public boolean isRefresh() {
241 return _refresh;
242 }
243
244 public void setBackLabel(String backLabel) {
245 _backLabel = backLabel;
246 }
247
248 public void setBackURL(String backURL) {
249 _backURL = backURL;
250 }
251
252 public void setEndPage(String endPage) {
253 _endPage = endPage;
254 }
255
256 public void setFormName(String formName) {
257 _formName = formName;
258 }
259
260 public void setNames(String names) {
261 _names = StringUtil.split(names);
262 }
263
264 public void setOnClick(String onClick) {
265 _onClick = onClick;
266 }
267
268 public void setParam(String param) {
269 _param = param;
270 }
271
272 public void setPortletURL(PortletURL portletURL) {
273 _portletURL = portletURL;
274 }
275
276 public void setRefresh(boolean refresh) {
277 _refresh = refresh;
278 }
279
280 public void setStartPage(String startPage) {
281 _startPage = startPage;
282 }
283
284 public void setTabsValues(String tabsValues) {
285 _tabsValues = StringUtil.split(tabsValues);
286 }
287
288 public void setType(String type) {
289 _type = type;
290 }
291
292 public void setUrl(String url) {
293 _url = url;
294 }
295
296 public void setUrl0(String url0) {
297 _url0 = url0;
298 }
299
300 public void setUrl1(String url1) {
301 _url1 = url1;
302 }
303
304 public void setUrl2(String url2) {
305 _url2 = url2;
306 }
307
308 public void setUrl3(String url3) {
309 _url3 = url3;
310 }
311
312 public void setUrl4(String url4) {
313 _url4 = url4;
314 }
315
316 public void setUrl5(String url5) {
317 _url5 = url5;
318 }
319
320 public void setUrl6(String url6) {
321 _url6 = url6;
322 }
323
324 public void setUrl7(String url7) {
325 _url7 = url7;
326 }
327
328 public void setUrl8(String url8) {
329 _url8 = url8;
330 }
331
332 public void setUrl9(String url9) {
333 _url9 = url9;
334 }
335
336 public void setValue(String value) {
337 _value = value;
338 }
339
340 @Override
341 protected String getEndPage() {
342 if (Validator.isNull(_endPage)) {
343 return _END_PAGE;
344 }
345 else {
346 return _endPage;
347 }
348 }
349
350 @Override
351 protected String getStartPage() {
352 if (Validator.isNull(_startPage)) {
353 return _START_PAGE;
354 }
355 else {
356 return _startPage;
357 }
358 }
359
360 private static final String _END_PAGE = "/html/taglib/ui/tabs/end.jsp";
361
362 private static final String _START_PAGE = "/html/taglib/ui/tabs/start.jsp";
363
364 private String _backLabel;
365 private String _backURL;
366 private String _endPage;
367 private String _formName;
368 private String[] _names;
369 private int _namesPos;
370 private String _onClick;
371 private String _param = "tabs1";
372 private PortletURL _portletURL;
373 private boolean _refresh = true;
374 private String _startPage;
375 private String[] _tabsValues;
376 private String _type;
377 private String _url;
378 private String _url0;
379 private String _url1;
380 private String _url2;
381 private String _url3;
382 private String _url4;
383 private String _url5;
384 private String _url6;
385 private String _url7;
386 private String _url8;
387 private String _url9;
388 private String _value;
389
390 }