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.ServerDetector;
26  import com.liferay.taglib.util.IncludeTag;
27  
28  import javax.servlet.http.HttpServletRequest;
29  import javax.servlet.jsp.JspException;
30  
31  /**
32   * <a href="IconTag.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   */
36  public class IconTag extends IncludeTag {
37  
38      public int doStartTag() {
39          HttpServletRequest request =
40              (HttpServletRequest)pageContext.getRequest();
41  
42          request.setAttribute("liferay-ui:icon:image", _image);
43          request.setAttribute("liferay-ui:icon:imageHover", _imageHover);
44          request.setAttribute("liferay-ui:icon:message", _message);
45          request.setAttribute("liferay-ui:icon:src", _src);
46          request.setAttribute("liferay-ui:icon:srcHover", _srcHover);
47          request.setAttribute("liferay-ui:icon:url", _url);
48          request.setAttribute("liferay-ui:icon:method", _method);
49          request.setAttribute("liferay-ui:icon:target", _target);
50          request.setAttribute("liferay-ui:icon:label", String.valueOf(_label));
51          request.setAttribute(
52              "liferay-ui:icon:toolTip", String.valueOf(_toolTip));
53          request.setAttribute("liferay-ui:icon:cssClass", _cssClass);
54  
55          return EVAL_BODY_BUFFERED;
56      }
57  
58      public int doEndTag() throws JspException {
59          int value = super.doEndTag();
60  
61          try {
62              HttpServletRequest request =
63                  (HttpServletRequest)pageContext.getRequest();
64  
65              request.removeAttribute("liferay-ui:icon:image");
66              request.removeAttribute("liferay-ui:icon:imageHover");
67              request.removeAttribute("liferay-ui:icon:message");
68              request.removeAttribute("liferay-ui:icon:src");
69              request.removeAttribute("liferay-ui:icon:srcHover");
70              request.removeAttribute("liferay-ui:icon:url");
71              request.removeAttribute("liferay-ui:icon:method");
72              request.removeAttribute("liferay-ui:icon:target");
73              request.removeAttribute("liferay-ui:icon:label");
74              request.removeAttribute("liferay-ui:icon:toolTip");
75              request.removeAttribute("liferay-ui:icon:cssClass");
76  
77              return value;
78          }
79          catch (Exception e) {
80              throw new JspException(e);
81          }
82          finally {
83              if (!ServerDetector.isResin()) {
84                  _image = null;
85                  _imageHover = null;
86                  _message = null;
87                  _src = null;
88                  _srcHover = null;
89                  _url = null;
90                  _method = null;
91                  _target = null;
92                  _label = false;
93                  _toolTip = false;
94                  _cssClass = null;
95              }
96          }
97      }
98  
99      public void setImage(String image) {
100         _image = image;
101     }
102 
103     public void setImageHover(String imageHover) {
104         _imageHover = imageHover;
105     }
106 
107     public void setMessage(String message) {
108         _message = message;
109     }
110 
111     public void setSrc(String src) {
112         _src = src;
113     }
114 
115     public void setSrcHover(String srcHover) {
116         _srcHover = srcHover;
117     }
118 
119     public void setUrl(String url) {
120         _url = url;
121     }
122 
123     public void setMethod(String method) {
124         _method = method;
125     }
126 
127     public void setTarget(String target) {
128         _target = target;
129     }
130 
131     public void setLabel(boolean label) {
132         _label = label;
133     }
134 
135     public void setToolTip(boolean toolTip) {
136         _toolTip = toolTip;
137     }
138 
139     public void setCssClass(String cssClass) {
140         _cssClass = cssClass;
141     }
142 
143     protected String getDefaultPage() {
144         return _PAGE;
145     }
146 
147     private static final String _PAGE = "/html/taglib/ui/icon/page.jsp";
148 
149     private String _image;
150     private String _imageHover;
151     private String _message;
152     private String _src;
153     private String _srcHover;
154     private String _url;
155     private String _method;
156     private String _target = "_self";
157     private boolean _label;
158     private boolean _toolTip = true;
159     private String _cssClass;
160 
161 }