more media handling stuff.
authormh <mh>
Sun, 30 Sep 2001 12:39:40 +0000 (12:39 +0000)
committermh <mh>
Sun, 30 Sep 2001 12:39:40 +0000 (12:39 +0000)
the ProducerStartPage now sets the tiny icon on the right hand column for
the newswire correctly. You need to update you templates + re-populate
media_type for this.

dbscripts/populate_mediatyp.sql
source/config.properties-dist
source/mir/media/MediaHandlerAudio.java [new file with mode: 0755]
source/mir/media/MediaHandlerGeneric.java
source/mir/media/MediaHandlerImages.java
source/mir/media/MirMedia.java
source/mircoders/entity/EntityUploadedMedia.java
source/mircoders/producer/ProducerStartPage.java
source/mircoders/storage/DatabaseContentToMedia.java
templates-dist/producer/startpage.template

index d7724a7..edb69b5 100755 (executable)
@@ -15,7 +15,7 @@ UPDATE "pg_class" SET "reltriggers" = 0 WHERE "relname" = 'media_type';
 COPY "media_type"  FROM stdin;
 2      unknown application/octet-stream        --      UploadedMedia   \N
 3      jpg     image/gif       ImagesGif       Images  \N
-4      mp3     audio/mp3       Generic UploadedMedia   \N
+4      mp3     audio/mp3       Audio   UploadedMedia   \N
 \.
 -- Enable triggers
 UPDATE pg_class SET reltriggers = (SELECT count(*) FROM pg_trigger where pg_class.oid = tgrelid) WHERE relname = 'media_type';
index d86ce49..25faa0c 100755 (executable)
@@ -102,6 +102,13 @@ Producer.Media.Path=/pub/Dokumente/Indymedia/de-tech/Mir/produced/media
 # relativ directory, where the thumbnails will be saved
 Producer.Image.IconPath=/icon
 
+# Tiny Icons for the media types on the newswire summary.
+# (right hand side of start page)
+Producer.Icon.TinyImage=photo_small.gif
+Producer.Icon.TinyAudio=audio_small.gif
+Producer.Icon.TinyVideo=video_small.gif
+Producer.Icon.TinyText=text_small.gif
+
 
 
 #
diff --git a/source/mir/media/MediaHandlerAudio.java b/source/mir/media/MediaHandlerAudio.java
new file mode 100755 (executable)
index 0000000..20fd12d
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * put your module comment here
+ */
+
+
+package  mir.media;
+
+import java.util.*;
+
+import mir.entity.*;
+import mir.misc.*;
+import mir.storage.*;
+
+
+/**
+ * Interfacedefinition für Datenbank-Adpatoren. Die Adaptoren legen
+ * jeweils das Verhalten und die Befehlsmächtigkeit der Datenbank
+ * fest.
+ *
+ * @author <mh>
+ * @version 24.09.2001
+ */
+
+public class MediaHandlerAudio extends MediaHandlerGeneric implements MirMedia
+{
+
+  public String getTinyIcon()
+  {
+    return MirConfig.getProp("Producer.Icon.TinyAudio");
+  }
+
+  public String getIconAlt()
+  {
+    return "Audio";
+  }
+
+  public boolean isAudio()
+  {
+    return true;
+  }
+}
index df11bf0..edd7ff1 100755 (executable)
@@ -93,6 +93,32 @@ public class MediaHandlerGeneric implements MirMedia
     {
         return MirConfig.getProp("Producer.Media.Host");
     }
+
+    public String getTinyIcon()
+    {
+        return MirConfig.getProp("Producer.Icon.TinyText");
+    }
+
+    public String getIconAlt()
+    {
+        return "Generic media"; 
+    }
+
+    public boolean isVideo()
+    {
+        return false;
+    }
+
+    public boolean isAudio()
+    {
+        return false;
+    }
+
+    public boolean isImage()
+    {
+        return false;
+    }
+
 }
         
         
index bf3f553..d1f96f8 100755 (executable)
@@ -100,5 +100,30 @@ public class MediaHandlerImages
     {
         return MirConfig.getProp("Producer.Image.Host");
     }
-        
+
+    public String getTinyIcon ()
+    {
+        return MirConfig.getProp("Producer.Icon.TinyImage");
+    } 
+
+    public String getIconAlt ()
+    {
+        return "Image";
+    } 
+
+    public boolean isVideo ()
+    {
+        return false;
+    } 
+
+    public boolean isAudio ()
+    {
+        return false;
+    } 
+
+    public boolean isImage ()
+    {
+        return true;
+    } 
+
 }
index d4a0f0c..f57b45c 100755 (executable)
@@ -24,32 +24,17 @@ public interface  MirMedia{
         * @return Adaptorklasse als String
         */
        public abstract boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt );
-
-
        public abstract byte[] get (Entity ent, Entity mediaTypeEnt);
-
+       public abstract byte[] getIcon (Entity ent);
+       //public abstract String getURL (Entity ent);
        public String getStoragePath ();
        public String getIconStoragePath ();
        public String getPublishHost ();
-
-
-       /**
-        * Liefert die URL für JDBC zurück, in den die Parameter user, pass und host
-        * eingefügt werden. Die URL wird aus der Konfiguration geholt.
-        *
-        * @param user user als String
-        * @param pass passwort als String
-        * @param host host als String
-        * @return url als String
-        */
-       //public abstract String makeURL (Entity ent);
-
-
-       /**
-        * Gibt zurück, ob das SQL der Datenbank den <code>limit</code>-Befehl beherrscht.
-        * @return true wenn ja, sonst false
-        */
-       public abstract byte[] getIcon (Entity ent);
+       public String getTinyIcon ();
+       public String getIconAlt ();
+       public boolean isVideo ();
+       public boolean isAudio ();
+       public boolean isImage ();
 
 }
 
index 4c34f26..554795c 100755 (executable)
@@ -42,6 +42,17 @@ public class EntityUploadedMedia extends AbstractEntity implements Entity
                super.setValues(theStringValues);
        }
 
+       /**
+        * fetches the MediaType entry assiciated w/ this media
+        *
+        * @return mir.entity.Entity
+        */
+       public Entity getMediaType() {
+               return ((DatabaseUploadedMedia)theStorageObject).getMediaType(this);
+       }
+
+
+
   public void finalize() {
     instances--;
     super.finalize();
index 5b478b7..ea3e937 100755 (executable)
@@ -7,6 +7,7 @@ import java.util.*;
 import freemarker.template.*;
 
 import mir.misc.*;
+import mir.media.*;
 import mir.storage.*;
 import mir.module.*;
 import mir.entity.*;
@@ -56,7 +57,17 @@ public class ProducerStartPage extends Producer {
     SimpleHash          startPageModel;
     SimpleList          contentList;
     String              currentMediaId;
+    EntityList          upMediaEntityList;
     EntityList          imageEntityList;
+    Entity              mediaType;
+    EntityUploadedMedia uploadedMedia;
+    Class               mediaHandlerClass;
+    MirMedia            mediaHandler;
+    String              mediaHandlerName;
+    String              tinyIcon;
+    String              iconAlt;
+    Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Producer.Logfile"));
+
     SimpleList mediaList;
     SimpleHash contentHash;
 
@@ -68,6 +79,73 @@ public class ProducerStartPage extends Producer {
     whereClause="is_published=true AND to_article_type >= 1";
     entityList = contentModule.getContent(whereClause,"date desc, webdb_create desc",0,newsPerPage);
     SimpleList newsWireList = HTMLTemplateProcessor.makeSimpleList(entityList);
+    for (int i=0; i < entityList.size();i++) {
+      currentContent = (EntityContent)entityList.elementAt(i);
+      //fetching/setting the images
+      upMediaEntityList = DatabaseContentToMedia.getInstance().getUploadedMedia(currentContent);
+      if (upMediaEntityList!=null && upMediaEntityList.getCount()>=1) {
+        tinyIcon = null;
+        iconAlt = null;
+        mediaHandler = null;
+        mediaHandlerName = null;
+        for (int n=0; n < upMediaEntityList.size();n++) {
+          uploadedMedia = (EntityUploadedMedia)upMediaEntityList.elementAt(n);
+          mediaType = uploadedMedia.getMediaType();
+
+          //must of had a non-existant to_media_type entry..
+          //let's save our ass.
+          if (mediaType != null) {
+              /*
+               * grrr. why doesn't getId return an int! if It
+               * did I could just compare the value of getId and
+               * pick the biggest one. or is there
+               * another way around this that I am missing?
+               * can we make getIdasInt() or can we just have
+               * another getId() that returns an Int and the VM 
+               * will handle it transparantly? -mh
+               */
+              try {
+                mediaHandlerName = mediaType.getValue("classname");
+                mediaHandlerClass = Class.forName("mir.media.MediaHandler"+mediaHandlerName);
+                mediaHandler = (MirMedia)mediaHandlerClass.newInstance();
+              } catch (Exception e) {
+                theLog.printError("ProducerStartpage:problem in reflection: "+mediaHandlerName);
+              }
+
+              //the best media type
+              if (mediaHandler.isVideo()) {
+                tinyIcon = MirConfig.getProp("Producer.Icon.TinyVideo");
+                iconAlt = "Video";
+                break;
+              } else if (mediaHandler.isAudio()) {
+                tinyIcon = MirConfig.getProp("Producer.Icon.TinyAudio");
+                iconAlt = "Audio";
+              } else if (tinyIcon == null && !mediaHandler.isImage()) {
+                tinyIcon = mediaHandler.getTinyIcon();
+                iconAlt = mediaHandler.getIconAlt();
+              }
+          }
+        }
+        //it only has image(s)
+        if (tinyIcon == null) {
+          tinyIcon = MirConfig.getProp("Producer.Icon.TinyImage");
+          iconAlt = "Image";
+        }
+
+      // uploadedMedia Entity list is empty.
+      // we only have text
+      } else {
+        tinyIcon = MirConfig.getProp("Producer.Icon.TinyText");
+        iconAlt = "Text";
+      }
+        
+      try{
+        //mediaList = HTMLTemplateProcessor.makeSimpleList(upMediaEntityList);
+        contentHash = (SimpleHash)newsWireList.get(i);
+        contentHash.put("tiny_icon", imageRoot+"/"+tinyIcon);
+        contentHash.put("icon_alt", iconAlt);
+      } catch (Exception e){}
+    }
 
     // get the startarticle and the related images
     whereClause="is_published=true AND to_article_type=4";
index 2f5b3b5..3a1fb52 100755 (executable)
@@ -83,6 +83,28 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
   }
 
 
+  /**
+   * get all the uploaded Media belonging to a content entity
+   *
+   */
+  public EntityList getUploadedMedia(EntityContent content) {
+    EntityList returnList=null;
+    if (content != null) {
+      // get all to_topic from media_x_topic
+      String id = content.getId();
+      //this is not supported by mysql
+      String subselect = "id in (select media_id from " + theTable + " where content_id=" + id+")";
+
+      try {
+        returnList = DatabaseUploadedMedia.getInstance().selectByWhereClause(subselect,-1);
+      } catch (Exception e) {
+        theLog.printDebugInfo("-- get uploadedMedia failed " + e.toString());
+      }
+    }
+    return returnList;
+  }
+
+
   public void setMedia(String contentId, String[] mediaId) {
     if (contentId == null){
       return;
index 242811c..3a46c73 100755 (executable)
@@ -98,7 +98,7 @@
                  <!-- newswire --> 
                   <p> 
                    <list newswire as n>
-                   <img alt="[Text]" border="0" height="10" src="/images/text_small.gif" width="12"> 
+                   <img alt=${n.icon_alt} border="0" height="10" src=${n.tiny_icon} width="12"> 
                     <a href="${config.docroot}${n.publish_path}${n.id}.shtml"><b>${n.title}</b></a><br>
                     <font size="-2"><b></b>${n.webdb_create_formatted}</font><br>
                     <br>