001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.taglib.ui;
022:
023: import com.liferay.portal.kernel.servlet.StringServletResponse;
024: import com.liferay.taglib.util.IncludeTag;
025:
026: import java.io.IOException;
027:
028: import javax.servlet.RequestDispatcher;
029: import javax.servlet.ServletContext;
030: import javax.servlet.ServletException;
031: import javax.servlet.http.HttpServletRequest;
032: import javax.servlet.http.HttpServletResponse;
033: import javax.servlet.jsp.JspException;
034:
035: /**
036: * <a href="PngImageTag.java.html"><b><i>View Source</i></b></a>
037: *
038: * @author Brian Wing Shun Chan
039: *
040: */
041: public class PngImageTag extends IncludeTag {
042:
043: public static void doTag(String image, String height, String width,
044: ServletContext ctx, HttpServletRequest req,
045: HttpServletResponse res) throws IOException,
046: ServletException {
047:
048: doTag(_PAGE, image, height, width, ctx, req, res);
049: }
050:
051: public static void doTag(String page, String image, String height,
052: String width, ServletContext ctx, HttpServletRequest req,
053: HttpServletResponse res) throws IOException,
054: ServletException {
055:
056: req.setAttribute("liferay-ui:png_image:image", image);
057: req.setAttribute("liferay-ui:png_image:height", height);
058: req.setAttribute("liferay-ui:png_image:width", width);
059:
060: RequestDispatcher rd = ctx.getRequestDispatcher(page);
061:
062: rd.include(req, res);
063: }
064:
065: public int doEndTag() throws JspException {
066: try {
067: ServletContext ctx = getServletContext();
068: HttpServletRequest req = getServletRequest();
069: StringServletResponse res = getServletResponse();
070:
071: doTag(_image, _height, _width, ctx, req, res);
072:
073: pageContext.getOut().print(res.getString());
074:
075: return EVAL_PAGE;
076: } catch (Exception e) {
077: throw new JspException(e);
078: }
079: }
080:
081: public void setImage(String image) {
082: _image = image;
083: }
084:
085: public void setHeight(String height) {
086: _height = height;
087: }
088:
089: public void setWidth(String width) {
090: _width = width;
091: }
092:
093: protected String getDefaultPage() {
094: return _PAGE;
095: }
096:
097: private static final String _PAGE = "/html/taglib/ui/png_image/page.jsp";
098:
099: private String _image;
100: private String _height;
101: private String _width;
102:
103: }
|