1 4 5 9 10 package org.openlaszlo.data; 11 12 import java.io.*; 13 import java.net.MalformedURLException ; 14 15 import javax.servlet.http.HttpServletRequest ; 16 import javax.servlet.http.HttpServletResponse ; 17 18 import org.openlaszlo.media.MimeType; 19 import org.openlaszlo.media.Transcoder; 20 import org.openlaszlo.media.TranscoderException; 21 import org.openlaszlo.utils.ChainedException; 22 23 import org.apache.log4j.*; 24 25 28 public class MediaConverter extends Converter { 29 30 private static Logger mLogger = Logger.getLogger(MediaConverter.class); 31 32 35 public InputStream convertToSWF(Data data, HttpServletRequest req, 36 HttpServletResponse res) 37 throws ConversionException, IOException { 38 39 String surl = null; 40 try { 41 surl = DataSource.getURL(req); 42 } catch (MalformedURLException e) { 43 throw new ChainedException(e); 44 } 45 int index = surl.indexOf('?'); 46 String path = surl; 47 if (index > 0) { 48 path = surl.substring(0, index); 49 } 50 51 String mimeType = data.getMimeType(); 52 if (!Transcoder.canTranscode(mimeType, MimeType.SWF)) { 53 mimeType = MimeType.fromExtension(path); 55 } 56 57 mLogger.debug("calling transcoder on " + "mime type: " + mimeType); 58 59 try { 60 return Transcoder.transcode(data.getInputStream(), 61 mimeType, MimeType.SWF, true); 62 } catch (TranscoderException e) { 63 throw new ConversionException(e.getMessage()); 64 } 65 } 66 67 70 public String chooseEncoding(HttpServletRequest req) { 71 return null; 72 } 73 74 } 75 | Popular Tags |