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.JavaConstants;
024: import com.liferay.portal.kernel.util.StringPool;
025: import com.liferay.portal.kernel.util.Validator;
026: import com.liferay.taglib.util.ParamAncestorTagImpl;
027:
028: import javax.portlet.RenderResponse;
029:
030: import javax.servlet.ServletRequest;
031: import javax.servlet.jsp.JspException;
032:
033: /**
034: * <a href="SectionTag.java.html"><b><i>View Source</i></b></a>
035: *
036: * @author Brian Wing Shun Chan
037: *
038: */
039: public class SectionTag extends ParamAncestorTagImpl {
040:
041: public int doStartTag() throws JspException {
042: _tabsTag = (TabsTag) findAncestorWithClass(this , TabsTag.class);
043:
044: if (_tabsTag == null) {
045: throw new JspException();
046: }
047:
048: try {
049: ServletRequest req = pageContext.getRequest();
050:
051: RenderResponse renderResponse = (RenderResponse) req
052: .getAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE);
053:
054: String namespace = StringPool.BLANK;
055:
056: if (renderResponse != null) {
057: namespace = renderResponse.getNamespace();
058: }
059:
060: String sectionParam = _tabsTag.getParam();
061: String sectionName = _tabsTag.getSectionName();
062: _sectionSelected = Boolean.valueOf(_tabsTag
063: .getSectionSelected());
064: String sectionScroll = namespace + sectionParam
065: + "TabsScroll";
066: String sectionRedirectParams = "&scroll=" + sectionScroll
067: + "&" + sectionParam + "=" + sectionName;
068:
069: _tabsTag.incrementSection();
070:
071: req.setAttribute("liferay-ui:section:param", sectionParam);
072: req.setAttribute("liferay-ui:section:name", sectionName);
073: req.setAttribute("liferay-ui:section:selected",
074: _sectionSelected);
075: req
076: .setAttribute("liferay-ui:section:scroll",
077: sectionScroll);
078:
079: pageContext.setAttribute("sectionSelected",
080: _sectionSelected);
081: pageContext.setAttribute("sectionParam", sectionParam);
082: pageContext.setAttribute("sectionName", sectionName);
083: pageContext.setAttribute("sectionScroll", sectionScroll);
084: pageContext.setAttribute("sectionRedirectParams",
085: sectionRedirectParams);
086:
087: if (!_tabsTag.isRefresh()
088: || _sectionSelected.booleanValue()) {
089: if (!_tabsTag.isRefresh()) {
090: include(getStartPage());
091: }
092:
093: return EVAL_BODY_INCLUDE;
094: } else {
095: return EVAL_PAGE;
096: }
097: } catch (Exception e) {
098: throw new JspException(e);
099: }
100: }
101:
102: public int doEndTag() throws JspException {
103: try {
104: if (!_tabsTag.isRefresh()
105: || _sectionSelected.booleanValue()) {
106: if (!_tabsTag.isRefresh()) {
107: include(getEndPage());
108: }
109:
110: return EVAL_BODY_INCLUDE;
111: } else {
112: return EVAL_PAGE;
113: }
114: } catch (Exception e) {
115: throw new JspException(e);
116: }
117: }
118:
119: public String getStartPage() {
120: if (Validator.isNull(_startPage)) {
121: return _START_PAGE;
122: } else {
123: return _startPage;
124: }
125: }
126:
127: public void setStartPage(String startPage) {
128: _startPage = startPage;
129: }
130:
131: public String getEndPage() {
132: if (Validator.isNull(_endPage)) {
133: return _END_PAGE;
134: } else {
135: return _endPage;
136: }
137: }
138:
139: public void setEndPage(String endPage) {
140: _endPage = endPage;
141: }
142:
143: private static final String _START_PAGE = "/html/taglib/ui/section/start.jsp";
144:
145: private static final String _END_PAGE = "/html/taglib/ui/section/end.jsp";
146:
147: private String _startPage;
148: private String _endPage;
149: private TabsTag _tabsTag = null;
150: private Boolean _sectionSelected = Boolean.FALSE;
151:
152: }
|