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