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.portal.kernel.servlet.StringServletResponse;
23  import com.liferay.taglib.util.IncludeTag;
24  
25  import java.io.IOException;
26  
27  import javax.servlet.RequestDispatcher;
28  import javax.servlet.ServletContext;
29  import javax.servlet.ServletException;
30  import javax.servlet.http.HttpServletRequest;
31  import javax.servlet.http.HttpServletResponse;
32  import javax.servlet.jsp.JspException;
33  
34  /**
35   * <a href="PngImageTag.java.html"><b><i>View Source</i></b></a>
36   *
37   * @author Brian Wing Shun Chan
38   *
39   */
40  public class PngImageTag extends IncludeTag {
41  
42      public static void doTag(
43              String image, String height, String width,
44              ServletContext servletContext, HttpServletRequest request,
45              HttpServletResponse response)
46          throws IOException, ServletException {
47  
48          doTag(_PAGE, image, height, width, servletContext, request, response);
49      }
50  
51      public static void doTag(
52              String page, String image, String height, String width,
53              ServletContext servletContext, HttpServletRequest request,
54              HttpServletResponse response)
55          throws IOException, ServletException {
56  
57          request.setAttribute("liferay-ui:png_image:image", image);
58          request.setAttribute("liferay-ui:png_image:height", height);
59          request.setAttribute("liferay-ui:png_image:width", width);
60  
61          RequestDispatcher requestDispatcher =
62              servletContext.getRequestDispatcher(page);
63  
64          requestDispatcher.include(request, response);
65      }
66  
67      public int doEndTag() throws JspException {
68          try {
69              ServletContext servletContext = getServletContext();
70              HttpServletRequest request = getServletRequest();
71              StringServletResponse response = getServletResponse();
72  
73              doTag(
74                  getPage(), _image, _height, _width, servletContext, request,
75                  response);
76  
77              pageContext.getOut().print(response.getString());
78  
79              return EVAL_PAGE;
80          }
81          catch (Exception e) {
82              throw new JspException(e);
83          }
84      }
85  
86      public void setImage(String image) {
87          _image = image;
88      }
89  
90      public void setHeight(String height) {
91          _height = height;
92      }
93  
94      public void setWidth(String width) {
95          _width = width;
96      }
97  
98      protected String getDefaultPage() {
99          return _PAGE;
100     }
101 
102     private static final String _PAGE = "/html/taglib/ui/png_image/page.jsp";
103 
104     private String _image;
105     private String _height;
106     private String _width;
107 
108 }