1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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   */
37  public class IconTag extends IncludeTag {
38  
39      public int doStartTag() {
40          HttpServletRequest request =
41              (HttpServletRequest)pageContext.getRequest();
42  
43          request.setAttribute("liferay-ui:icon:image", _image);
44          request.setAttribute("liferay-ui:icon:imageHover", _imageHover);
45          request.setAttribute("liferay-ui:icon:message", _message);
46          request.setAttribute("liferay-ui:icon:src", _src);
47          request.setAttribute("liferay-ui:icon:srcHover", _srcHover);
48          request.setAttribute("liferay-ui:icon:url", _url);
49          request.setAttribute("liferay-ui:icon:method", _method);
50          request.setAttribute("liferay-ui:icon:target", _target);
51          request.setAttribute("liferay-ui:icon:label", String.valueOf(_label));
52          request.setAttribute(
53              "liferay-ui:icon:toolTip", String.valueOf(_toolTip));
54          request.setAttribute("liferay-ui:icon:cssClass", _cssClass);
55  
56          return EVAL_BODY_BUFFERED;
57      }
58  
59      public int doEndTag() throws JspException {
60          int value = super.doEndTag();
61  
62          try {
63              HttpServletRequest request =
64                  (HttpServletRequest)pageContext.getRequest();
65  
66              request.removeAttribute("liferay-ui:icon:image");
67              request.removeAttribute("liferay-ui:icon:imageHover");
68              request.removeAttribute("liferay-ui:icon:message");
69              request.removeAttribute("liferay-ui:icon:src");
70              request.removeAttribute("liferay-ui:icon:srcHover");
71              request.removeAttribute("liferay-ui:icon:url");
72              request.removeAttribute("liferay-ui:icon:method");
73              request.removeAttribute("liferay-ui:icon:target");
74              request.removeAttribute("liferay-ui:icon:label");
75              request.removeAttribute("liferay-ui:icon:toolTip");
76              request.removeAttribute("liferay-ui:icon:cssClass");
77  
78              return value;
79          }
80          catch (Exception e) {
81              throw new JspException(e);
82          }
83          finally {
84              if (!ServerDetector.isResin()) {
85                  _image = null;
86                  _imageHover = null;
87                  _message = null;
88                  _src = null;
89                  _srcHover = null;
90                  _url = null;
91                  _method = null;
92                  _target = null;
93                  _label = false;
94                  _toolTip = false;
95                  _cssClass = null;
96              }
97          }
98      }
99  
100     public void setImage(String image) {
101         _image = image;
102     }
103 
104     public void setImageHover(String imageHover) {
105         _imageHover = imageHover;
106     }
107 
108     public void setMessage(String message) {
109         _message = message;
110     }
111 
112     public void setSrc(String src) {
113         _src = src;
114     }
115 
116     public void setSrcHover(String srcHover) {
117         _srcHover = srcHover;
118     }
119 
120     public void setUrl(String url) {
121         _url = url;
122     }
123 
124     public void setMethod(String method) {
125         _method = method;
126     }
127 
128     public void setTarget(String target) {
129         _target = target;
130     }
131 
132     public void setLabel(boolean label) {
133         _label = label;
134     }
135 
136     public void setToolTip(boolean toolTip) {
137         _toolTip = toolTip;
138     }
139 
140     public void setCssClass(String cssClass) {
141         _cssClass = cssClass;
142     }
143 
144     protected String getDefaultPage() {
145         return _PAGE;
146     }
147 
148     private static final String _PAGE = "/html/taglib/ui/icon/page.jsp";
149 
150     private String _image;
151     private String _imageHover;
152     private String _message;
153     private String _src;
154     private String _srcHover;
155     private String _url;
156     private String _method;
157     private String _target = "_self";
158     private boolean _label;
159     private boolean _toolTip = true;
160     private String _cssClass;
161 
162 }