+++ /dev/null
-/*
- * 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 <heckmann@hbe.ca>
- * @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;
- }
-}
+++ /dev/null
-/*
- * 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.
- * <p>
- * Most media handlers should override this class.
- * <p>
- * 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..)
- * <p>
- * Of course it implements the MirMedia interface.
- *
- * @see mir.media.MirMedia
- * @author mh <heckmann@hbe.ca>
- * @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;
- }
-
-}
-
-
-
+++ /dev/null
-
-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.
- * <p>
- * 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;
- }
-
-}
+++ /dev/null
-/*
- * 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 <heckmann@hbe.ca>
- * @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<p>"+plsURL+"\n<p>"+rawURL;
-
- }
-
-}
-
-
-
+++ /dev/null
-/*
- * 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 <john@manifestor.org>
- * @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;
- }
-
-}
-
-
-
+++ /dev/null
-/*
- * 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 <john@manifestor.org>
- * @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;
- }
-
-}
-
-
-
+++ /dev/null
-/*
- * 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 <john@manifestor.org>
- * @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;
- }
-}
import mir.entity.Entity;
import mir.storage.Database;
+
/**
* helper class to resolve media handlers using reflection
*
public final class MediaHelper {
- static String _classPrefix = "mir.media.MediaHandler";
+ static String _classPrefix = "mircoders.media.MediaHandler";
public static MirMedia getHandler( Entity mediaType )
throws MirMediaException {
{
theLog.printDebugInfo("--getaudio started");
java.sql.Connection con=null;Statement stmt=null;
- byte[] img_data=null;
+ byte[] data=null;
try {
con = theStorageObject.getPooledCon();
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();
}
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 {
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");
--- /dev/null
+/*
+ * 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 <heckmann@hbe.ca>
+ * @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;
+ }
+}
--- /dev/null
+/*
+ * 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.
+ * <p>
+ * Most media handlers should override this class.
+ * <p>
+ * 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..)
+ * <p>
+ * Of course it implements the MirMedia interface.
+ *
+ * @see mir.media.MirMedia
+ * @author mh <heckmann@hbe.ca>
+ * @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;
+ }
+
+}
+
+
+
--- /dev/null
+
+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.
+ * <p>
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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 <heckmann@hbe.ca>
+ * @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<p>"+plsURL+"\n<p>"+rawURL;
+
+ }
+
+}
+
+
+
--- /dev/null
+/*
+ * 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 <john@manifestor.org>
+ * @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;
+ }
+
+}
+
+
+
--- /dev/null
+/*
+ * 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 <john@manifestor.org>
+ * @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;
+ }
+
+}
+
+
+
--- /dev/null
+/*
+ * 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 <john@manifestor.org>
+ * @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;
+ }
+}