From: mh Date: Sat, 2 Mar 2002 11:34:15 +0000 (+0000) Subject: moved media handler implementations to mircoders/media for added flexibility. X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=eed379d582e04f6a9642358fbb5b7c4b427f969b;p=mir.git moved media handler implementations to mircoders/media for added flexibility. cleaned up set method in MediaHandlerImages (no more reflection). prepared set method in EntityAudio. --- diff --git a/source/mir/media/MediaHandlerAudio.java b/source/mir/media/MediaHandlerAudio.java deleted file mode 100755 index 4be2dd51..00000000 --- a/source/mir/media/MediaHandlerAudio.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * put your module comment here - */ - - -package mir.media; - -import java.util.*; - -import mir.entity.*; -import mir.misc.*; -import mir.storage.*; - - -/** - * Handles audio media, like mp3 and maybe it could also handle some other. - * It is MediaHandlerGeneric with different icons. - * - * @see mir.media.MediaHandlerGeneric - * @see mir.media.MirMedia - * @author mh - * @version 24.09.2001 - */ - -public class MediaHandlerAudio extends MediaHandlerGeneric implements MirMedia -{ - - private static String tinyIcon = MirConfig.getProp("Producer.Icon.TinyAudio"); - private static String bigIcon = MirConfig.getProp("Producer.Icon.BigAudio"); - - public String getTinyIcon() - { - return tinyIcon; - } - - public String getBigIcon() - { - return bigIcon; - } - - public String getIconAlt() - { - return "Audio"; - } - - public boolean isAudio() - { - return true; - } -} diff --git a/source/mir/media/MediaHandlerGeneric.java b/source/mir/media/MediaHandlerGeneric.java deleted file mode 100755 index a466a988..00000000 --- a/source/mir/media/MediaHandlerGeneric.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * put your module comment here - */ - - -package mir.media; - -import java.util.*; - -import mir.entity.*; -import mir.misc.*; -import mir.storage.*; - - -/** - * This is the Generic MediaHandler. It stores the media data on - * the filesystem and keeps basic metadata (size, type...) in the - * DB. Usually only representation needs to be overridden. - * See the MediaHandlerAudio class to see an example of how one - * could override it. - *

- * Most media handlers should override this class. - *

- * In theory, it could be used to handle miscellaneous media that - * we don't have entered in the media_type table, (like RTF documents, - * PS, PDF, etc..) - *

- * Of course it implements the MirMedia interface. - * - * @see mir.media.MirMedia - * @author mh - * @version 24.09.2001 - */ - -public class MediaHandlerGeneric implements MirMedia -{ - - protected String imageHost = MirConfig.getProp("Producer.Image.Host"); - protected String imageRoot = MirConfig.getProp("Producer.ImageRoot"); - protected Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+"log/media.log"); - public boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt ) - throws MirMediaException { - - String ext = mediaTypeEnt.getValue("name"); - String dir = MirConfig.getProp("Producer.Media.Path"); - String mediaHost = MirConfig.getProp("Producer.Media.Host"); - String mediaFname = ent.getId()+"."+ext; - String date = ent.getValue("date"); - String datePath = StringUtil.webdbDate2path(date); - Integer size = new Integer(uploadedData.length); - try { - FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData); - //if(FileUtil.write(dir+"/"+mediaFname, uploadedData)) { - //were done with the data, dereference. - uploadedData=null; - - ent.setValueForProperty("is_produced", "1"); - ent.setValueForProperty("icon_is_produced", "1"); - ent.setValueForProperty("publish_path",datePath+"/"+mediaFname); - //ent.setValueForProperty("publish_path", mediaFname); - ent.setValueForProperty("publish_server", mediaHost); - ent.setValueForProperty("size", size.toString()); - ent.update(); - } catch (Exception e) { - theLog.printError(e.toString()); - throw new MirMediaException(e.toString()); - } - - return true; - } - - //a class that will probably never get used.. - private byte[] getFile (String fileName) - throws MirMediaException { - - long size = FileUtil.getSize(fileName); - if (size < 0) return null; - - byte[] container = new byte[(int)size]; - - try { - FileUtil.read(fileName, container); - } catch (Exception e) { - theLog.printError(e.toString()); - throw new MirMediaException(e.toString()); - } - - return container; - } - - public byte[] get (Entity ent, Entity mediaTypeEnt) { - return null; - } - - public byte[] getIcon (Entity ent) { - return null; - } - - public String getStoragePath() - { - return MirConfig.getProp("Producer.Media.Path"); - } - - public String getIconStoragePath() - { - return MirConfig.getProp("Producer.Image.IconPath"); - } - - public String getPublishHost() - { - return MirConfig.getProp("Producer.Media.Host"); - } - - public String getTinyIcon() - { - return MirConfig.getProp("Producer.Icon.TinyText"); - } - - public String getBigIcon() - { - return MirConfig.getProp("Producer.Icon.BigText"); - } - - public String getIconAlt() - { - return "Generic media"; - } - - public String getURL(Entity ent, Entity mediaTypeEnt) - { - String stringSize = ent.getValue("size"); - if (stringSize == null) - return null; - int size = Integer.parseInt(stringSize, 10)/1024; - String title = ent.getValue("title")+ - " - "+mediaTypeEnt.getValue("name")+" "+ - size+" KB"; - return StringUtil.createURLLinks(ent.getValue("publish_server")+"/"+ - ent.getValue("publish_path"), title, imageRoot, getBigIcon()); - } - - public String getListView(Entity ent, Entity mediaTypeEnt) - { - //String title = ent.getValue("title")+ - // " - "+mediaTypeEnt.getValue("name")+" "+ - // ent.getValue("size")+" Bytes"; - return StringUtil.createIMGLinks(imageHost+ - getBigIcon(), null, null, null); - } - - public boolean isVideo() - { - return false; - } - - public boolean isAudio() - { - return false; - } - - public boolean isImage() - { - return false; - } - -} - - - diff --git a/source/mir/media/MediaHandlerImages.java b/source/mir/media/MediaHandlerImages.java deleted file mode 100755 index cd8c7c57..00000000 --- a/source/mir/media/MediaHandlerImages.java +++ /dev/null @@ -1,169 +0,0 @@ - -package mir.media; - -import java.lang.*; -import java.io.*; -import java.util.*; -import java.lang.reflect.*; - -import mir.misc.*; -import mir.entity.*; - -/** - * This class handles saving, fetching creating representations - * for all images. The image content is stored in the DB. The content is - * written out to a file at the ProducerImages level. - * Remember that Handlers for specific image types, Gif, Jpeg, etc.. - * should override it. - * It implements the MirMedia interface. - *

- * ok. this is a big hack, it's cause putting the image in the DB - * and fetching it from the DB needs low level db connections for - * some reason. Does anyone know how to get around this? - * -mh 25.09.2001 - * - * @see mir.media.MirMedia - * @author mh - * @version 24.09.2001 - */ - - -public class MediaHandlerImages implements MirMedia -{ - protected final String WEBDB_JPG="0"; - protected final String WEBDB_GIF="1"; - - protected String imageType="0"; - private Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+"log/media.log"); - - public byte[] get(Entity ent, Entity mediaTypeEnt) throws MirMediaException - { - byte[] image_data = null; - - try { - Method method = ent.getClass().getMethod("getImage",null); - image_data = (byte[])method.invoke(ent, null); - } catch ( NoSuchMethodException e) { - theLog.printDebugInfo("method lookup unsuccesful: "+e.toString()); - throw new MirMediaException(e.toString()); - } catch ( IllegalAccessException e) { - theLog.printDebugInfo("method illegal: "+e.toString()); - throw new MirMediaException(e.toString()); - } catch ( InvocationTargetException e) { - theLog.printDebugInfo("get: invocation target illegal: "+e.toString()); - throw new MirMediaException(e.toString()); - } - - - return image_data; - } - - public boolean set(byte[] uploadData, Entity ent, Entity mediaTypeEnt) - throws MirMediaException { - - try { - Class[] params = {byte[].class, String.class}; - theLog.printDebugInfo("NAME: "+ent.getClass().getName()+" "+ - mediaTypeEnt.getClass().getName()+" "+uploadData.length+" "+ - imageType); - Method method = ent.getClass().getMethod("setImage",params); - method.invoke(ent, new Object[] {uploadData, imageType}); - } catch ( NoSuchMethodException e) { - theLog.printDebugInfo("method lookup unsuccesful: "+e.toString()); - throw new MirMediaException(e.toString()); - } catch ( IllegalAccessException e) { - theLog.printDebugInfo("method illegal: "+e.toString()); - throw new MirMediaException(e.toString()); - } catch ( InvocationTargetException e) { - theLog.printDebugInfo("set: invocation target illegal: "+e.toString()); - throw new MirMediaException(e.toString()); - } - //deref. -mh - uploadData=null; - - return true; - } - - public byte[] getIcon(Entity ent) throws MirMediaException - { - byte[] icon_data = null; - - try { - Method method = ent.getClass().getMethod("getIcon",null); - icon_data = (byte[])method.invoke(ent, null); - } catch ( NoSuchMethodException e) { - theLog.printDebugInfo("method lookup unsuccesful: "+e.toString()); - throw new MirMediaException(e.toString()); - } catch ( IllegalAccessException e) { - theLog.printDebugInfo("method illegal: "+e.toString()); - throw new MirMediaException(e.toString()); - } catch ( InvocationTargetException e) { - theLog.printDebugInfo("getIcon: invocation target illegal: "+e.toString()); - throw new MirMediaException(e.toString()); - } - - return icon_data; - } - - public String getURL(Entity ent, Entity mediaTypeEnt) - { - String title = ent.getValue("title"); - return StringUtil.createIMGLinks(ent.getValue("publish_server")+ - ent.getValue("publish_path"), title, ent.getValue("img_height"), - ent.getValue("img_width")); - } - - public String getListView(Entity ent, Entity mediaTypeEnt) - { - //String title = ent.getValue("title"); - return StringUtil.createIMGLinks( MirConfig.getProp("Producer.ProductionHost")+ - ent.getValue("icon_path"), null, ent.getValue("icon_height"), - ent.getValue("icon_width")); - } - - public String getStoragePath() - { - return MirConfig.getProp("Producer.Image.Path"); - } - - public String getIconStoragePath() - { - return MirConfig.getProp("Producer.Image.IconPath"); - } - - public String getPublishHost() - { - return MirConfig.getProp("Producer.Image.Host"); - } - - public String getTinyIcon () - { - return MirConfig.getProp("Producer.Icon.TinyImage"); - } - - public String getBigIcon () - { - return MirConfig.getProp("Producer.Icon.BigImage"); - } - - public String getIconAlt () - { - return "Image"; - } - - public boolean isVideo () - { - return false; - } - - public boolean isAudio () - { - return false; - } - - public boolean isImage () - { - return true; - } - -} diff --git a/source/mir/media/MediaHandlerMp3.java b/source/mir/media/MediaHandlerMp3.java deleted file mode 100755 index 0357a02b..00000000 --- a/source/mir/media/MediaHandlerMp3.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * put your module comment here - */ - - -package mir.media; - -import java.util.*; - -import mir.entity.*; -import mir.misc.*; -import mir.storage.*; - - -/** - * Please note: this media handler produces - * 3 media files, the raw .mp3, a .m3u which is - * contains the URL for the mp3 and a .pls which - * contains the URL to the mp3 in shoutcast playlist - * format. What's important is that the web server (of - * the media host) must recognize the .m3u and .pls file - * extensions and send the proper "audio/x-mpegurl" - * and "audio/x-scpls" mime-types respectively. - * If the web server is apache, it's easy, just - * add: - * - * audio/x-mpegurl m3u - * audio/x-scpl pls - * - * to the file pointed to by the "TypesConfig" - * command in your apache config file. Or add - * and equivalent AddType command to your httpd.conf. - * Of course this assumes that the mod_mime is loaded. - * - * If the web server is not apache, then your on your own. - * - * @see mir.media.MirMedia - * @author mh - * @version 01.12.2001 - */ - -public class MediaHandlerMp3 extends MediaHandlerAudio implements MirMedia -{ - - public boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt ) - throws MirMediaException { - - String ext = mediaTypeEnt.getValue("name"); - String dir = MirConfig.getProp("Producer.Media.Path"); - String mediaHost = MirConfig.getProp("Producer.Media.Host"); - String date = ent.getValue("date"); - String datePath = StringUtil.webdbDate2path(date); - String baseName = ent.getId(); - String mediaFname = baseName+"."+ext; - String mp3Pointer = mediaHost+datePath+mediaFname; - String mpegURLFile = baseName+".m3u"; - String playlistFile = baseName+".pls"; - Integer size = new Integer(uploadedData.length); - try { - FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData); - //FileUtil.write(dir+"/"+mediaFname, uploadedData); - //were done with the data, dereference. - uploadedData=null; - - //write the "meta" files - //first the .m3u since it only contains one line - FileUtil.write(dir+"/"+datePath+"/"+mpegURLFile,mp3Pointer.getBytes()); - //now the .pls file - FileUtil.write(dir+"/"+datePath+"/"+playlistFile,mp3Pointer.getBytes()); - ent.setValueForProperty("is_produced", "1"); - ent.setValueForProperty("icon_is_produced", "1"); - ent.setValueForProperty("publish_path",datePath+"/"+mediaFname); - //ent.setValueForProperty("publish_path", mediaFname); - ent.setValueForProperty("publish_server", mediaHost); - ent.setValueForProperty("size", size.toString()); - ent.update(); - } catch (Exception e) { - theLog.printError(e.toString()); - throw new MirMediaException(e.toString()); - } - - return true; - } - - public String getURL(Entity ent, Entity mediaTypeEnt) - { - String stringSize = ent.getValue("size"); - if (stringSize == null) - return null; - int size = Integer.parseInt(stringSize, 10)/1024; - String rawTitle = ent.getValue("title")+ - " - "+mediaTypeEnt.getValue("name")+" "+ - size+" KB "+"download"; - String m3uTitle = ent.getValue("title")+ - " - "+mediaTypeEnt.getValue("name")+" "+ - "streaming URL"; - String plsTitle = ent.getValue("title")+ - " - "+mediaTypeEnt.getValue("name")+" "+ - "playlist URL"; - - String basePath=StringUtil.regexpReplace(ent.getValue("publish_path"), ".mp3$",""); - - String m3uURL = StringUtil.createURLLinks(ent.getValue("publish_server")+"/"+basePath+".m3u", m3uTitle, imageRoot, getBigIcon()); - String plsURL = StringUtil.createURLLinks(ent.getValue("publish_server")+"/"+basePath+".pls", plsTitle, imageRoot, getBigIcon()); - String rawURL = StringUtil.createURLLinks(ent.getValue("publish_server")+"/"+ent.getValue("publish_path"), rawTitle, imageRoot, getBigIcon()); - - return m3uURL+"\n

"+plsURL+"\n

"+rawURL; - - } - -} - - - diff --git a/source/mir/media/MediaHandlerRealAudio.java b/source/mir/media/MediaHandlerRealAudio.java deleted file mode 100755 index e9f99a2d..00000000 --- a/source/mir/media/MediaHandlerRealAudio.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * put your module comment here - */ - - -package mir.media; - -import java.util.*; - -import mir.entity.*; -import mir.misc.*; -import mir.storage.*; - - - -/** - * Handles real audio. like MediaHandlerAudio, except it manages the ram file, too. - * - * @see mir.media.MediaHandlerGeneric - * @see mir.media.MirMedia - * @author john - * @version 11.10.2001 - */ - - -public class MediaHandlerRealAudio extends MediaHandlerAudio implements MirMedia -{ - - public boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt ) - throws MirMediaException { - String ext = mediaTypeEnt.getValue("name"); - String dir = MirConfig.getProp("Producer.Media.Path"); - String rtspDir = MirConfig.getProp("Producer.RealMedia.Path"); - String mediaHost = MirConfig.getProp("Producer.Media.Host"); - String rtspMediaHost = MirConfig.getProp("Producer.RealMedia.Host"); - - String date = ent.getValue("date"); - String datePath = StringUtil.webdbDate2path(date); - String mediaFname = ent.getId()+"."+ext; - String realMediaPointer = rtspMediaHost+datePath+mediaFname; - String realMediaFile = ent.getId()+".ram"; - Integer size = new Integer(uploadedData.length); - try { - FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData); - //FileUtil.write(rtspDir+"/"+mediaFname, uploadedData); - //were done with the data, dereference. - uploadedData=null; - - //write a ram file - FileUtil.write(dir+"/"+datePath+"/"+realMediaFile,realMediaPointer.getBytes()); - ent.setValueForProperty("is_produced", "1"); - ent.setValueForProperty("icon_is_produced", "1"); - ent.setValueForProperty("publish_path",datePath+"/"+realMediaFile); - //ent.setValueForProperty("publish_path", realMediaFile); - ent.setValueForProperty("publish_server", mediaHost); - ent.setValueForProperty("size", size.toString()); - ent.update(); - } catch (Exception e) { - theLog.printError(e.toString()); - throw new MirMediaException(e.toString()); - } - - return true; - } - -} - - - diff --git a/source/mir/media/MediaHandlerRealVideo.java b/source/mir/media/MediaHandlerRealVideo.java deleted file mode 100755 index f47e9963..00000000 --- a/source/mir/media/MediaHandlerRealVideo.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * put your module comment here - */ - - -package mir.media; - -import java.util.*; - -import mir.entity.*; -import mir.misc.*; -import mir.storage.*; - - - -/** - * Handles real video. like MediaHandlerAudio, except it manages the ram file, too. - * - * @see mir.media.MediaHandlerGeneric - * @see mir.media.MirMedia - * @author john - * @version 11.10.2001 - */ - - -public class MediaHandlerRealVideo extends MediaHandlerGeneric implements MirMedia -{ - - private String imageHost = MirConfig.getProp("Producer.Image.Host"); - private static String imageRoot = MirConfig.getProp("Producer.ImageRoot"); - private Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+"log/media.log"); - - public boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt ) - throws MirMediaException { - - String ext = mediaTypeEnt.getValue("name"); - String dir = MirConfig.getProp("Producer.Media.Path"); - String rtspDir = MirConfig.getProp("Producer.RealMedia.Path"); - String mediaHost = MirConfig.getProp("Producer.Media.Host"); - String rtspMediaHost = MirConfig.getProp("Producer.RealMedia.Host"); - - String mediaFname = ent.getId()+"."+ext; - String RealMediaPointer = rtspMediaHost+mediaFname; - String RealMediaFile = ent.getId()+".ram"; - String date = ent.getValue("date"); - String datePath = StringUtil.webdbDate2path(date); - Integer size = new Integer(uploadedData.length); - try { - FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData); - //FileUtil.write(rtspDir+"/"+mediaFname, uploadedData); - //were done with the data, dereference. - uploadedData=null; - - //write an rm file - FileUtil.write(dir+"/"+RealMediaFile,RealMediaPointer.getBytes()); - ent.setValueForProperty("is_produced", "1"); - ent.setValueForProperty("icon_is_produced", "1"); - ent.setValueForProperty("publish_path",datePath+"/"+mediaFname); - //ent.setValueForProperty("publish_path", RealMediaFile); - ent.setValueForProperty("publish_server", mediaHost); - ent.setValueForProperty("size", size.toString()); - ent.update(); - } catch (Exception e) { - theLog.printError(e.toString()); - throw new MirMediaException(e.toString()); - } - - return true; - } - - - - - - public String getPublishHost() - { - return MirConfig.getProp("Producer.Media.Host"); - } - - - - public String getURL(Entity ent, Entity mediaTypeEnt) - { - int size = Integer.parseInt(ent.getValue("size"), 10)/1024; - String title = ent.getValue("title")+ - " - "+mediaTypeEnt.getValue("name")+" "+ - size+" KB"; - return StringUtil.createURLLinks(ent.getValue("publish_server")+"/"+ - ent.getValue("publish_path"), title, imageRoot, getBigIcon()); - } - - - private static String tinyIcon = MirConfig.getProp("Producer.Icon.TinyVideo"); - private static String bigIcon = MirConfig.getProp("Producer.Icon.BigVideo"); - - public String getTinyIcon() - { - return tinyIcon; - } - - public String getBigIcon() - { - return bigIcon; - } - - public String getIconAlt() - { - return "Video"; - } - - public boolean isVideo() - { - return true; - } - -} - - - diff --git a/source/mir/media/MediaHandlerVideo.java b/source/mir/media/MediaHandlerVideo.java deleted file mode 100755 index d7a7e030..00000000 --- a/source/mir/media/MediaHandlerVideo.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * put your module comment here - */ - - -package mir.media; - -import java.util.*; - -import mir.entity.*; -import mir.misc.*; -import mir.storage.*; - - -/** - * Handles video media, like mpeg, av, and qt - * It is like MediaHandlerAudio with different icons. - * It is MediaHandlerGeneric with different icons. - * - * @see mir.media.MediaHandlerGeneric - * @see mir.media.MirMedia - * @author john - * @version 11.10.2001 - */ - -public class MediaHandlerVideo extends MediaHandlerGeneric implements MirMedia -{ - - private static String tinyIcon = MirConfig.getProp("Producer.Icon.TinyVideo"); - private static String bigIcon = MirConfig.getProp("Producer.Icon.BigVideo"); - - public String getTinyIcon() - { - return tinyIcon; - } - - public String getBigIcon() - { - return bigIcon; - } - - public String getIconAlt() - { - return "Video"; - } - - public boolean isVideo() - { - return true; - } -} diff --git a/source/mir/media/MediaHelper.java b/source/mir/media/MediaHelper.java index a9d31273..ba33cbf0 100755 --- a/source/mir/media/MediaHelper.java +++ b/source/mir/media/MediaHelper.java @@ -6,6 +6,7 @@ import java.lang.*; import mir.entity.Entity; import mir.storage.Database; + /** * helper class to resolve media handlers using reflection * @@ -15,7 +16,7 @@ import mir.storage.Database; public final class MediaHelper { - static String _classPrefix = "mir.media.MediaHandler"; + static String _classPrefix = "mircoders.media.MediaHandler"; public static MirMedia getHandler( Entity mediaType ) throws MirMediaException { diff --git a/source/mircoders/entity/EntityAudio.java b/source/mircoders/entity/EntityAudio.java index 8e0f37d5..a780e7ab 100755 --- a/source/mircoders/entity/EntityAudio.java +++ b/source/mircoders/entity/EntityAudio.java @@ -47,7 +47,7 @@ public class EntityAudio extends EntityUploadedMedia { theLog.printDebugInfo("--getaudio started"); java.sql.Connection con=null;Statement stmt=null; - byte[] img_data=null; + byte[] data=null; try { con = theStorageObject.getPooledCon(); @@ -63,9 +63,9 @@ public class EntityAudio extends EntityUploadedMedia if(rs!=null) { if (rs.next()) { LargeObject lob = lom.open(rs.getInt(1)); - img_data = lob.read(lob.size()); + data = lob.read(lob.size()); lob.close(); - //img_data = rs.getBytes(1); + //data = rs.getBytes(1); } rs.close(); } @@ -86,39 +86,54 @@ public class EntityAudio extends EntityUploadedMedia theStorageObject.freeConnection(con,stmt); } - return img_data; + return data; } - public void setAudio(byte[] audioData, String audioType) + public void setAudio(byte[] uploadData) throws StorageObjectException { - if (audioData!=null) { + if (uploadData!=null) { java.sql.Connection con=null;PreparedStatement pstmt=null; try { - theLog.printDebugInfo("settaudio :: making internal representation of audio"); - theLog.printDebugInfo("settaudio :: made internal representation of audio"); - theLog.printDebugInfo("settaudio :: getAudio"); - - if ( audioData!=null) { + if (uploadData!=null) { con = theStorageObject.getPooledCon(); con.setAutoCommit(false); - theLog.printDebugInfo("settaudio :: trying to insert audio"); + theLog.printDebugInfo("setaudio :: trying to insert audio"); // setting values - pstmt.setBytes(1, audioData); - String sql="update content set is_produced='0' where to_media="+getId(); + LargeObjectManager lom; + java.sql.Connection jCon; + jCon = ((com.codestudio.sql.PoolManConnectionHandle)con) + .getNativeConnection(); + lom = ((org.postgresql.Connection)jCon).getLargeObjectAPI(); + int oid = lom.create(); + LargeObject lob = lom.open(oid); + lob.write(uploadData); + lob.close(); + String sql = "update images set" + +" audio_data="+oid + +" where id="+getId(); + theLog.printDebugInfo("setaudio :: updating: "+ sql); + pstmt = con.prepareStatement(sql); + //pstmt.setBytes(1, imageData); + //pstmt.setBytes(2, iconData); + pstmt.executeUpdate(); + sql="update content set is_produced='0' where to_media="+getId(); pstmt = con.prepareStatement(sql); pstmt.executeUpdate(); } } - catch (Exception e) {throwStorageObjectException(e, "settaudio :: setAudio gescheitert: ");} + catch (Exception e) { + throwStorageObjectException(e,"setaudio ::failed: "); + } finally { try { if (con!=null) con.setAutoCommit(true); } catch (Exception e) {;} theStorageObject.freeConnection(con,pstmt); } } } + public void update() throws StorageObjectException { super.update(); try { diff --git a/source/mircoders/entity/EntityImages.java b/source/mircoders/entity/EntityImages.java index f873f51e..d495f0b7 100755 --- a/source/mircoders/entity/EntityImages.java +++ b/source/mircoders/entity/EntityImages.java @@ -91,21 +91,15 @@ public class EntityImages extends EntityUploadedMedia return img_data; } - public void setImage(byte[] uploadData, String imageType) + public void setImage(byte[] uploadData) throws StorageObjectException { - int type = 0; - - //hack -mh - if (imageType.equals("1")) - type = 1; - //end hack if (uploadData!=null) { java.sql.Connection con=null;PreparedStatement pstmt=null; try { theLog.printDebugInfo("settimage :: making internal representation of image"); - WebdbImage webdbImage= new WebdbImage(uploadData,type); + WebdbImage webdbImage= new WebdbImage(uploadData); theLog.printDebugInfo("settimage :: made internal representation of image"); byte[] imageData = webdbImage.getImage(); theLog.printDebugInfo("settimage :: getImage"); diff --git a/source/mircoders/media/MediaHandlerAudio.java b/source/mircoders/media/MediaHandlerAudio.java new file mode 100755 index 00000000..d32ff508 --- /dev/null +++ b/source/mircoders/media/MediaHandlerAudio.java @@ -0,0 +1,51 @@ +/* + * put your module comment here + */ + + +package mircoders.media; + +import java.util.*; + +import mir.media.*; +import mir.entity.*; +import mir.misc.*; +import mir.storage.*; + + +/** + * Handles audio media, like mp3 and maybe it could also handle some other. + * It is MediaHandlerGeneric with different icons. + * + * @see mir.media.MediaHandlerGeneric + * @see mir.media.MirMedia + * @author mh + * @version 24.09.2001 + */ + +public class MediaHandlerAudio extends MediaHandlerGeneric implements MirMedia +{ + + private static String tinyIcon = MirConfig.getProp("Producer.Icon.TinyAudio"); + private static String bigIcon = MirConfig.getProp("Producer.Icon.BigAudio"); + + public String getTinyIcon() + { + return tinyIcon; + } + + public String getBigIcon() + { + return bigIcon; + } + + public String getIconAlt() + { + return "Audio"; + } + + public boolean isAudio() + { + return true; + } +} diff --git a/source/mircoders/media/MediaHandlerGeneric.java b/source/mircoders/media/MediaHandlerGeneric.java new file mode 100755 index 00000000..98bb183a --- /dev/null +++ b/source/mircoders/media/MediaHandlerGeneric.java @@ -0,0 +1,170 @@ +/* + * put your module comment here + */ + + +package mircoders.media; + +import java.util.*; + +import mir.media.*; +import mir.entity.*; +import mir.misc.*; +import mir.storage.*; + + +/** + * This is the Generic MediaHandler. It stores the media data on + * the filesystem and keeps basic metadata (size, type...) in the + * DB. Usually only representation needs to be overridden. + * See the MediaHandlerAudio class to see an example of how one + * could override it. + *

+ * Most media handlers should override this class. + *

+ * In theory, it could be used to handle miscellaneous media that + * we don't have entered in the media_type table, (like RTF documents, + * PS, PDF, etc..) + *

+ * Of course it implements the MirMedia interface. + * + * @see mir.media.MirMedia + * @author mh + * @version 24.09.2001 + */ + +public class MediaHandlerGeneric implements MirMedia +{ + + protected String imageHost = MirConfig.getProp("Producer.Image.Host"); + protected String imageRoot = MirConfig.getProp("Producer.ImageRoot"); + protected Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+"log/media.log"); + public boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt ) + throws MirMediaException { + + String ext = mediaTypeEnt.getValue("name"); + String dir = MirConfig.getProp("Producer.Media.Path"); + String mediaHost = MirConfig.getProp("Producer.Media.Host"); + String mediaFname = ent.getId()+"."+ext; + String date = ent.getValue("date"); + String datePath = StringUtil.webdbDate2path(date); + Integer size = new Integer(uploadedData.length); + try { + FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData); + //if(FileUtil.write(dir+"/"+mediaFname, uploadedData)) { + //were done with the data, dereference. + uploadedData=null; + + ent.setValueForProperty("is_produced", "1"); + ent.setValueForProperty("icon_is_produced", "1"); + ent.setValueForProperty("publish_path",datePath+"/"+mediaFname); + //ent.setValueForProperty("publish_path", mediaFname); + ent.setValueForProperty("publish_server", mediaHost); + ent.setValueForProperty("size", size.toString()); + ent.update(); + } catch (Exception e) { + theLog.printError(e.toString()); + throw new MirMediaException(e.toString()); + } + + return true; + } + + //a method that will probably never get used.. + private byte[] getFile (String fileName) + throws MirMediaException { + + long size = FileUtil.getSize(fileName); + if (size < 0) return null; + + byte[] container = new byte[(int)size]; + + try { + FileUtil.read(fileName, container); + } catch (Exception e) { + theLog.printError(e.toString()); + throw new MirMediaException(e.toString()); + } + + return container; + } + + public byte[] get (Entity ent, Entity mediaTypeEnt) { + return null; + } + + public byte[] getIcon (Entity ent) { + return null; + } + + public String getStoragePath() + { + return MirConfig.getProp("Producer.Media.Path"); + } + + public String getIconStoragePath() + { + return MirConfig.getProp("Producer.Image.IconPath"); + } + + public String getPublishHost() + { + return MirConfig.getProp("Producer.Media.Host"); + } + + public String getTinyIcon() + { + return MirConfig.getProp("Producer.Icon.TinyText"); + } + + public String getBigIcon() + { + return MirConfig.getProp("Producer.Icon.BigText"); + } + + public String getIconAlt() + { + return "Generic media"; + } + + public String getURL(Entity ent, Entity mediaTypeEnt) + { + String stringSize = ent.getValue("size"); + if (stringSize == null) + return null; + int size = Integer.parseInt(stringSize, 10)/1024; + String title = ent.getValue("title")+ + " - "+mediaTypeEnt.getValue("name")+" "+ + size+" KB"; + return StringUtil.createURLLinks(ent.getValue("publish_server")+"/"+ + ent.getValue("publish_path"), title, imageRoot, getBigIcon()); + } + + public String getListView(Entity ent, Entity mediaTypeEnt) + { + //String title = ent.getValue("title")+ + // " - "+mediaTypeEnt.getValue("name")+" "+ + // ent.getValue("size")+" Bytes"; + return StringUtil.createIMGLinks(imageHost+ + getBigIcon(), null, null, null); + } + + public boolean isVideo() + { + return false; + } + + public boolean isAudio() + { + return false; + } + + public boolean isImage() + { + return false; + } + +} + + + diff --git a/source/mircoders/media/MediaHandlerImages.java b/source/mircoders/media/MediaHandlerImages.java new file mode 100755 index 00000000..c24add82 --- /dev/null +++ b/source/mircoders/media/MediaHandlerImages.java @@ -0,0 +1,144 @@ + +package mircoders.media; + +import java.lang.*; +import java.io.*; +import java.util.*; +import java.lang.reflect.*; + +import mir.media.*; +import mir.misc.*; +import mir.entity.*; +import mir.storage.StorageObjectException; +import mircoders.entity.EntityImages; + +/** + * This class handles saving, fetching creating representations + * for all images. The image content is stored in the DB. The content is + * written out to a file at the ProducerImages level. + * Remember that Handlers for specific image types, Gif, Jpeg, etc.. + * should override it. + * It implements the MirMedia interface. + *

+ * slowly starting to look better, a next step would be to have the + * representation stuff (WebdbImage) happen here. + * -mh 01.03.2002 + * + * @see mir.media.MirMedia + * @author mh + * @version 24.09.2001 + */ + + +public class MediaHandlerImages implements MirMedia +{ + private Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+ + "log/media.log"); + + public byte[] get(Entity ent, Entity mediaTypeEnt) + throws MirMediaException + { + byte[] image_data = null; + + try { + image_data = ((EntityImages)ent).getImage(); + } catch ( StorageObjectException e) { + theLog.printDebugInfo("MediaHandlerImages.get: "+e.toString()); + throw new MirMediaException(e.toString()); + } + + + return image_data; + } + + public boolean set(byte[] uploadData, Entity ent, Entity mediaTypeEnt) + throws MirMediaException { + + try { + ((EntityImages)ent).setImage(uploadData); + } catch ( StorageObjectException e) { + theLog.printDebugInfo("MediaHandlerImages.set: "+e.toString()); + throw new MirMediaException(e.toString()); + } + //deref. -mh + uploadData=null; + + return true; + } + + public byte[] getIcon(Entity ent) throws MirMediaException + { + byte[] icon_data = null; + + try { + icon_data = ((EntityImages)ent).getIcon(); + } catch ( StorageObjectException e) { + theLog.printDebugInfo("MediaHandlerImages.getIcon: "+e.toString()); + throw new MirMediaException(e.toString()); + } + + return icon_data; + } + + public String getURL(Entity ent, Entity mediaTypeEnt) + { + String title = ent.getValue("title"); + return StringUtil.createIMGLinks(ent.getValue("publish_server")+ + ent.getValue("publish_path"), title, ent.getValue("img_height"), + ent.getValue("img_width")); + } + + public String getListView(Entity ent, Entity mediaTypeEnt) + { + //String title = ent.getValue("title"); + return StringUtil.createIMGLinks( MirConfig.getProp("Producer.ProductionHost")+ + ent.getValue("icon_path"), null, ent.getValue("icon_height"), + ent.getValue("icon_width")); + } + + public String getStoragePath() + { + return MirConfig.getProp("Producer.Image.Path"); + } + + public String getIconStoragePath() + { + return MirConfig.getProp("Producer.Image.IconPath"); + } + + public String getPublishHost() + { + return MirConfig.getProp("Producer.Image.Host"); + } + + public String getTinyIcon () + { + return MirConfig.getProp("Producer.Icon.TinyImage"); + } + + public String getBigIcon () + { + return MirConfig.getProp("Producer.Icon.BigImage"); + } + + public String getIconAlt () + { + return "Image"; + } + + public boolean isVideo () + { + return false; + } + + public boolean isAudio () + { + return false; + } + + public boolean isImage () + { + return true; + } + +} diff --git a/source/mircoders/media/MediaHandlerMp3.java b/source/mircoders/media/MediaHandlerMp3.java new file mode 100755 index 00000000..2ac0aa03 --- /dev/null +++ b/source/mircoders/media/MediaHandlerMp3.java @@ -0,0 +1,115 @@ +/* + * put your module comment here + */ + + +package mircoders.media; + +import java.util.*; + +import mir.media.*; +import mir.entity.*; +import mir.misc.*; +import mir.storage.*; + + +/** + * Please note: this media handler produces + * 3 media files, the raw .mp3, a .m3u which is + * contains the URL for the mp3 and a .pls which + * contains the URL to the mp3 in shoutcast playlist + * format. What's important is that the web server (of + * the media host) must recognize the .m3u and .pls file + * extensions and send the proper "audio/x-mpegurl" + * and "audio/x-scpls" mime-types respectively. + * If the web server is apache, it's easy, just + * add: + * + * audio/x-mpegurl m3u + * audio/x-scpl pls + * + * to the file pointed to by the "TypesConfig" + * command in your apache config file. Or add + * and equivalent AddType command to your httpd.conf. + * Of course this assumes that the mod_mime is loaded. + * + * If the web server is not apache, then your on your own. + * + * @see mir.media.MirMedia + * @author mh + * @version 01.12.2001 + */ + +public class MediaHandlerMp3 extends MediaHandlerAudio implements MirMedia +{ + + public boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt ) + throws MirMediaException { + + String ext = mediaTypeEnt.getValue("name"); + String dir = MirConfig.getProp("Producer.Media.Path"); + String mediaHost = MirConfig.getProp("Producer.Media.Host"); + String date = ent.getValue("date"); + String datePath = StringUtil.webdbDate2path(date); + String baseName = ent.getId(); + String mediaFname = baseName+"."+ext; + String mp3Pointer = mediaHost+datePath+mediaFname; + String mpegURLFile = baseName+".m3u"; + String playlistFile = baseName+".pls"; + Integer size = new Integer(uploadedData.length); + try { + FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData); + //FileUtil.write(dir+"/"+mediaFname, uploadedData); + //were done with the data, dereference. + uploadedData=null; + + //write the "meta" files + //first the .m3u since it only contains one line + FileUtil.write(dir+"/"+datePath+"/"+mpegURLFile,mp3Pointer.getBytes()); + //now the .pls file + FileUtil.write(dir+"/"+datePath+"/"+playlistFile,mp3Pointer.getBytes()); + ent.setValueForProperty("is_produced", "1"); + ent.setValueForProperty("icon_is_produced", "1"); + ent.setValueForProperty("publish_path",datePath+"/"+mediaFname); + //ent.setValueForProperty("publish_path", mediaFname); + ent.setValueForProperty("publish_server", mediaHost); + ent.setValueForProperty("size", size.toString()); + ent.update(); + } catch (Exception e) { + theLog.printError(e.toString()); + throw new MirMediaException(e.toString()); + } + + return true; + } + + public String getURL(Entity ent, Entity mediaTypeEnt) + { + String stringSize = ent.getValue("size"); + if (stringSize == null) + return null; + int size = Integer.parseInt(stringSize, 10)/1024; + String rawTitle = ent.getValue("title")+ + " - "+mediaTypeEnt.getValue("name")+" "+ + size+" KB "+"download"; + String m3uTitle = ent.getValue("title")+ + " - "+mediaTypeEnt.getValue("name")+" "+ + "streaming URL"; + String plsTitle = ent.getValue("title")+ + " - "+mediaTypeEnt.getValue("name")+" "+ + "playlist URL"; + + String basePath=StringUtil.regexpReplace(ent.getValue("publish_path"), ".mp3$",""); + + String m3uURL = StringUtil.createURLLinks(ent.getValue("publish_server")+"/"+basePath+".m3u", m3uTitle, imageRoot, getBigIcon()); + String plsURL = StringUtil.createURLLinks(ent.getValue("publish_server")+"/"+basePath+".pls", plsTitle, imageRoot, getBigIcon()); + String rawURL = StringUtil.createURLLinks(ent.getValue("publish_server")+"/"+ent.getValue("publish_path"), rawTitle, imageRoot, getBigIcon()); + + return m3uURL+"\n

"+plsURL+"\n

"+rawURL; + + } + +} + + + diff --git a/source/mircoders/media/MediaHandlerRealAudio.java b/source/mircoders/media/MediaHandlerRealAudio.java new file mode 100755 index 00000000..d8875ccd --- /dev/null +++ b/source/mircoders/media/MediaHandlerRealAudio.java @@ -0,0 +1,70 @@ +/* + * put your module comment here + */ + + +package mircoders.media; + +import java.util.*; + +import mir.media.*; +import mir.entity.*; +import mir.misc.*; +import mir.storage.*; + + + +/** + * Handles real audio. like MediaHandlerAudio, except it manages the ram file, too. + * + * @see mir.media.MediaHandlerGeneric + * @see mir.media.MirMedia + * @author john + * @version 11.10.2001 + */ + + +public class MediaHandlerRealAudio extends MediaHandlerAudio implements MirMedia +{ + + public boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt ) + throws MirMediaException { + String ext = mediaTypeEnt.getValue("name"); + String dir = MirConfig.getProp("Producer.Media.Path"); + String rtspDir = MirConfig.getProp("Producer.RealMedia.Path"); + String mediaHost = MirConfig.getProp("Producer.Media.Host"); + String rtspMediaHost = MirConfig.getProp("Producer.RealMedia.Host"); + + String date = ent.getValue("date"); + String datePath = StringUtil.webdbDate2path(date); + String mediaFname = ent.getId()+"."+ext; + String realMediaPointer = rtspMediaHost+datePath+mediaFname; + String realMediaFile = ent.getId()+".ram"; + Integer size = new Integer(uploadedData.length); + try { + FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData); + //FileUtil.write(rtspDir+"/"+mediaFname, uploadedData); + //were done with the data, dereference. + uploadedData=null; + + //write a ram file + FileUtil.write(dir+"/"+datePath+"/"+realMediaFile,realMediaPointer.getBytes()); + ent.setValueForProperty("is_produced", "1"); + ent.setValueForProperty("icon_is_produced", "1"); + ent.setValueForProperty("publish_path",datePath+"/"+realMediaFile); + //ent.setValueForProperty("publish_path", realMediaFile); + ent.setValueForProperty("publish_server", mediaHost); + ent.setValueForProperty("size", size.toString()); + ent.update(); + } catch (Exception e) { + theLog.printError(e.toString()); + throw new MirMediaException(e.toString()); + } + + return true; + } + +} + + + diff --git a/source/mircoders/media/MediaHandlerRealVideo.java b/source/mircoders/media/MediaHandlerRealVideo.java new file mode 100755 index 00000000..e960ec36 --- /dev/null +++ b/source/mircoders/media/MediaHandlerRealVideo.java @@ -0,0 +1,120 @@ +/* + * put your module comment here + */ + + +package mircoders.media; + +import java.util.*; + +import mir.media.*; +import mir.entity.*; +import mir.misc.*; +import mir.storage.*; + + + +/** + * Handles real video. like MediaHandlerAudio, except it manages the ram file, too. + * + * @see mir.media.MediaHandlerGeneric + * @see mir.media.MirMedia + * @author john + * @version 11.10.2001 + */ + + +public class MediaHandlerRealVideo extends MediaHandlerGeneric implements MirMedia +{ + + private String imageHost = MirConfig.getProp("Producer.Image.Host"); + private static String imageRoot = MirConfig.getProp("Producer.ImageRoot"); + private Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+"log/media.log"); + + public boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt ) + throws MirMediaException { + + String ext = mediaTypeEnt.getValue("name"); + String dir = MirConfig.getProp("Producer.Media.Path"); + String rtspDir = MirConfig.getProp("Producer.RealMedia.Path"); + String mediaHost = MirConfig.getProp("Producer.Media.Host"); + String rtspMediaHost = MirConfig.getProp("Producer.RealMedia.Host"); + + String mediaFname = ent.getId()+"."+ext; + String RealMediaPointer = rtspMediaHost+mediaFname; + String RealMediaFile = ent.getId()+".ram"; + String date = ent.getValue("date"); + String datePath = StringUtil.webdbDate2path(date); + Integer size = new Integer(uploadedData.length); + try { + FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData); + //FileUtil.write(rtspDir+"/"+mediaFname, uploadedData); + //were done with the data, dereference. + uploadedData=null; + + //write an rm file + FileUtil.write(dir+"/"+RealMediaFile,RealMediaPointer.getBytes()); + ent.setValueForProperty("is_produced", "1"); + ent.setValueForProperty("icon_is_produced", "1"); + ent.setValueForProperty("publish_path",datePath+"/"+mediaFname); + //ent.setValueForProperty("publish_path", RealMediaFile); + ent.setValueForProperty("publish_server", mediaHost); + ent.setValueForProperty("size", size.toString()); + ent.update(); + } catch (Exception e) { + theLog.printError(e.toString()); + throw new MirMediaException(e.toString()); + } + + return true; + } + + + + + + public String getPublishHost() + { + return MirConfig.getProp("Producer.Media.Host"); + } + + + + public String getURL(Entity ent, Entity mediaTypeEnt) + { + int size = Integer.parseInt(ent.getValue("size"), 10)/1024; + String title = ent.getValue("title")+ + " - "+mediaTypeEnt.getValue("name")+" "+ + size+" KB"; + return StringUtil.createURLLinks(ent.getValue("publish_server")+"/"+ + ent.getValue("publish_path"), title, imageRoot, getBigIcon()); + } + + + private static String tinyIcon = MirConfig.getProp("Producer.Icon.TinyVideo"); + private static String bigIcon = MirConfig.getProp("Producer.Icon.BigVideo"); + + public String getTinyIcon() + { + return tinyIcon; + } + + public String getBigIcon() + { + return bigIcon; + } + + public String getIconAlt() + { + return "Video"; + } + + public boolean isVideo() + { + return true; + } + +} + + + diff --git a/source/mircoders/media/MediaHandlerVideo.java b/source/mircoders/media/MediaHandlerVideo.java new file mode 100755 index 00000000..3e9ed4a3 --- /dev/null +++ b/source/mircoders/media/MediaHandlerVideo.java @@ -0,0 +1,52 @@ +/* + * put your module comment here + */ + + +package mircoders.media; + +import java.util.*; + +import mir.media.*; +import mir.entity.*; +import mir.misc.*; +import mir.storage.*; + + +/** + * Handles video media, like mpeg, av, and qt + * It is like MediaHandlerAudio with different icons. + * It is MediaHandlerGeneric with different icons. + * + * @see mir.media.MediaHandlerGeneric + * @see mir.media.MirMedia + * @author john + * @version 11.10.2001 + */ + +public class MediaHandlerVideo extends MediaHandlerGeneric implements MirMedia +{ + + private static String tinyIcon = MirConfig.getProp("Producer.Icon.TinyVideo"); + private static String bigIcon = MirConfig.getProp("Producer.Icon.BigVideo"); + + public String getTinyIcon() + { + return tinyIcon; + } + + public String getBigIcon() + { + return bigIcon; + } + + public String getIconAlt() + { + return "Video"; + } + + public boolean isVideo() + { + return true; + } +}