KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > data > MediaConverter


1 /* *****************************************************************************
2  * MediaConverter.java
3 * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.data;
11
12 import java.io.*;
13 import java.net.MalformedURLException JavaDoc;
14
15 import javax.servlet.http.HttpServletRequest JavaDoc;
16 import javax.servlet.http.HttpServletResponse JavaDoc;
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 /**
26  * Media Converter
27  */

28 public class MediaConverter extends Converter {
29     
30     private static Logger mLogger = Logger.getLogger(MediaConverter.class);
31
32     /**
33      * Convert incoming Media to SWF
34      */

35     public InputStream convertToSWF(Data data, HttpServletRequest JavaDoc req,
36                                     HttpServletResponse JavaDoc res)
37         throws ConversionException, IOException {
38
39         String JavaDoc surl = null;
40         try {
41             surl = DataSource.getURL(req);
42         } catch (MalformedURLException JavaDoc e) {
43             throw new ChainedException(e);
44         }
45         int index = surl.indexOf('?');
46         String JavaDoc path = surl;
47         if (index > 0) {
48             path = surl.substring(0, index);
49         }
50
51         String JavaDoc mimeType = data.getMimeType();
52         if (!Transcoder.canTranscode(mimeType, MimeType.SWF)) {
53             // If we can't convert the content type, try from the extension
54
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, /* do stream audio */ true);
62         } catch (TranscoderException e) {
63             throw new ConversionException(e.getMessage());
64         }
65     }
66
67     /**
68      * media should be as is
69      */

70     public String JavaDoc chooseEncoding(HttpServletRequest JavaDoc req) {
71         return null;
72     }
73
74 }
75
Popular Tags