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  import com.liferay.util.TextFormatter;
22  
23  import java.util.HashMap;
24  import java.util.Map;
25  
26  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.jsp.JspException;
28  import javax.servlet.jsp.tagext.DynamicAttributes;
29  
30  /**
31   * <a href="FieldWrapperTag.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Julio Camarero
34   * @author Jorge Ferrer
35   * @author Brian Wing Shun Chan
36   */
37  public class FieldWrapperTag extends IncludeTag implements DynamicAttributes {
38  
39      public int doEndTag() throws JspException {
40          try{
41              PortalIncludeUtil.include(pageContext, getEndPage());
42  
43              return EVAL_PAGE;
44          }
45          catch (Exception e) {
46              throw new JspException(e);
47          }
48          finally {
49              if (!ServerDetector.isResin()) {
50                  _cssClass = null;
51                  _dynamicAttributes.clear();
52                  _endPage = null;
53                  _first = false;
54                  _helpMessage = null;
55                  _inlineField = false;
56                  _inlineLabel = null;
57                  _label = null;
58                  _last = false;
59                  _name = null;
60                  _startPage = null;
61              }
62          }
63      }
64  
65      public int doStartTag() throws JspException {
66          try{
67              HttpServletRequest request =
68                  (HttpServletRequest)pageContext.getRequest();
69  
70              if (_label == null) {
71                  _label = TextFormatter.format(_name, TextFormatter.K);
72              }
73  
74              request.setAttribute("aui:field-wrapper:cssClass", _cssClass);
75              request.setAttribute(
76                  "aui:field-wrapper:dynamicAttributes", _dynamicAttributes);
77              request.setAttribute(
78                  "aui:field-wrapper:first", String.valueOf(_first));
79              request.setAttribute(
80                  "aui:field-wrapper:helpMessage", _helpMessage);
81              request.setAttribute(
82                  "aui:field-wrapper:inlineField", String.valueOf(_inlineField));
83              request.setAttribute("aui:field-wrapper:inlineLabel", _inlineLabel);
84              request.setAttribute("aui:field-wrapper:label", _label);
85              request.setAttribute(
86                  "aui:field-wrapper:last", String.valueOf(_last));
87              request.setAttribute("aui:field-wrapper:name", _name);
88  
89              PortalIncludeUtil.include(pageContext, getStartPage());
90  
91              return EVAL_BODY_INCLUDE;
92          }
93          catch (Exception e) {
94              throw new JspException(e);
95          }
96      }
97  
98      public String getEndPage() {
99          if (Validator.isNull(_endPage)) {
100             return _END_PAGE;
101         }
102         else {
103             return _endPage;
104         }
105     }
106 
107     public String getStartPage() {
108         if (Validator.isNull(_startPage)) {
109             return _START_PAGE;
110         }
111         else {
112             return _startPage;
113         }
114     }
115 
116     public void setCssClass(String cssClass) {
117         _cssClass = cssClass;
118     }
119 
120     public void setDynamicAttribute(
121         String uri, String localName, Object value) {
122 
123         _dynamicAttributes.put(localName, value);
124     }
125 
126     public void setEndPage(String endPage) {
127         _endPage = endPage;
128     }
129 
130     public void setFirst(boolean first) {
131         _first = first;
132     }
133 
134     public void setHelpMessage(String helpMessage) {
135         _helpMessage = helpMessage;
136     }
137 
138     public void setInlineField(boolean inlineField) {
139         _inlineField = inlineField;
140     }
141 
142     public void setInlineLabel(String inlineLabel) {
143         _inlineLabel = inlineLabel;
144     }
145 
146     public void setLabel(String label) {
147         _label = label;
148     }
149 
150     public void setLast(boolean last) {
151         _last = last;
152     }
153 
154     public void setName(String name) {
155         _name = name;
156     }
157 
158     public void setStartPage(String startPage) {
159         _startPage = startPage;
160     }
161 
162     private static final String _END_PAGE =
163         "/html/taglib/aui/field_wrapper/end.jsp";
164 
165     private static final String _START_PAGE =
166         "/html/taglib/aui/field_wrapper/start.jsp";
167 
168     private String _cssClass;
169     private Map<String, Object> _dynamicAttributes =
170         new HashMap<String, Object>();
171     private String _endPage;
172     private boolean _first;
173     private String _helpMessage;
174     private boolean _inlineField;
175     private String _inlineLabel;
176     private String _label;
177     private boolean _last;
178     private String _name;
179     private String _startPage;
180 
181 }