1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.taglib.aui;
16  
17  import com.liferay.portal.kernel.servlet.PortalIncludeUtil;
18  import com.liferay.portal.kernel.util.ServerDetector;
19  import com.liferay.portal.kernel.util.Validator;
20  import com.liferay.taglib.util.IncludeTag;
21  
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  import javax.servlet.http.HttpServletRequest;
26  import javax.servlet.jsp.JspException;
27  import javax.servlet.jsp.tagext.DynamicAttributes;
28  
29  /**
30   * <a href="ColumnTag.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Julio Camarero
33   * @author Jorge Ferrer
34   * @author Brian Wing Shun Chan
35   */
36  public class ColumnTag extends IncludeTag implements DynamicAttributes {
37  
38      public int doEndTag() throws JspException {
39          try{
40              PortalIncludeUtil.include(pageContext, getEndPage());
41  
42              return EVAL_PAGE;
43          }
44          catch (Exception e) {
45              throw new JspException(e);
46          }
47          finally {
48              if (!ServerDetector.isResin()) {
49                  _columnWidth = 0;
50                  _cssClass = null;
51                  _dynamicAttributes.clear();
52                  _endPage = null;
53                  _first = false;
54                  _last = false;
55                  _startPage = null;
56              }
57          }
58      }
59  
60      public int doStartTag() throws JspException {
61          try{
62              HttpServletRequest request =
63                  (HttpServletRequest)pageContext.getRequest();
64  
65              request.setAttribute(
66                  "aui:column:columnWidth", String.valueOf(_columnWidth));
67              request.setAttribute("aui:column:cssClass", _cssClass);
68              request.setAttribute(
69                  "aui:column:dynamicAttributes", _dynamicAttributes);
70              request.setAttribute(
71                  "aui:column:first", String.valueOf(_first));
72              request.setAttribute(
73                  "aui:column:last", String.valueOf(_last));
74  
75              PortalIncludeUtil.include(pageContext, getStartPage());
76  
77              return EVAL_BODY_INCLUDE;
78          }
79          catch (Exception e) {
80              throw new JspException(e);
81          }
82      }
83  
84      public String getEndPage() {
85          if (Validator.isNull(_endPage)) {
86              return _END_PAGE;
87          }
88          else {
89              return _endPage;
90          }
91      }
92  
93      public String getStartPage() {
94          if (Validator.isNull(_startPage)) {
95              return _START_PAGE;
96          }
97          else {
98              return _startPage;
99          }
100     }
101 
102     public void setColumnWidth(int columnWidth) {
103         _columnWidth = columnWidth;
104     }
105 
106     public void setCssClass(String cssClass) {
107         _cssClass = cssClass;
108     }
109 
110     public void setDynamicAttribute(
111         String uri, String localName, Object value) {
112 
113         _dynamicAttributes.put(localName, value);
114     }
115 
116     public void setEndPage(String endPage) {
117         _endPage = endPage;
118     }
119 
120     public void setFirst(boolean first) {
121         _first = first;
122     }
123 
124     public void setLast(boolean last) {
125         _last = last;
126     }
127 
128     public void setStartPage(String startPage) {
129         _startPage = startPage;
130     }
131 
132     private static final String _END_PAGE =
133         "/html/taglib/aui/column/end.jsp";
134 
135     private static final String _START_PAGE =
136         "/html/taglib/aui/column/start.jsp";
137 
138     private int _columnWidth;
139     private String _cssClass;
140     private Map<String, Object> _dynamicAttributes =
141         new HashMap<String, Object>();
142     private String _endPage;
143     private boolean _first;
144     private boolean _last;
145     private String _startPage;
146 
147 }