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