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