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