KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > krysalis > jcharts > encoders > ServletEncoderHelper


1 /***********************************************************************************************
2  * Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
3  *
4  * Redistribution and use of this software and associated documentation ("Software"), with or
5  * without modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain copyright statements and notices.
8  * Redistributions must also contain a copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
11  * conditions and the following disclaimer in the documentation and/or other materials
12  * provided with the distribution.
13  *
14  * 3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to endorse or promote
15  * products derived from this Software without prior written permission of Nathaniel G.
16  * Auvil. For written permission, please contact nathaniel_auvil@users.sourceforge.net
17  *
18  * 4. Products derived from this Software may not be called "jCharts" nor may "jCharts" appear
19  * in their names without prior written permission of Nathaniel G. Auvil. jCharts is a
20  * registered trademark of Nathaniel G. Auvil.
21  *
22  * 5. Due credit should be given to the jCharts Project (http://jcharts.sourceforge.net/).
23  *
24  * THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS ``AS IS'' AND ANY
25  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
27  * jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
32  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
33  ************************************************************************************************/

34
35
36 package org.krysalis.jcharts.encoders;
37
38
39 import org.krysalis.jcharts.Chart;
40 import org.krysalis.jcharts.chartData.ChartDataException;
41 import org.krysalis.jcharts.properties.PropertyException;
42
43 import javax.servlet.http.HttpServletResponse JavaDoc;
44 import java.io.IOException JavaDoc;
45
46
47 /*************************************************************************************
48  *
49  * @author Nathaniel Auvil
50  * @version $Id: ServletEncoderHelper.java,v 1.2 2003/05/26 13:40:21 nathaniel_auvil Exp $
51  ************************************************************************************/

52 public class ServletEncoderHelper
53 {
54     public static final String JavaDoc SVG_MIME_TYPE = "image/svg+xml";
55     public static final String JavaDoc PNG_MIME_TYPE = "image/png";
56     public static final String JavaDoc JPEG_MIME_TYPE = "image/jpeg";
57
58
59     /******************************************************************************************
60      * Convenience method to call from a Servlet or JSP. This method will set the appropriate
61      * mime type and then export the chart as the response.
62      *
63      * We cannot overload encode(...) as it will create a compile time dependency with the
64      * HttpServletResponse Class which will require the J2EE libraries.
65      *
66      * @param chart
67      * @param httpServletResponse
68      * @throws ChartDataException
69      * @throws PropertyException
70      * @throws IOException
71      * @since 0.7
72      ******************************************************************************************/

73     public static void encodeServlet( Chart chart, HttpServletResponse JavaDoc httpServletResponse ) throws ChartDataException, PropertyException, IOException JavaDoc
74     {
75         httpServletResponse.setContentType( SVG_MIME_TYPE );
76         SVGEncoder.encode( chart, httpServletResponse.getOutputStream() );
77     }
78
79
80     /******************************************************************************************
81      * Convenience method to call from a Servlet or JSP. This method will set the appropriate
82      * mime type and then export the chart as the response.
83      *
84      * We cannot overload encode(...) as it will create a compile time dependency with the
85      * HttpServletResponse Class which will require the J2EE libraries.
86      *
87      * @param chart
88      * @param quality float value from 0.0f(worst image quality) - 1.0f(best image quality)
89      * @param httpServletResponse
90      * @throws ChartDataException
91      * @throws PropertyException
92      * @throws IOException
93      * @since 0.7
94      ******************************************************************************************/

95     public static void encodeJPEG13( Chart chart,
96                                                 float quality,
97                                                 HttpServletResponse JavaDoc httpServletResponse ) throws ChartDataException, PropertyException, IOException JavaDoc
98     {
99         httpServletResponse.setContentType( JPEG_MIME_TYPE );
100         JPEGEncoder13.encode( chart, quality, httpServletResponse.getOutputStream() );
101     }
102
103
104     /******************************************************************************************
105      * Convenience method to call from a Servlet or JSP. This method will set the appropriate
106      * mime type and then export the chart as the response.
107      *
108      * @param chart
109      * @param quality float value from 0.0f(worst image quality) - 1.0f(best image quality)
110      * @param httpServletResponse
111      * @throws ChartDataException
112      * @throws PropertyException
113      * @throws IOException
114      ******************************************************************************************/

115     public static void encodeJPEG( Chart chart,
116                                              float quality,
117                                              HttpServletResponse JavaDoc httpServletResponse ) throws ChartDataException, PropertyException, IOException JavaDoc
118     {
119         httpServletResponse.setContentType( JPEG_MIME_TYPE );
120         JPEGEncoder.encode( chart, quality, httpServletResponse.getOutputStream() );
121     }
122
123
124     /******************************************************************************************
125      * Convenience method to call from a Servlet or JSP. This method will set the appropriate
126      * mime type and then export the chart as the response.
127      *
128      * @param chart
129      * @param httpServletResponse
130      * @throws ChartDataException
131      * @throws PropertyException
132      * @throws java.io.IOException
133      ******************************************************************************************/

134     public static void encodePNG( Chart chart, HttpServletResponse JavaDoc httpServletResponse ) throws ChartDataException, PropertyException, IOException JavaDoc
135     {
136         httpServletResponse.setContentType( PNG_MIME_TYPE );
137         PNGEncoder.encode( chart, httpServletResponse.getOutputStream() );
138     }
139
140
141 }
142
Popular Tags