1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.taglib.ui;
21  
22  import com.liferay.taglib.util.IncludeTag;
23  
24  import javax.servlet.http.HttpServletRequest;
25  import javax.servlet.jsp.JspException;
26  
27  /**
28   * <a href="IconTag.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   *
32   */
33  public class IconTag extends IncludeTag {
34  
35      public int doStartTag() {
36          HttpServletRequest request =
37              (HttpServletRequest)pageContext.getRequest();
38  
39          request.setAttribute("liferay-ui:icon:image", _image);
40          request.setAttribute("liferay-ui:icon:message", _message);
41          request.setAttribute("liferay-ui:icon:src", _src);
42          request.setAttribute("liferay-ui:icon:url", _url);
43          request.setAttribute("liferay-ui:icon:method", _method);
44          request.setAttribute("liferay-ui:icon:target", _target);
45          request.setAttribute("liferay-ui:icon:label", String.valueOf(_label));
46          request.setAttribute(
47              "liferay-ui:icon:toolTip", String.valueOf(_toolTip));
48          request.setAttribute("liferay-ui:icon:cssClass", _cssClass);
49  
50          return EVAL_BODY_BUFFERED;
51      }
52  
53      public int doEndTag() throws JspException {
54          int value = super.doEndTag();
55  
56          try {
57              HttpServletRequest request =
58                  (HttpServletRequest)pageContext.getRequest();
59  
60              request.removeAttribute("liferay-ui:icon:image");
61              request.removeAttribute("liferay-ui:icon:message");
62              request.removeAttribute("liferay-ui:icon:src");
63              request.removeAttribute("liferay-ui:icon:url");
64              request.removeAttribute("liferay-ui:icon:method");
65              request.removeAttribute("liferay-ui:icon:target");
66              request.removeAttribute("liferay-ui:icon:label");
67              request.removeAttribute("liferay-ui:icon:toolTip");
68              request.removeAttribute("liferay-ui:icon:cssClass");
69  
70              return value;
71          }
72          catch (Exception e) {
73              throw new JspException(e);
74          }
75          finally {
76              _image = null;
77              _message = null;
78              _src = null;
79              _url = null;
80              _method = null;
81              _target = null;
82              _label = false;
83              _toolTip = false;
84          }
85      }
86  
87      public void setImage(String image) {
88          _image = image;
89      }
90  
91      public void setMessage(String message) {
92          _message = message;
93      }
94  
95      public void setSrc(String src) {
96          _src = src;
97      }
98  
99      public void setUrl(String url) {
100         _url = url;
101     }
102 
103     public void setMethod(String method) {
104         _method = method;
105     }
106 
107     public void setTarget(String target) {
108         _target = target;
109     }
110 
111     public void setLabel(boolean label) {
112         _label = label;
113     }
114 
115     public void setToolTip(boolean toolTip) {
116         _toolTip = toolTip;
117     }
118 
119     public void setCssClass(String cssClass) {
120         _cssClass = cssClass;
121     }
122 
123     protected String getDefaultPage() {
124         return _PAGE;
125     }
126 
127     private static final String _PAGE = "/html/taglib/ui/icon/page.jsp";
128 
129     private String _image;
130     private String _message;
131     private String _src;
132     private String _url;
133     private String _method;
134     private String _target = "_self";
135     private boolean _label;
136     private boolean _toolTip = true;
137     private String _cssClass;
138 
139 }