001: /***********************************************************************************************
002: * Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
003: *
004: * Redistribution and use of this software and associated documentation ("Software"), with or
005: * without modification, are permitted provided that the following conditions are met:
006: *
007: * 1. Redistributions of source code must retain copyright statements and notices.
008: * Redistributions must also contain a copy of this document.
009: *
010: * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
011: * conditions and the following disclaimer in the documentation and/or other materials
012: * provided with the distribution.
013: *
014: * 3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to endorse or promote
015: * products derived from this Software without prior written permission of Nathaniel G.
016: * Auvil. For written permission, please contact nathaniel_auvil@users.sourceforge.net
017: *
018: * 4. Products derived from this Software may not be called "jCharts" nor may "jCharts" appear
019: * in their names without prior written permission of Nathaniel G. Auvil. jCharts is a
020: * registered trademark of Nathaniel G. Auvil.
021: *
022: * 5. Due credit should be given to the jCharts Project (http://jcharts.sourceforge.net/).
023: *
024: * THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS ``AS IS'' AND ANY
025: * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
026: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
028: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
029: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
030: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,STRICT LIABILITY, OR TORT
031: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
032: * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
033: ************************************************************************************************/package org.krysalis.jcharts.encoders;
034:
035: import org.krysalis.jcharts.Chart;
036: import org.krysalis.jcharts.chartData.ChartDataException;
037: import org.krysalis.jcharts.properties.PropertyException;
038:
039: import javax.servlet.http.HttpServletResponse;
040: import java.io.IOException;
041:
042: /*************************************************************************************
043: *
044: * @author Nathaniel Auvil
045: * @version $Id: ServletEncoderHelper.java,v 1.2 2003/05/26 13:40:21 nathaniel_auvil Exp $
046: ************************************************************************************/
047: public class ServletEncoderHelper {
048: public static final String SVG_MIME_TYPE = "image/svg+xml";
049: public static final String PNG_MIME_TYPE = "image/png";
050: public static final String JPEG_MIME_TYPE = "image/jpeg";
051:
052: /******************************************************************************************
053: * Convenience method to call from a Servlet or JSP. This method will set the appropriate
054: * mime type and then export the chart as the response.
055: *
056: * We cannot overload encode(...) as it will create a compile time dependency with the
057: * HttpServletResponse Class which will require the J2EE libraries.
058: *
059: * @param chart
060: * @param httpServletResponse
061: * @throws ChartDataException
062: * @throws PropertyException
063: * @throws IOException
064: * @since 0.7
065: ******************************************************************************************/
066: public static void encodeServlet(Chart chart,
067: HttpServletResponse httpServletResponse)
068: throws ChartDataException, PropertyException, IOException {
069: httpServletResponse.setContentType(SVG_MIME_TYPE);
070: SVGEncoder.encode(chart, httpServletResponse.getOutputStream());
071: }
072:
073: /******************************************************************************************
074: * Convenience method to call from a Servlet or JSP. This method will set the appropriate
075: * mime type and then export the chart as the response.
076: *
077: * We cannot overload encode(...) as it will create a compile time dependency with the
078: * HttpServletResponse Class which will require the J2EE libraries.
079: *
080: * @param chart
081: * @param quality float value from 0.0f(worst image quality) - 1.0f(best image quality)
082: * @param httpServletResponse
083: * @throws ChartDataException
084: * @throws PropertyException
085: * @throws IOException
086: * @since 0.7
087: ******************************************************************************************/
088: public static void encodeJPEG13(Chart chart, float quality,
089: HttpServletResponse httpServletResponse)
090: throws ChartDataException, PropertyException, IOException {
091: httpServletResponse.setContentType(JPEG_MIME_TYPE);
092: JPEGEncoder13.encode(chart, quality, httpServletResponse
093: .getOutputStream());
094: }
095:
096: /******************************************************************************************
097: * Convenience method to call from a Servlet or JSP. This method will set the appropriate
098: * mime type and then export the chart as the response.
099: *
100: * @param chart
101: * @param quality float value from 0.0f(worst image quality) - 1.0f(best image quality)
102: * @param httpServletResponse
103: * @throws ChartDataException
104: * @throws PropertyException
105: * @throws IOException
106: ******************************************************************************************/
107: public static void encodeJPEG(Chart chart, float quality,
108: HttpServletResponse httpServletResponse)
109: throws ChartDataException, PropertyException, IOException {
110: httpServletResponse.setContentType(JPEG_MIME_TYPE);
111: JPEGEncoder.encode(chart, quality, httpServletResponse
112: .getOutputStream());
113: }
114:
115: /******************************************************************************************
116: * Convenience method to call from a Servlet or JSP. This method will set the appropriate
117: * mime type and then export the chart as the response.
118: *
119: * @param chart
120: * @param httpServletResponse
121: * @throws ChartDataException
122: * @throws PropertyException
123: * @throws java.io.IOException
124: ******************************************************************************************/
125: public static void encodePNG(Chart chart,
126: HttpServletResponse httpServletResponse)
127: throws ChartDataException, PropertyException, IOException {
128: httpServletResponse.setContentType(PNG_MIME_TYPE);
129: PNGEncoder.encode(chart, httpServletResponse.getOutputStream());
130: }
131:
132: }
|