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