/*******************************************************************************
 * Copyright (c)2008 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

package org.eclipse.birt.report.engine.util;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.util.logging.Logger;

import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.batik.transcoder.image.JPEGTranscoder;

public class SvgFile
{

	private static Logger logger = Logger.getLogger( SvgFile.class.getName( ) );

	static boolean isSvg = false;

	public static boolean isSvg( String uri )
	{
		if ( uri != null && uri.endsWith( ".svg" ) )
		{
			isSvg = true;
		}
		else
		{
			isSvg = false;
		}
		return isSvg;
	}
	
	public static boolean isSvg( String mimeType, String uri, String extension )
	{
		isSvg = ( ( mimeType != null ) && mimeType
				.equalsIgnoreCase( "image/svg+xml" ) ) //$NON-NLS-1$
				|| ( ( uri != null ) && uri.toLowerCase( ).endsWith( ".svg" ) ) //$NON-NLS-1$
				|| ( ( extension != null ) && extension.toLowerCase( )
						.endsWith( ".svg" ) ); //$NON-NLS-1$
		return isSvg;
	}

	public static byte[] transSvgToArray( String uri ) throws Exception
	{
		InputStream in = new URL( uri ).openStream( );
		try
		{
			return transSvgToArray( in );
		}
		finally
		{
			in.close( );
		}
	}

	public static byte[] transSvgToArray( InputStream inputStream )
			throws Exception
	{
		JPEGTranscoder transcoder = new JPEGTranscoder( );
		// set the transcoding hints
		transcoder.addTranscodingHint( JPEGTranscoder.KEY_QUALITY, new Float(
				.8 ) );
		// create the transcoder input
		TranscoderInput input = new TranscoderInput( inputStream );
		// create the transcoder output
		ByteArrayOutputStream ostream = new ByteArrayOutputStream( );
		TranscoderOutput output = new TranscoderOutput( ostream );
		transcoder.transcode( input, output );
		// flush the stream
		ostream.flush( );
		// use the output stream as Image input stream.
		return ostream.toByteArray( );
	}
}

@@ -836,19 +836,18 @@
 r.image.
-JPE
+PN
 GTransco
@@ -1842,19 +1842,18 @@
 on%0A%09%7B%0A%09%09
-JPE
+PN
 GTransco
@@ -1873,19 +1873,18 @@
 r = new 
-JPE
+PN
 GTransco
@@ -1895,123 +1895,8 @@
  );%0A
-%09%09// set the transcoding hints%0A%09%09transcoder.addTranscodingHint( JPEGTranscoder.KEY_QUALITY, new Float(%0A%09%09%09%09.8 ) );%0A
 %09%09//

Refactor change SVG file from JPEG to PNG