tiny error message fix
[mir.git] / source / mircoders / media / MediaHandlerGeneric.java
index 98bb183..1fc91db 100755 (executable)
@@ -6,6 +6,9 @@
 package  mircoders.media;
 
 import java.util.*;
+import java.io.*;
+
+import freemarker.template.SimpleList;
 
 import mir.media.*;
 import mir.entity.*;
@@ -35,41 +38,50 @@ 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 static String imageHost = MirConfig.getProp("Producer.Image.Host");
+    protected static String imageRoot = MirConfig.getProp("Producer.ImageRoot");
+    protected static 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) {
-            theLog.printError(e.toString()); 
+            theLog.printError(e.toString());
             throw new MirMediaException(e.toString());
         }
 
         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 {
@@ -78,11 +90,11 @@ public class MediaHandlerGeneric implements MirMedia
         if (size < 0) return null;
 
         byte[] container = new byte[(int)size];
-            
+
         try {
             FileUtil.read(fileName, container);
         } catch (Exception e) {
-            theLog.printError(e.toString()); 
+            theLog.printError(e.toString());
             throw new MirMediaException(e.toString());
         }
 
@@ -124,47 +136,37 @@ public class MediaHandlerGeneric implements MirMedia
 
     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());
+        return "Generic media";
     }
 
-    public String getListView(Entity ent, Entity mediaTypeEnt)
+    public SimpleList getURL(Entity ent, Entity mediaTypeEnt)
     {
-      //String title = ent.getValue("title")+
-      //  " - "+mediaTypeEnt.getValue("name")+" "+
-      //  ent.getValue("size")+" Bytes";
-      return StringUtil.createIMGLinks(imageHost+
-        getBigIcon(), null, null, null);
+      SimpleList theList = new SimpleList();
+      theList.add(ent);
+      return theList;
     }
 
     public boolean isVideo()
     {
-        return false;
+      return false;
     }
 
     public boolean isAudio()
     {
-        return false;
+      return false;
     }
 
     public boolean isImage()
     {
-        return false;
+      return false;
+    }
+
+    public String getDescr()
+    {
+      return "";
     }
 
 }
-        
-        
+
+