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