1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.taglib.ui;
24  
25  import com.liferay.portal.kernel.util.JavaConstants;
26  import com.liferay.portal.kernel.util.StringPool;
27  import com.liferay.portal.kernel.util.Validator;
28  import com.liferay.taglib.util.ParamAndPropertyAncestorTagImpl;
29  
30  import javax.portlet.RenderResponse;
31  
32  import javax.servlet.http.HttpServletRequest;
33  import javax.servlet.jsp.JspException;
34  
35  /**
36   * <a href="SectionTag.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Brian Wing Shun Chan
39   */
40  public class SectionTag extends ParamAndPropertyAncestorTagImpl {
41  
42      public int doStartTag() throws JspException {
43          _tabsTag = (TabsTag)findAncestorWithClass(this, TabsTag.class);
44  
45          if (_tabsTag == null) {
46              throw new JspException();
47          }
48  
49          try {
50              HttpServletRequest request =
51                  (HttpServletRequest)pageContext.getRequest();
52  
53              RenderResponse renderResponse =
54                  (RenderResponse)request.getAttribute(
55                      JavaConstants.JAVAX_PORTLET_RESPONSE);
56  
57              String namespace = StringPool.BLANK;
58  
59              if (renderResponse != null) {
60                  namespace = renderResponse.getNamespace();
61              }
62  
63              String sectionParam = _tabsTag.getParam();
64              String sectionName = _tabsTag.getSectionName();
65              _sectionSelected = Boolean.valueOf(_tabsTag.getSectionSelected());
66              String sectionScroll = namespace + sectionParam + "TabsScroll";
67              String sectionRedirectParams =
68                  "&scroll=" + sectionScroll + "&" + sectionParam + "=" +
69                      sectionName;
70  
71              _tabsTag.incrementSection();
72  
73              request.setAttribute("liferay-ui:section:param", sectionParam);
74              request.setAttribute("liferay-ui:section:name", sectionName);
75              request.setAttribute(
76                  "liferay-ui:section:selected", _sectionSelected);
77              request.setAttribute("liferay-ui:section:scroll", sectionScroll);
78  
79              pageContext.setAttribute("sectionSelected", _sectionSelected);
80              pageContext.setAttribute("sectionParam", sectionParam);
81              pageContext.setAttribute("sectionName", sectionName);
82              pageContext.setAttribute("sectionScroll", sectionScroll);
83              pageContext.setAttribute(
84                  "sectionRedirectParams", sectionRedirectParams);
85  
86              if (!_tabsTag.isRefresh() || _sectionSelected.booleanValue()) {
87                  if (!_tabsTag.isRefresh()) {
88                      include(getStartPage());
89                  }
90  
91                  return EVAL_BODY_INCLUDE;
92              }
93              else {
94                  return EVAL_PAGE;
95              }
96          }
97          catch (Exception e) {
98              throw new JspException(e);
99          }
100     }
101 
102     public int doEndTag() throws JspException {
103         try {
104             if (!_tabsTag.isRefresh() || _sectionSelected.booleanValue()) {
105                 if (!_tabsTag.isRefresh()) {
106                     include(getEndPage());
107                 }
108 
109                 return EVAL_BODY_INCLUDE;
110             }
111             else {
112                 return EVAL_PAGE;
113             }
114         }
115         catch (Exception e) {
116             throw new JspException(e);
117         }
118     }
119 
120     public String getStartPage() {
121         if (Validator.isNull(_startPage)) {
122             return _START_PAGE;
123         }
124         else {
125             return _startPage;
126         }
127     }
128 
129     public void setStartPage(String startPage) {
130         _startPage = startPage;
131     }
132 
133     public String getEndPage() {
134         if (Validator.isNull(_endPage)) {
135             return _END_PAGE;
136         }
137         else {
138             return _endPage;
139         }
140     }
141 
142     public void setEndPage(String endPage) {
143         _endPage = endPage;
144     }
145 
146     private static final String _START_PAGE =
147         "/html/taglib/ui/section/start.jsp";
148 
149     private static final String _END_PAGE = "/html/taglib/ui/section/end.jsp";
150 
151     private String _startPage;
152     private String _endPage;
153     private TabsTag _tabsTag = null;
154     private Boolean _sectionSelected = Boolean.FALSE;
155 
156 }