rework of media handling vis a vis storage and producing. making it more
authormh <mh>
Sat, 23 Mar 2002 22:14:57 +0000 (22:14 +0000)
committermh <mh>
Sat, 23 Mar 2002 22:14:57 +0000 (22:14 +0000)
consitent.

16 files changed:
dbscripts/create_pg.sql
source/mir/media/MirMedia.java
source/mircoders/media/MediaHandlerGeneric.java
source/mircoders/media/MediaHandlerImages.java
source/mircoders/media/MediaHandlerMp3.java
source/mircoders/media/MediaHandlerRealAudio.java
source/mircoders/media/MediaHandlerRealVideo.java
source/mircoders/producer/Producer.java
source/mircoders/producer/ProducerAll.java
source/mircoders/producer/ProducerAudio.java [new file with mode: 0755]
source/mircoders/producer/ProducerImages.java
source/mircoders/producer/ProducerMedia.java
source/mircoders/producer/ProducerOther.java [new file with mode: 0755]
source/mircoders/producer/ProducerVideo.java [new file with mode: 0755]
source/mircoders/servlet/ServletModuleImages.java
source/mircoders/servlet/ServletModuleOpenIndy.java

index 997dfcd..703176f 100755 (executable)
@@ -439,7 +439,6 @@ CREATE TABLE "links_imcs" (
 --
 
 CREATE TABLE "audio" (
-       "audio_data" oid,
        "kbits" smallint
 )
 INHERITS ("uploaded_media");
@@ -451,7 +450,6 @@ INHERITS ("uploaded_media");
 --
 
 CREATE TABLE "video" (
-       "video_data" oid
 )
 INHERITS ("uploaded_media");
 
index 3597a1f..0431e9b 100755 (executable)
@@ -72,7 +72,11 @@ public interface  MirMedia{
    * @return boolean, success/fail
    * @see mir.entity.Entity
    */
-       public abstract boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt ) throws MirMediaException;
+  public abstract boolean set (byte[] uploadedData, Entity ent,
+                                Entity mediaTypeEnt ) throws MirMediaException;
+
+       public abstract void produce (Entity ent, Entity mediaTypeEnt ) 
+    throws MirMediaException;
 
   /**
    * Get's the media data from storage and returns it as a byte array
@@ -84,8 +88,8 @@ public interface  MirMedia{
    * @return byte[]
    * @see mir.entity.Entity
    */
-       public abstract byte[] get (Entity ent, Entity mediaTypeEnt)
-        throws MirMediaException;
+  public abstract byte[] get (Entity ent, Entity mediaTypeEnt)
+          throws MirMediaException;
 
   /**
    * Pretty much like get() above. But get's the specific Icon
@@ -94,7 +98,7 @@ public interface  MirMedia{
    * @return byte[]
    * @see mir.entity.Entity
    */
-       public abstract byte[] getIcon (Entity ent) throws MirMediaException;
+  public abstract byte[] getIcon (Entity ent) throws MirMediaException;
 
        /**
    * gets the final content representation for the media
@@ -148,7 +152,7 @@ public interface  MirMedia{
    * @return String, the path.
    * @see mir.misc.MirConfig
    */
-       public abstract String getIconStoragePath () throws MirMediaException;
+  public abstract String getIconStoragePath () throws MirMediaException;
 
        /**
    * Returns the base URL to that the media is accessible from
@@ -161,7 +165,7 @@ public interface  MirMedia{
    * @return String, the base URL to the host.
    * @see mir.misc.MirConfig
    */
-       public abstract String getPublishHost () throws MirMediaException;
+  public abstract String getPublishHost () throws MirMediaException;
 
        /**
    * Returns the file name of the Icon representing the media type.
@@ -172,7 +176,7 @@ public interface  MirMedia{
    * @return String, the icon filename.
    * @see mir.misc.MirConfig
    */
-       public abstract String getBigIcon ();
+  public abstract String getBigIcon ();
   
        /**
    * Returns the file name of the small Icon representing 
@@ -184,14 +188,14 @@ public interface  MirMedia{
    * @return String, the icon filename.
    * @see mir.misc.MirConfig
    */
-       public abstract String getTinyIcon ();
+  public abstract String getTinyIcon ();
 
        /**
    * Returns the IMG SRC "ALT" text to be used
    * for the Icon representations
    * @return String, the ALT text.
    */
-       public abstract String getIconAlt ();
+  public abstract String getIconAlt ();
 
        /**
    * your all smart enough to figure it out.
@@ -203,13 +207,13 @@ public interface  MirMedia{
    * your all smart enough to figure it out.
    * @return boolean.
    */
-       public abstract boolean isAudio ();
+  public abstract boolean isAudio ();
 
        /**
    * your all smart enough to figure it out.
    * @return boolean.
    */
-       public abstract boolean isImage ();
+  public abstract boolean isImage ();
 
 }
 
index 98bb183..31eaff9 100755 (executable)
@@ -6,6 +6,7 @@
 package  mircoders.media;
 
 import java.util.*;
+import java.io.*;
 
 import mir.media.*;
 import mir.entity.*;
@@ -35,31 +36,25 @@ import mir.storage.*;
 
 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");
+    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)) {
+            FileUtil.write(getStoragePath()+"/"+datePath+"/"+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) {
@@ -70,6 +65,21 @@ public class MediaHandlerGeneric implements MirMedia
         return true;
     }
 
+    public void produce (Entity ent, Entity mediaTypeEnt )
+      throws MirMediaException {
+      
+      //check first if the media file exist since produced
+      //location is also the storage location
+      String date = ent.getValue("date");
+      String datePath = StringUtil.webdbDate2path(date);
+      String relPath = datePath+ent.getId()+"."+mediaTypeEnt.getValue("name");
+      String fname = getStoragePath()+relPath;
+      if(! new File(fname).exists())
+        throw new MirMediaException("error in MirMedia.produce(): "+relPath+
+                                    "does not exist!");
+    }
+      
+
     //a method that will probably never get used..
     private byte[] getFile (String fileName)
         throws MirMediaException {
index c24add8..d5db1a1 100755 (executable)
@@ -32,113 +32,149 @@ import mircoders.entity.EntityImages;
 
 public class MediaHandlerImages implements MirMedia
 {
-    private Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+
+  private Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+
                                                 "log/media.log");
 
        public byte[] get(Entity ent, Entity mediaTypeEnt)
-        throws MirMediaException
+    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());
-        }
+    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;
-       }
+    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());
-        }
+    throws MirMediaException {
 
-        return icon_data;
+    try {
+      ((EntityImages)ent).setImage(uploadData);
+    } catch ( StorageObjectException e) {
+      theLog.printError("MediaHandlerImages.set: "+e.toString()); 
+      throw new MirMediaException(e.toString());
     }
+    //deref. -mh
+    uploadData=null;
 
-    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"));
-    }
+    return true;
+       }
 
-    public String getStoragePath()
-    {
-        return MirConfig.getProp("Producer.Image.Path");
+  public void produce(Entity ent, Entity mediaTypeEnt) throws MirMediaException
+  {
+    String date = ent.getValue("date");
+    String datePath = StringUtil.webdbDate2path(date);
+    String ext = "."+mediaTypeEnt.getValue("name");
+    String filepath = datePath+ent.getId()+ext;
+    String iconFilePath = MirConfig.getProp("Producer.StorageRoot")
+                          +getIconStoragePath() + filepath;
+    String productionFilePath = getStoragePath() + "/" + filepath;
+
+
+    if (ent.getValue("icon_data")!= null &&
+        ent.getValue("image_data")!= null) {
+      // make icon
+      try {
+        FileUtil.write(iconFilePath,((EntityImages)ent).getIcon());
+        FileUtil.write(productionFilePath,((EntityImages)ent).getImage());
+        ent.setValueForProperty("icon_path",getIconStoragePath()+filepath);
+        ent.setValueForProperty("publish_path",filepath);
+        //ent.setValueForProperty("publish_server", getPublishHost());
+        //ent.setValueForProperty("icon_is_produced","1");
+        //ent.setValueForProperty("is_produced","1");
+        ent.update();
+      } catch ( Exception e) {
+        String msg = "MediaHandlerImages.produce - Error: " + e.toString();
+        theLog.printError(msg);
+        throw new MirMediaException(msg);
+      }
+    } else {
+      String msg="MediaHandlerImages.produce - missing image or icon OID for: "+
+                  ent.getId();
+      theLog.printError(msg);
+      throw new MirMediaException(msg);
     }
+  }
+                        
 
-    public String getIconStoragePath()
-    {
-        return MirConfig.getProp("Producer.Image.IconPath");
-    }
+       public byte[] getIcon(Entity ent) throws MirMediaException
+       {
+    byte[] icon_data = null;
 
-    public String getPublishHost()
-    {
-        return MirConfig.getProp("Producer.Image.Host");
+    try {
+      icon_data = ((EntityImages)ent).getIcon();
+    } catch ( StorageObjectException e) {
+      theLog.printDebugInfo("MediaHandlerImages.getIcon: "+e.toString()); 
+      throw new MirMediaException(e.toString());
     }
 
-    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;
-    } 
+    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;
+  } 
 
 }
index 2ac0aa0..270bc64 100755 (executable)
@@ -43,48 +43,35 @@ import mir.storage.*;
 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 void produce (Entity ent, Entity mediaTypeEnt )
+      throws MirMediaException {
+      
+      // first check if the file exists
+      super.produce(ent, mediaTypeEnt);
+
+      String baseName = ent.getId();
+      String date = ent.getValue("date");
+      String datePath = StringUtil.webdbDate2path(date);
+      String mp3Pointer = getPublishHost()+ent.getValue("publish_path");
+      String mpegURLFile = baseName+".m3u"; 
+      String playlistFile = baseName+".pls"; 
+
+      try {
+        //write the "meta" files
+        //first the .m3u since it only contains one line
+        FileUtil.write(getStoragePath()+"/"+datePath+"/"+mpegURLFile,
+                      mp3Pointer.getBytes());
+        //now the .pls file
+        FileUtil.write(getStoragePath()+"/"+datePath+"/"+playlistFile,
+                      mp3Pointer.getBytes());
+      } catch (Exception e) {
+          theLog.printError(e.toString()); 
+          throw new MirMediaException(e.toString());
+      }
     }
 
-    public String getURL(Entity ent, Entity mediaTypeEnt)
-    {
+  public String getURL(Entity ent, Entity mediaTypeEnt)
+  {
       String stringSize = ent.getValue("size");
       if (stringSize == null)
         return null;
index d8875cc..3536981 100755 (executable)
@@ -15,53 +15,55 @@ import mir.storage.*;
 
 
 /**
- * Handles real audio.  like MediaHandlerAudio, except it manages the ram file, too.  
+ * Handles realAudio .it manages the ram file.
+ *
+ * 03.2002 - reworked Realmedia handling. -mh
  *
  * @see mir.media.MediaHandlerGeneric
  * @see mir.media.MirMedia
- * @author john <john@manifestor.org>
+ * @author john <john@manifestor.org>, mh <heckmann@hbe.ca>
  * @version 11.10.2001
  */
 
 
-public class MediaHandlerRealAudio extends MediaHandlerAudio implements MirMedia
+public class MediaHandlerRealAudio extends MediaHandlerAudio implements
+  MirMedia
 {
+    public void produce (Entity ent, Entity mediaTypeEnt )
+      throws MirMediaException {
+
+      // first see if the file exists
+      super.produce(ent, mediaTypeEnt);
+
+      String baseName = ent.getId();
+      String date = ent.getValue("date");
+      String datePath = StringUtil.webdbDate2path(date);
+      String rtspDir = MirConfig.getProp("Producer.RealMedia.Path");
+      String rtspMediaHost = MirConfig.getProp("Producer.RealMedia.Host");
+
+      String RealMediaPointer = rtspMediaHost+ent.getValue("publish_path");
+      String RealMediaFile = datePath+ent.getId()+".ram";
+      try {
+        //write an rm (ram?. -mh) file
+        FileUtil.write(super.getStoragePath()+"/"+RealMediaFile,
+                        RealMediaPointer.getBytes());
+      } catch (Exception e) {
+        theLog.printError(e.toString());
+        throw new MirMediaException(e.toString());
+      }
+    }
+
+    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());
+    }
 
-    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;
+    public String getStoragePath() {
+      return MirConfig.getProp("Producer.RealMedia.Path");
     }
 
 }
index e960ec3..a6e4e8d 100755 (executable)
@@ -15,103 +15,55 @@ import mir.storage.*;
 
 
 /**
- * Handles real video.  like MediaHandlerAudio, except it manages the ram file, too.  
+ * Handles realVideo .it manages the ram file.
+ *
+ * 03.2002 - reworked Realmedia handling. -mh
  *
  * @see mir.media.MediaHandlerGeneric
  * @see mir.media.MirMedia
- * @author john <john@manifestor.org>
+ * @author john <john@manifestor.org>, mh <heckmann@hbe.ca>
  * @version 11.10.2001
  */
 
 
-public class MediaHandlerRealVideo extends MediaHandlerGeneric implements MirMedia
+public class MediaHandlerRealVideo extends MediaHandlerVideo 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 void produce (Entity ent, Entity mediaTypeEnt )
+      throws MirMediaException {
+
+      // first see if the file exists
+      super.produce(ent, mediaTypeEnt);
+
+      String baseName = ent.getId();
+      String date = ent.getValue("date");
+      String datePath = StringUtil.webdbDate2path(date);
+      String rtspDir = MirConfig.getProp("Producer.RealMedia.Path");
+      String rtspMediaHost = MirConfig.getProp("Producer.RealMedia.Host");
+
+      String RealMediaPointer = rtspMediaHost+ent.getValue("publish_path");
+      String RealMediaFile = datePath+ent.getId()+".ram";
+      try {
+        //write an rm (ram?. -mh) file
+        FileUtil.write(super.getStoragePath()+"/"+RealMediaFile,
+                        RealMediaPointer.getBytes());
+      } catch (Exception e) {
+        theLog.printError(e.toString());
+        throw new MirMediaException(e.toString());
+      }
     }
 
-
-
-
-
-    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";
+      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;
+    public String getStoragePath() {
+      return MirConfig.getProp("Producer.RealMedia.Path");
     }
 
 }
index 2d4d638..75b130a 100755 (executable)
@@ -102,37 +102,6 @@ abstract public class Producer {
                }
        }
 
-       public boolean produceFile(String filename, byte[] in, PrintWriter htmlout, boolean icon) {
-
-               boolean retVal = false;
-
-               if (in!=null) {
-                       try {
-        File f = null;
-        if(icon==false){
-          f = new File(filename);
-          theLog.printDebugInfo("image: " + filename);
-        } else {
-          f = new File(producerStorageRoot + filename);
-          theLog.printDebugInfo("icon: " + filename);
-        }
-                               File dir = new File(f.getParent());
-                               dir.mkdirs();
-
-                               FileOutputStream outStream;
-                               outStream = new FileOutputStream(f);
-                               outStream.write(in);
-                               outStream.close();
-                               retVal = true;
-                       } catch(IOException exception) {
-        logHTML(htmlout, "Producer: File could not be written: " + filename);
-      }
-               }
-               return retVal;
-       }
-
-
-
        //
        // filename methods
 
index c07463f..f98c0fa 100755 (executable)
@@ -35,11 +35,28 @@ public class ProducerAll extends Producer{
                long                startTime = (new java.util.Date()).getTime();
     
         try {
-            //new ProducerImages().handle(htmlout, user, force,sync);
-            new ProducerMedia().handle(htmlout, user, force,sync);
+            new ProducerImages().handle(htmlout, user, force,sync);
         } catch (Exception e) {
             logHTML(htmlout, "Producer.All <font color=\"red\">ERROR:</font>"
-                +" in Producer.Media continuing "+ e.toString());
+                +" in ProducerImages continuing "+ e.toString());
+        }
+        try {
+            new ProducerAudio().handle(htmlout, user, force,sync);
+        } catch (Exception e) {
+            logHTML(htmlout, "Producer.All <font color=\"red\">ERROR:</font>"
+                +" in ProducerAudio continuing "+ e.toString());
+        }
+        try {
+            new ProducerVideo().handle(htmlout, user, force,sync);
+        } catch (Exception e) {
+            logHTML(htmlout, "Producer.All <font color=\"red\">ERROR:</font>"
+                +" in ProducerVideo continuing "+ e.toString());
+        }
+        try {
+            new ProducerOther().handle(htmlout, user, force,sync);
+        } catch (Exception e) {
+            logHTML(htmlout, "Producer.All <font color=\"red\">ERROR:</font>"
+                +" in ProducerOther continuing "+ e.toString());
         }
         try {
             new ProducerStartPage().handle(htmlout, user, force,sync);
diff --git a/source/mircoders/producer/ProducerAudio.java b/source/mircoders/producer/ProducerAudio.java
new file mode 100755 (executable)
index 0000000..bf89571
--- /dev/null
@@ -0,0 +1,24 @@
+package mircoders.producer;
+
+import java.io.*;
+import java.lang.*;
+import java.util.*;
+
+import freemarker.template.*;
+
+import mir.misc.*;
+import mir.storage.*;
+import mir.module.*;
+import mir.entity.*;
+
+import mircoders.entity.*;
+import mircoders.storage.*;
+
+
+public class ProducerAudio extends ProducerMedia {
+
+  protected Database getStorage() throws StorageObjectException {
+    return DatabaseAudio.getInstance();
+  }
+
+}
index 0e0f94a..f75af22 100755 (executable)
@@ -12,126 +12,13 @@ import mir.module.*;
 import mir.entity.*;
 
 import mircoders.entity.*;
-import mir.storage.*;
-
-
-
-public class ProducerImages extends Producer {
-
-       public static void main(String argv[]){
-               try {
-                       new ProducerContent().handle(new PrintWriter(System.out), null,
-                                        false,false);
-               } catch(Exception e) { System.err.println(e.toString()); }
-       }
-
-       public void handle(PrintWriter htmlout, EntityUsers user, boolean force,
-                        boolean sync)
-               throws StorageObjectException, ModuleException {
-               handle(htmlout,user,force,sync,null);
-       }
-
-       public void handle(PrintWriter htmlout, EntityUsers user, boolean force,
-                        boolean sync, String id)
-               throws StorageObjectException, ModuleException
-       {
-               long                sessionConnectTime = 0;
-               long                startTime = (new java.util.Date()).getTime();
-               String              whereClause;
-               String              iconFilename;
-               String              imageFilename;
-               String              productionPath;
-               EntityImages         currentImage;
-               EntityList          batchEntityList;
-        String              orderBy = "date desc, webdb_lastchange desc";
-
-        int contentBatchsize = Integer.parseInt(MirConfig.getProp(
-                                        "Producer.Content.Batchsize"));
-        String imageHost = MirConfig.getProp("Producer.Image.Host");
-        String imagePath = MirConfig.getProp("Producer.Image.Path");
-        String iconPath = MirConfig.getProp("Producer.Image.IconPath");
-
-               // get batch of non-produced images, that are to be published
-               whereClause="is_published='1'";
-               if (id!= null)
-                       whereClause += " and id="+id;
-               if (force==false) whereClause += " and icon_is_produced='0'";
-
-               batchEntityList = imageModule.getByWhereClause(whereClause, orderBy, 0,
-                                                        contentBatchsize);
-               theLog.printDebugInfo("whereclause: " + whereClause);
-
-
-               while (batchEntityList != null) {
-                       for(int i=0;i<batchEntityList.size();i++) {
-                               theLog.printDebugInfo("trying image: " + i);
-                               currentImage = (EntityImages)batchEntityList.elementAt(i);
-
-            try {
-                               // make filenames
-                               String date = currentImage.getValue("date");
-                String datePath = StringUtil.webdbDate2path(date);
-
-                               iconFilename=producerDocRoot + iconPath + datePath +
-                             currentImage.getId() +
-                             ((currentImage.getValue("to_img_type").equals("0"))
-                             ? ".jpg":".gif");
-
-                               imageFilename=datePath + currentImage.getId() +
-                             ((currentImage.getValue("to_img_type").equals("0"))
-                             ? ".jpg":".gif");
-                               productionPath = imagePath + "/" + imageFilename ;
-
-                               currentImage.setValueForProperty("icon_path",iconFilename);
-                currentImage.setValueForProperty("publish_path",imageFilename);
-                               currentImage.setValueForProperty("publish_server", imageHost);
-
-                               if (currentImage.getValue("icon_data")!= null &&
-                    currentImage.getValue("image_data")!= null) {
-                                       // make icon
-                                       boolean iconProduced = produceFile(iconFilename,
-                                                       currentImage.getIcon(),
-                                                       htmlout, true);
-                                       logHTML(htmlout,"icon : "+iconFilename+((
-                            iconProduced==true )?
-                            " succeded":" <font color=\"Red\" failed!</font>"));
-                                       // make image
-                                       boolean imageProduced = produceFile(productionPath,
-                                                        currentImage.getImage(),
-                                                        htmlout, false);
-                                       logHTML(htmlout,"image: "+productionPath +
-                            ((imageProduced==true)?
-                            " succeded":" <font color=\"Red\" failed!</font>"));
-
-                                       // update image-data
-                                       if (iconProduced && imageProduced) {
-                                               currentImage.setValueForProperty("icon_is_produced",
-                                                        "1");
-                                               currentImage.update();
-                                       }
+import mircoders.storage.*;
 
-                               }
-            } catch (Exception e) {
-               logHTML(htmlout, "Producer.Images ERROR with: image ID "+
-                       currentImage.getId() +
-                       " <font color=\"Red\"> failed!</font>");
-            }
-                       }//end for
 
-                       // if next batch get it...
-                       if (batchEntityList.hasNextBatch()){
-                               batchEntityList = imageModule.getByWhereClause(whereClause, 
-                                    orderBy, batchEntityList.getNextBatch(),
-                                    contentBatchsize);
-                       } else {
-                               batchEntityList=null;
-                       }
-               }
-               // Finish
-               sessionConnectTime = new java.util.Date().getTime() - startTime;
-               logHTML(htmlout, "Producer.Images finished: " + sessionConnectTime +
-                " ms.");
+public class ProducerImages extends ProducerMedia {
 
-       }
+  protected Database getStorage() throws StorageObjectException {
+    return DatabaseImages.getInstance();
+  }
 
 }
index 5d38acb..0eb99db 100755 (executable)
@@ -4,7 +4,7 @@ import java.io.*;
 import java.lang.*;
 import java.util.*;
 
-import freemarker.template.*;
+//import freemarker.template.*;
 
 import mir.misc.*;
 import mir.storage.*;
@@ -15,128 +15,79 @@ import mir.media.*;
 import mircoders.media.*;
 import mircoders.entity.*;
 import mircoders.storage.*;
-import mir.storage.*;
-
-
-
-public class ProducerMedia extends Producer {
-
-       public static void main(String argv[]){
-               try {
-                       new ProducerContent().handle(new PrintWriter(System.out), null, false,false);
-               } catch(Exception e) { System.err.println(e.toString()); }
-       }
-
-       public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync)
-               throws StorageObjectException, ModuleException {
-               handle(htmlout,user,force,sync,null);
-       }
-
-       public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync, String id)
-               throws StorageObjectException, ModuleException
-       {
-               long                sessionConnectTime = 0;
-               long                startTime = (new java.util.Date()).getTime();
-        boolean             iconProduced = false;
-        boolean             mediaProduced = false;
-               String              whereClause;
-               String              mediaHost;
-               String              id2=null;
-               String              iconPath;
-               String              mediaPath;
-               String              iconFilename;
-               String              mediaFilename;
-               String              productionPath;
-               Entity              currentMedia;
-               EntityList          batchEntityList;
-
-        int contentBatchsize = Integer.parseInt(MirConfig.getProp("Producer.Content.Batchsize"));
-
-               // get batch of non-produced medias, that are to be published
-               whereClause="is_published='1'";
-               if (id!= null)
-                       whereClause += " and id="+id;
-               if (force==false) whereClause += " and is_produced='0'";
-
-               batchEntityList = uploadedMediaModule.getByWhereClause(whereClause, null, 0, contentBatchsize);
-
-               while (batchEntityList != null) {
-                       for(int i=0;i<batchEntityList.size();i++) {
-                try {
-                    currentMedia = (Entity)batchEntityList.elementAt(i);
-
-                    Entity currentMediaType = DatabaseUploadedMedia.getInstance().getMediaType(currentMedia);
-                    String mediaHandlerName = currentMediaType.getValue("classname");
-                    Class mediaHandlerClass = Class.forName("mircoders.media.MediaHandler"+mediaHandlerName);
-                    MirMedia currentMediaHandler = (MirMedia)mediaHandlerClass.newInstance();
-
-                    String date = currentMedia.getValue("date");
-                    String datePath = StringUtil.webdbDate2path(date);
-
-                    // do icon
-                    if (!currentMedia.getValue("icon_is_produced").equals("1")) {
-                        iconPath = currentMediaHandler.getIconStoragePath();
-                        iconFilename = producerDocRoot+iconPath+datePath+
-                            currentMedia.getId()+"."+currentMediaType.getValue("name");
-                        iconProduced = produceFile(iconFilename, currentMediaHandler.getIcon(currentMedia), htmlout, true);
-                        if(iconProduced) {
-                            currentMedia.setValueForProperty("icon_path",iconFilename);
-                            logHTML(htmlout,"icon : " + iconFilename + (( iconProduced==true )? " succeded":" <font color=\"Red\"> failed!</font>"));
-                        }
-
-                    } else {
-                        iconProduced = true;
-                    }
-
-                    //now produce the media content
-
-                    mediaHost = currentMediaHandler.getPublishHost();
-                    mediaPath = currentMediaHandler.getStoragePath();
-                    id2 = currentMedia.getId();
-                    mediaFilename = currentMedia.getId()+"."+currentMediaType.getValue("name");
-                    //hack: make this a config option. -mh
-                    productionPath = mediaPath+datePath+"/"+ mediaFilename ;
-                    //productionPath = mediaPath+"/"+mediaFilename ;
-
-                    //hack: see above. -mh.
-                    currentMedia.setValueForProperty("publish_path",datePath+"/"+mediaFilename);
-                    //currentMedia.setValueForProperty("publish_path",mediaFilename);
-                    currentMedia.setValueForProperty("publish_server", mediaHost);
-
-                    theLog.printError("ABOUT OT FILE"+id2);
-                    mediaProduced = produceFile(productionPath, currentMediaHandler.get(currentMedia, currentMediaType), htmlout, false);
-                    logHTML(htmlout,"media: " + productionPath + ((mediaProduced==true)?" succeded":" <font color=\"Red\"> failed!</font>"));
-
-                    // update media-data
-                    if (iconProduced && mediaProduced) {
-                        currentMedia.setValueForProperty("icon_is_produced", "1");
-                        currentMedia.setValueForProperty("is_produced", "1");
-                        currentMedia.update();
-                    }
-                } catch (MirMediaException e) {
-                    theLog.printError("media exception: "+id+e.toString());
-                    logHTML(htmlout, "problem with media id: "
-                        +id+" <font color=\"Red\"> failed!</font>: "
-                        +e.toString());
-                } catch (Exception e) {
-                    theLog.printError("failed in reflection: "+id+e.toString());
-                    logHTML(htmlout, "reflection problem in media id: "
-                        +id+" <font color=\"Red\"> failed!</font>: "
-                        +e.toString());
-                }
-                       }
-
-                       // if next batch get it...
-                       if (batchEntityList.hasNextBatch()){
-                               batchEntityList = uploadedMediaModule.getByWhereClause(whereClause, null, batchEntityList.getNextBatch(),contentBatchsize);
-                       } else {
-                               batchEntityList=null;
-                       }
-               }
-               // Finish
-               sessionConnectTime = new java.util.Date().getTime() - startTime;
-               logHTML(htmlout, "Producer.Media finished: " + sessionConnectTime + " ms.");
 
-       }
+abstract public class ProducerMedia extends Producer {
+
+  abstract Database getStorage() throws StorageObjectException;
+
+  public void handle(PrintWriter htmlout, EntityUsers user, boolean force,
+    boolean sync) throws StorageObjectException, ModuleException {
+    handle(htmlout,user,force,sync,null);
+  }
+
+  public void handle(PrintWriter htmlout,EntityUsers user,boolean force,
+    boolean sync, String id) throws StorageObjectException, ModuleException
+  {
+    long                sessionConnectTime = 0;
+    long                startTime = (new java.util.Date()).getTime();
+    String              whereClause;
+    Entity              currentMedia;
+    MirMedia            currentMediaHandler;
+    EntityList          batchEntityList;
+
+    int contentBatchsize =
+            Integer.parseInt(MirConfig.getProp("Producer.Content.Batchsize"));
+
+    // get batch of non-produced medias, that are to be published
+    whereClause="is_published='1'";
+    if (id!= null) {
+      whereClause += " and id="+id;
+      // optimization to avoid select count(*)..
+      contentBatchsize = -1;
+    }
+    if (force==false) whereClause += " and is_produced='0'";
+
+    batchEntityList = getStorage().selectByWhereClause(whereClause,
+                                                null, 0, contentBatchsize);
+
+    while (batchEntityList != null) {
+      for(int i=0;i<batchEntityList.size();i++) {
+        currentMedia = (Entity)batchEntityList.elementAt(i);
+        try {
+          Entity currentMediaType =
+                DatabaseUploadedMedia.getInstance().getMediaType(currentMedia);
+          currentMediaHandler = MediaHelper.getHandler( currentMediaType );
+
+          // now produce
+          currentMediaHandler.produce(currentMedia,currentMediaType);
+          currentMedia.setValueForProperty("is_produced", "1");
+          currentMedia.setValueForProperty("icon_is_produced", "1");
+          currentMedia.setValueForProperty("publish_server",
+                                        currentMediaHandler.getPublishHost());
+          currentMedia.update();
+          logHTML(htmlout,"produced media id "+currentMedia.getId()
+                  +": "+currentMediaType.getValue("mime_type")+" success");
+        } catch (Exception e) {
+          // don't throw and exception here, just log.
+          // we don't want to make the admin interface unuseable
+          theLog.printError("media exception: "+currentMedia.getId()+
+                            e.toString());
+          logHTML(htmlout, "problem with media id: "+currentMedia.getId()+
+                  " <font color=\"Red\"> failed!</font>: "+e.toString());
+        }
+      }
+
+      // if next batch get it...
+      if (batchEntityList.hasNextBatch()){
+        batchEntityList = uploadedMediaModule.getByWhereClause(whereClause,
+          null, batchEntityList.getNextBatch(),contentBatchsize);
+      } else {
+        batchEntityList=null;
+      }
+    }
+    // Finish
+    sessionConnectTime = new java.util.Date().getTime() - startTime;
+    logHTML(htmlout, "Producer.Media finished: " + sessionConnectTime + " ms.");
+  }
 
 }
diff --git a/source/mircoders/producer/ProducerOther.java b/source/mircoders/producer/ProducerOther.java
new file mode 100755 (executable)
index 0000000..f13065d
--- /dev/null
@@ -0,0 +1,24 @@
+package mircoders.producer;
+
+import java.io.*;
+import java.lang.*;
+import java.util.*;
+
+import freemarker.template.*;
+
+import mir.misc.*;
+import mir.storage.*;
+import mir.module.*;
+import mir.entity.*;
+
+import mircoders.entity.*;
+import mircoders.storage.*;
+
+
+public class ProducerOther extends ProducerMedia {
+
+  protected Database getStorage() throws StorageObjectException {
+    return DatabaseOther.getInstance();
+  }
+
+}
diff --git a/source/mircoders/producer/ProducerVideo.java b/source/mircoders/producer/ProducerVideo.java
new file mode 100755 (executable)
index 0000000..4ead0e0
--- /dev/null
@@ -0,0 +1,24 @@
+package mircoders.producer;
+
+import java.io.*;
+import java.lang.*;
+import java.util.*;
+
+import freemarker.template.*;
+
+import mir.misc.*;
+import mir.storage.*;
+import mir.module.*;
+import mir.entity.*;
+
+import mircoders.entity.*;
+import mircoders.storage.*;
+
+
+public class ProducerVideo extends ProducerMedia {
+
+  protected Database getStorage() throws StorageObjectException {
+    return DatabaseVideo.getInstance();
+  }
+
+}
index ed22077..8992cd0 100755 (executable)
@@ -121,7 +121,7 @@ public class ServletModuleImages extends mir.servlet.ServletModule
                 mpReq=null;
 
               if(mediaId!=null){
-                new ProducerMedia().handle(null, null, false, false, mediaId);
+                new ProducerImages().handle(null, null, false, false, mediaId);
               }
              } catch (Exception e) {
                theLog.printError("setting uploaded_media failed: "+e.toString());
index 6e10b89..55fa553 100755 (executable)
@@ -329,6 +329,7 @@ public class ServletModuleOpenIndy extends ServletModule
         String mediaTypeId = null;
         MirMedia mediaHandler;
         Database mediaStorage;
+        ProducerMedia mediaProducer;
  
         //if we found an entry matching the
         //content-type int the table.
@@ -356,7 +357,10 @@ public class ServletModuleOpenIndy extends ServletModule
             mediaHandler = MediaHelper.getHandler(mediaType);
             mediaStorage = MediaHelper.getStorage(mediaType,
                                                 "mircoders.storage.Database");
-          } catch (MirMediaException e) {
+            Class prodCls = Class.forName("mircoders.producer.Producer"
+                                              +mediaType.getValue("tablename"));
+            mediaProducer = (ProducerMedia)prodCls.newInstance();
+          } catch (Exception e) {
             theLog.printError("getting media handler failed: "+e.toString());
             contentModule.deleteById(cid);
             throw new ServletModuleException("getting media handler failed: "
@@ -381,11 +385,12 @@ public class ServletModuleOpenIndy extends ServletModule
             //were done with mpReq at this point, dereference it.
             //as it contains mucho mem. -mh 01.10.2001
             mpReq=null;
-              
+            
             //we got this far, associate the media to the article
             mediaEnt.setValueForProperty("is_published","1");
             mediaEnt.update();
-            new ProducerMedia().handle(null,null,false,false,mediaId);
+            //produce it
+            mediaProducer.handle(null, null, false, false, mediaId);
             DatabaseContentToMedia.getInstance().addMedia(cid,mediaId);
           } catch (Exception e) {
             theLog.printError("setting media failed: "+e.toString());