001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.taglib.ui;
022:
023: import com.liferay.portal.kernel.util.ParamUtil;
024: import com.liferay.portal.kernel.util.StringPool;
025: import com.liferay.portal.kernel.util.StringUtil;
026: import com.liferay.portal.kernel.util.Validator;
027: import com.liferay.taglib.util.ParamAncestorTagImpl;
028:
029: import javax.portlet.PortletURL;
030:
031: import javax.servlet.ServletRequest;
032: import javax.servlet.jsp.JspException;
033:
034: /**
035: * <a href="TabsTag.java.html"><b><i>View Source</i></b></a>
036: *
037: * @author Brian Wing Shun Chan
038: *
039: */
040: public class TabsTag extends ParamAncestorTagImpl {
041:
042: public int doStartTag() throws JspException {
043: try {
044: ServletRequest req = getServletRequest();
045:
046: req.setAttribute("liferay-ui:tabs:names", _names);
047:
048: if ((_tabsValues == null)
049: || (_tabsValues.length < _names.length)) {
050: _tabsValues = _names;
051: }
052:
053: req.setAttribute("liferay-ui:tabs:values", _tabsValues);
054:
055: req.setAttribute("liferay-ui:tabs:formName", _formName);
056: req.setAttribute("liferay-ui:tabs:param", _param);
057:
058: if (_value == null) {
059: if (_tabsValues.length > 0) {
060: _value = ParamUtil.getString(req, _param,
061: _tabsValues[0]);
062: }
063: }
064:
065: if (Validator.isNull(_value)) {
066: if (_tabsValues.length > 0) {
067: _value = _tabsValues[0];
068: } else {
069: _value = StringPool.BLANK;
070: }
071: }
072:
073: boolean match = false;
074:
075: for (int i = 0; i < _tabsValues.length; i++) {
076: if (_value.equals(_tabsValues[i])) {
077: match = true;
078: }
079: }
080:
081: if (!match) {
082: if (_tabsValues.length > 0) {
083: _value = _tabsValues[0];
084: } else {
085: _value = StringPool.BLANK;
086: }
087: }
088:
089: req.setAttribute("liferay-ui:tabs:value", _value);
090: req.setAttribute("liferay-ui:tabs:portletURL", _portletURL);
091: req.setAttribute("liferay-ui:tabs:url", _url);
092:
093: if (_url0 != null) {
094: req.setAttribute("liferay-ui:tabs:url0", _url0);
095: }
096:
097: if (_url1 != null) {
098: req.setAttribute("liferay-ui:tabs:url1", _url1);
099: }
100:
101: if (_url2 != null) {
102: req.setAttribute("liferay-ui:tabs:url2", _url2);
103: }
104:
105: if (_url3 != null) {
106: req.setAttribute("liferay-ui:tabs:url3", _url3);
107: }
108:
109: if (_url4 != null) {
110: req.setAttribute("liferay-ui:tabs:url4", _url4);
111: }
112:
113: if (_url5 != null) {
114: req.setAttribute("liferay-ui:tabs:url5", _url5);
115: }
116:
117: if (_url6 != null) {
118: req.setAttribute("liferay-ui:tabs:url6", _url6);
119: }
120:
121: if (_url7 != null) {
122: req.setAttribute("liferay-ui:tabs:url7", _url7);
123: }
124:
125: if (_url8 != null) {
126: req.setAttribute("liferay-ui:tabs:url8", _url8);
127: }
128:
129: if (_url9 != null) {
130: req.setAttribute("liferay-ui:tabs:url9", _url9);
131: }
132:
133: req.setAttribute("liferay-ui:tabs:backURL", _backURL);
134: req.setAttribute("liferay-ui:tabs:refresh", String
135: .valueOf(_refresh));
136: req.setAttribute("liferay-ui:tabs:onClick", String
137: .valueOf(_onClick));
138:
139: include(getStartPage());
140:
141: return EVAL_BODY_INCLUDE;
142: } catch (Exception e) {
143: throw new JspException(e);
144: }
145: }
146:
147: public int doEndTag() throws JspException {
148: try {
149: ServletRequest req = pageContext.getRequest();
150:
151: req.removeAttribute("liferay-ui:tabs:url0");
152: req.removeAttribute("liferay-ui:tabs:url1");
153: req.removeAttribute("liferay-ui:tabs:url2");
154: req.removeAttribute("liferay-ui:tabs:url3");
155: req.removeAttribute("liferay-ui:tabs:url4");
156: req.removeAttribute("liferay-ui:tabs:url5");
157: req.removeAttribute("liferay-ui:tabs:url6");
158: req.removeAttribute("liferay-ui:tabs:url7");
159: req.removeAttribute("liferay-ui:tabs:url8");
160: req.removeAttribute("liferay-ui:tabs:url9");
161:
162: include(getEndPage());
163:
164: return EVAL_PAGE;
165: } catch (Exception e) {
166: throw new JspException(e);
167: } finally {
168: _startPage = null;
169: _endPage = null;
170: _names = null;
171: _namesPos = 0;
172: _tabsValues = null;
173: _formName = StringPool.BLANK;
174: _param = "tabs1";
175: _value = null;
176: _portletURL = null;
177: _url = null;
178: _url0 = null;
179: _url1 = null;
180: _url2 = null;
181: _url3 = null;
182: _url4 = null;
183: _url5 = null;
184: _url6 = null;
185: _url7 = null;
186: _url8 = null;
187: _url9 = null;
188: _backURL = null;
189: _refresh = true;
190: _onClick = null;
191: }
192: }
193:
194: public String getStartPage() {
195: if (Validator.isNull(_startPage)) {
196: return _START_PAGE;
197: } else {
198: return _startPage;
199: }
200: }
201:
202: public void setStartPage(String startPage) {
203: _startPage = startPage;
204: }
205:
206: public String getEndPage() {
207: if (Validator.isNull(_endPage)) {
208: return _END_PAGE;
209: } else {
210: return _endPage;
211: }
212: }
213:
214: public void setEndPage(String endPage) {
215: _endPage = endPage;
216: }
217:
218: public void setNames(String names) {
219: _names = StringUtil.split(names);
220: }
221:
222: public void setTabsValues(String tabsValues) {
223: _tabsValues = StringUtil.split(tabsValues);
224: }
225:
226: public void setFormName(String formName) {
227: _formName = formName;
228: }
229:
230: public String getParam() {
231: return _param;
232: }
233:
234: public void setParam(String param) {
235: _param = param;
236: }
237:
238: public void setValue(String value) {
239: _value = value;
240: }
241:
242: public void setPortletURL(PortletURL portletURL) {
243: _portletURL = portletURL;
244: }
245:
246: public void setUrl(String url) {
247: _url = url;
248: }
249:
250: public void setUrl0(String url0) {
251: _url0 = url0;
252: }
253:
254: public void setUrl1(String url1) {
255: _url1 = url1;
256: }
257:
258: public void setUrl2(String url2) {
259: _url2 = url2;
260: }
261:
262: public void setUrl3(String url3) {
263: _url3 = url3;
264: }
265:
266: public void setUrl4(String url4) {
267: _url4 = url4;
268: }
269:
270: public void setUrl5(String url5) {
271: _url5 = url5;
272: }
273:
274: public void setUrl6(String url6) {
275: _url6 = url6;
276: }
277:
278: public void setUrl7(String url7) {
279: _url7 = url7;
280: }
281:
282: public void setUrl8(String url8) {
283: _url8 = url8;
284: }
285:
286: public void setUrl9(String url9) {
287: _url9 = url9;
288: }
289:
290: public void setBackURL(String backURL) {
291: _backURL = backURL;
292: }
293:
294: public boolean isRefresh() {
295: return _refresh;
296: }
297:
298: public void setRefresh(boolean refresh) {
299: _refresh = refresh;
300: }
301:
302: public String getOnClick() {
303: return _onClick;
304: }
305:
306: public void setOnClick(String onClick) {
307: _onClick = onClick;
308: }
309:
310: public String getSectionName() {
311: if (_names.length > _namesPos) {
312: return _names[_namesPos];
313: } else {
314: return StringPool.BLANK;
315: }
316: }
317:
318: public boolean getSectionSelected() {
319: if ((_names.length == 0)
320: || ((_names.length > _namesPos) && (_names[_namesPos]
321: .equals(_value)))) {
322:
323: return true;
324: } else {
325: return false;
326: }
327: }
328:
329: public void incrementSection() {
330: _namesPos++;
331: }
332:
333: private static final String _START_PAGE = "/html/taglib/ui/tabs/start.jsp";
334:
335: private static final String _END_PAGE = "/html/taglib/ui/tabs/end.jsp";
336:
337: private String _startPage;
338: private String _endPage;
339: private String[] _names;
340: private int _namesPos;
341: private String[] _tabsValues;
342: private String _formName;
343: private String _param = "tabs1";
344: private String _value;
345: private PortletURL _portletURL;
346: private String _url;
347: private String _url0;
348: private String _url1;
349: private String _url2;
350: private String _url3;
351: private String _url4;
352: private String _url5;
353: private String _url6;
354: private String _url7;
355: private String _url8;
356: private String _url9;
357: private String _backURL;
358: private boolean _refresh = true;
359: private String _onClick;
360:
361: }
|