more media.. media is now available in article
authormh <mh>
Tue, 2 Oct 2001 00:33:12 +0000 (00:33 +0000)
committermh <mh>
Tue, 2 Oct 2001 00:33:12 +0000 (00:33 +0000)
( content) pages.

the reflection stuff is getting out of hand, I'll wrap it in a helper class
maybe with some sort of caching, of handlers or singletons..

12 files changed:
dbscripts/create_pg.sql
source/config.properties-dist
source/mir/media/MediaHandlerAudio.java
source/mir/media/MediaHandlerGeneric.java
source/mir/media/MediaHandlerImages.java
source/mir/media/MirMedia.java
source/mir/misc/StringUtil.java
source/mir/module/AbstractModule.java
source/mircoders/producer/ProducerContent.java
source/mircoders/servlet/ServletModuleOpenIndy.java
source/mircoders/storage/DatabaseUploadedMedia.java
templates-dist/producer/content.template

index 7092165..530591e 100755 (executable)
@@ -326,7 +326,8 @@ CREATE TABLE "media" (
 
 CREATE TABLE "uploaded_media" (
        "icon_is_produced" boolean DEFAULT '0' NOT NULL,
-       "icon_path" character varying(255)
+       "icon_path" character varying(255),
+    "size" integer
 ) INHERITS ("media");
 
 CREATE TABLE "images" (
index 82c6c43..69a8108 100755 (executable)
@@ -109,6 +109,12 @@ Producer.Icon.TinyAudio=audio_small.gif
 Producer.Icon.TinyVideo=video_small.gif
 Producer.Icon.TinyText=text_small.gif
 
+#Medium sized icons used at various places
+Producer.Icon.BigImage=photo_big.gif
+Producer.Icon.BigAudio=audio_big.gif
+Producer.Icon.BigVideo=video_big.gif
+Producer.Icon.BigText=text_big.gif
+
 
 
 #
index 20fd12d..dc3e08b 100755 (executable)
@@ -24,9 +24,17 @@ import mir.storage.*;
 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 MirConfig.getProp("Producer.Icon.TinyAudio");
+    return tinyIcon;
+  }
+
+  public String getBigIcon()
+  {
+    return bigIcon;
   }
 
   public String getIconAlt()
index edd7ff1..471f06c 100755 (executable)
@@ -24,6 +24,7 @@ import mir.storage.*;
 public class MediaHandlerGeneric implements MirMedia
 {
 
+    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 ) {
         String ext = mediaTypeEnt.getValue("name");
@@ -32,6 +33,7 @@ public class MediaHandlerGeneric implements MirMedia
         String mediaFname = ent.getId()+"."+ext;
         String date = ent.getValue("date");
         String datePath = StringUtil.webdbDate2path(date);
+        Integer size = new Integer(uploadedData.length);
         //hack: make it a config option to use "dated" dirs
         //we can't cause of stallman -mh
         //if(FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData)) {
@@ -44,6 +46,7 @@ public class MediaHandlerGeneric implements MirMedia
                 //ent.setValueForProperty("publish_path",datePath+"/"+mediaFname);
                 ent.setValueForProperty("publish_path", mediaFname);
                 ent.setValueForProperty("publish_server", mediaHost);
+                ent.setValueForProperty("size", size.toString());
                 ent.update();
             } catch (StorageObjectException e) {
                 theLog.printError("StorageObjectException: "+e.toString()); 
@@ -99,11 +102,25 @@ public class MediaHandlerGeneric implements MirMedia
         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 title = ent.getValue("title")+
+        " - "+mediaTypeEnt.getValue("name")+" "+
+        ent.getValue("size")+" Bytes";
+      return StringUtil.createURLLinks(ent.getValue("publish_server")+
+        ent.getValue("publish_path"), title, imageRoot, getBigIcon());
+    }
+
     public boolean isVideo()
     {
         return false;
index d1f96f8..52293d8 100755 (executable)
@@ -86,6 +86,14 @@ public class MediaHandlerImages
         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 getStoragePath()
     {
         return MirConfig.getProp("Producer.Image.Path");
@@ -106,6 +114,11 @@ public class MediaHandlerImages
         return MirConfig.getProp("Producer.Icon.TinyImage");
     } 
 
+    public String getBigIcon ()
+    {
+        return MirConfig.getProp("Producer.Icon.BigImage");
+    } 
+
     public String getIconAlt ()
     {
         return "Image";
index f57b45c..f6c59b7 100755 (executable)
@@ -26,10 +26,11 @@ public interface  MirMedia{
        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 abstract String getURL (Entity ent, Entity mediaTypeEnt);
        public String getStoragePath ();
        public String getIconStoragePath ();
        public String getPublishHost ();
+       public String getBigIcon ();
        public String getTinyIcon ();
        public String getIconAlt ();
        public boolean isVideo ();
index 2b70011..54d70c6 100755 (executable)
@@ -743,8 +743,8 @@ public final class StringUtil {
     return Math.min(i, j);
   }
 
-  /**
-   * Diese Routine macht aus links in reinem text browsbare links
+   /**
+   * This routine makes html links (href) out of text browseable urls
    * @param text
    * @return Konvertierter String
    */
@@ -847,21 +847,69 @@ public final class StringUtil {
   }
 
   /**
-   *  createURLLinks wandelt text im url-format
-   *  in einen klickbaren link um
-   *  nur sinnvoll, wenn text nicht im html-format eingegeben
+   * this routine takes text in url format and makes
+   * a clickaeble "<href>" link removing any "illegal" html tags
+   * @param haystack, the url
+   * @param title, the href link text
+   * @param imagRoot, the place to find icons
+   * @param extImage, the url of the icon to show next to the link
+   * @return a String containing the url
    */
-  public static String createURLLinks(String haystack,String imageRoot,String extImage,String intImage) {
+  public static String createURLLinks(String haystack, String title, String imageRoot,String extImage) {
     try {
       //dieser Ausdruck brauch dringend fachliche Beratung
       RE regex = new RE("((https://)|(http://)|(ftp://))+([a-zA-Z0-9_-]+).([a-zA-Z0-9_.:-]+)/?([^ \t\r\n<>]+[^ \t\r\n.,<>])");
-      return regex.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/>&#160;<a href=\"$0\">$0</a>");
+      if (title == null) {
+        return regex.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/>&#160;<a href=\"$0\">$0</a>");
+      } else {
+        title = removeHTMLTags(title);
+        return regex.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/>&#160;<a href=\"$0\">"+title+"</a>");
+      } 
     } catch(REException ex){
       return null;
     }
   }
 
   /**
+   * this routine takes text in url format and makes
+   * a clickaeble "<href>" link removing any "illegal" html tags
+   * @param haystack, the url
+   * @param imageRoot, the place to find icons
+   * @param extImage, the url of the icon to show next to the link
+   * @param intImage, unused
+   * @return a String containing the url
+   */
+  public static String createURLLinks(String haystack, String title, String imageRoot,String extImage,String intImage) {
+    return createURLLinks(haystack, title, imageRoot, extImage);
+  }
+
+  /**
+   * this routine takes text in url format and makes
+   * an image link removing any "illegal" html tags
+   * @param haystack, the url
+   * @param title, the image alt text, can be null
+   * @param height, height of the image
+   * @param width, width of the image
+   * @return a String containing the url
+   */
+  public static String createIMGLinks(String haystack, String title, String height,String width) {
+    try {
+      //dieser Ausdruck brauch dringend fachliche Beratung
+      RE regex = new RE("((https://)|(http://)|(ftp://))+([a-zA-Z0-9_-]+).([a-zA-Z0-9_.:-]+)/?([^ \t\r\n<>]+[^ \t\r\n.,<>])");
+      if (title != null) {
+        title = removeHTMLTags(title);
+        return regex.substituteAll(haystack,"<img src=\"$0\" width=\""+width+"\" height=\""+height+"\" alt=\""+title+"\"/>&#160;<br><i>"+title+"</i>");
+      } else {
+        return regex.substituteAll(haystack,"<img src=\"$0\" width=\""+width+"\" height=\""+height+"\" alt=\"\"/>&#160;");
+      } 
+    } catch(REException ex){
+      return null;
+    }
+  }
+
+
+
+   /**
    *  deleteForbiddenTags
    *  this method deletes all <script>, <body> and <head>-tags
    */
@@ -956,7 +1004,7 @@ try {
     content=convertNewline2Break(content);
     content=convertNewline2P(content);
     content=createMailLinks(content,producerDocRoot,mailImage);
-    content=createURLLinks(content,producerDocRoot,extImage,intImage);
+    content=createURLLinks(content,null,producerDocRoot,extImage,intImage);
     return content;
   }
 
index db40dd6..b834130 100755 (executable)
@@ -20,7 +20,6 @@ import  mir.entity.*;
  */
 public class AbstractModule {
        protected StorageObject theStorage;
-       protected Logfile theLog;
 
   public void setStorage(StorageObject storage) {
         this.theStorage = storage;
@@ -63,8 +62,6 @@ public class AbstractModule {
                try {
                        if (theStorage == null)
                                throw  new ModuleException("Kein StorageObject gesetzt");
-            theLog = Logfile.getInstance(MirConfig.getProp("Home") + "log/media.log");
-            theLog.printError("aboot to run getByWhere...");
                        return theStorage.selectByWhereClause(whereClause, offset);
                }
                catch (StorageObjectException e){
index bee57b8..11519f1 100755 (executable)
@@ -2,11 +2,13 @@ package mircoders.producer;
 
 import java.io.*;
 import java.lang.*;
+import java.lang.reflect.*;
 import java.util.*;
 
 import freemarker.template.*;
 
 import mir.misc.*;
+import mir.media.*;
 import mir.storage.*;
 import mir.module.*;
 import mir.entity.*;
@@ -67,6 +69,15 @@ public class ProducerContent extends Producer {
     HashMap             currentContentValues;
     SimpleHash          imageHash = new SimpleHash();
     EntityUsers         userEntity=null;
+    Entity              mediaType;
+    Entity              upMedia;
+    SimpleHash          upMediaSimpleHash;
+    Class               mediaHandlerClass;
+    Class               mediaStorageClass;
+    String              mediaStorageName;
+    String              mediaHandlerName=null;
+    MirMedia            mediaHandler=null;
+    Database            mediaStorage=null;
 
 
 
@@ -136,12 +147,37 @@ public class ProducerContent extends Producer {
         //create the freemarker-model
         SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHash(currentContentValues);
 
-        // get the images
-        EntityList currentMedia = DatabaseContentToMedia.getInstance().getImages(currentContent);
-        if (currentMedia!=null && currentMedia.getCount()>=1) {
-          SimpleList mediaList = HTMLTemplateProcessor.makeSimpleList(currentMedia);
+        // get the uploaded media
+        EntityList currentMediaList = DatabaseContentToMedia.getInstance().getUploadedMedia(currentContent);
+        if (currentMediaList!=null && currentMediaList.getCount()>=1) {
+          SimpleList mediaList = new SimpleList();
+          for (int n=0; n < currentMediaList.size();n++) {
+            upMedia = currentMediaList.elementAt(n);
+            upMediaSimpleHash = HTMLTemplateProcessor.makeSimpleHash(upMedia);
+            mediaType = ((EntityUploadedMedia)upMedia).getMediaType();
+            //must be a non-existant to_media_type entry..
+            if (mediaType != null) {
+              try {
+                mediaHandlerName = mediaType.getValue("classname");
+                mediaStorageName = mediaType.getValue("tablename");
+                mediaStorageClass = Class.forName("mircoders.storage.Database"+mediaStorageName);
+                mediaHandlerClass = Class.forName("mir.media.MediaHandler"+mediaHandlerName);
+                mediaHandler = (MirMedia)mediaHandlerClass.newInstance();
+                if(!mediaStorageName.equals(new String("UploadedMedia"))) {
+                  Method m = mediaStorageClass.getMethod("getInstance", null);
+                  mediaStorage = (Database)m.invoke(null, null);
+                  //we most likely need further info
+                  upMedia = mediaStorage.selectById(upMedia.getId());
+                }
+              } catch (Exception e) {
+                theLog.printError("ProducerStartpage:problem in reflection: "+mediaHandlerName);
+              } //end catch
+              upMediaSimpleHash.put("url", mediaHandler.getURL(upMedia, mediaType));
+              mediaList.add(upMediaSimpleHash);
+            } //end if media_type != null
+          } //end for
           mergeData.put("to_media", mediaList);
-        }
+        } //end if currentMediaList != null
 
         // get the comments for the article
         mergeData.put("comments", currentContent.getComments());
index 2374afe..ccec385 100755 (executable)
@@ -285,7 +285,6 @@ public class ServletModuleOpenIndy extends ServletModule
                 mediaEnt.setValues(mediaValues);
                 mediaId = mediaEnt.insert();
 
-                theLog.printError("done inserting!!! ");
                 Class mediaHandlerClass = Class.forName("mir.media.MediaHandler"+mediaHandlerName);
                 MirMedia mediaHandler = (MirMedia)mediaHandlerClass.newInstance();
                 mediaHandler.set(mpReq.getMedia(), mediaEnt,mediaTypesList.elementAt(0));
index 8489e88..15ce4e6 100755 (executable)
@@ -57,7 +57,6 @@ public class DatabaseUploadedMedia extends Database implements StorageObject {
   public Entity getMediaType(Entity ent) {
     Entity type=null;
     try {
-      theLog.printError("about to run relationMediaType");
       type = relationMediaType.getOne(ent);
     }
     catch (StorageObjectException e) {
index e01c922..c01372b 100755 (executable)
                         <h2>${title}</h2>
                         <h4><i>${creator}, ${webdb_create_formatted}</i></h4>
                         <p><b>${description}</b>
-                       <!-- images -->
-                       <list to_media as images>
+                       <!-- media -->
+                       <list to_media as media>
                        <p> 
-                          <if images && images["is_published"]=="1">                   
-                          <img src="${imageHost}/${images["id"]}.jpg" width="${images["img_width"]}" height="${images["img_height"]}" alt="${images["title"]}"> 
-                          </if><br><i>${images["title"]}</i>
+                          <if media && media["is_published"]=="1">
+                            ${media["url"]}
+                          </if>
                        </p>
                        </list>
-                       <!-- images -->
+                       <!-- media -->
                        <p>${content_data}</p>
                        <if creator_main_url || creator_email>
                         <table width="100%" bgcolor="#FFFFFF">