made the getUrl() method of MirMedia return a SimpleList of TemplateModels
authormh <mh>
Tue, 26 Mar 2002 20:47:21 +0000 (20:47 +0000)
committermh <mh>
Tue, 26 Mar 2002 20:47:21 +0000 (20:47 +0000)
(either Entity directly or a self made one.) so that the templates have more
flexibility. it's not quite finished, but hang in there. it does work

source/mir/media/MirMedia.java
source/mircoders/entity/EntityUploadedMedia.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
templates-dist/producer/content.template

index 0431e9b..646cd0f 100755 (executable)
@@ -8,6 +8,8 @@ package  mir.media;
 
 import java.util.*;
 
+import freemarker.template.SimpleList;
+
 import mir.entity.*;
 
 /**
@@ -113,7 +115,7 @@ public interface  MirMedia{
    * @see mir.entity.Entity
    * @see mir.misc.StringUtil
    */
-  public abstract String getURL (Entity ent, Entity mediaTypeEnt)
+  public abstract SimpleList getURL (Entity ent, Entity mediaTypeEnt)
     throws MirMediaException;
 
        /**
index 044a37f..7e67826 100755 (executable)
@@ -65,8 +65,8 @@ public class EntityUploadedMedia extends Entity
     String returnValue=null;
 
     if (key!=null) {
-      if (key.equals("url"))
-        returnValue=getUrl();
+      if (key.equals("big_icon"))
+        returnValue=getBigIcon();
       else if (key.equals("list"))
         returnValue=getListView();
       else
@@ -77,10 +77,29 @@ public class EntityUploadedMedia extends Entity
 
   public TemplateModel get(java.lang.String key) throws TemplateModelException
   {
+    if (key.equals("url"))
+      return getUrl();
+
     return new SimpleScalar(getValue(key));
   }
 
-  private String getUrl()
+  private String getBigIcon()
+  {
+    MirMedia            mediaHandler=null;
+    Entity              mediaType=null;
+
+    try {
+      mediaType = getMediaType();
+      mediaHandler = MediaHelper.getHandler( mediaType );
+      return mediaHandler.getBigIcon();
+    } catch (Exception ex) {
+      theLog.printWarning("-- getBigIcon: could not fetch data "
+                         + this.getClass().toString()+" "+ ex.toString());
+    }
+    return null;
+  }
+
+  private SimpleList getUrl()
   {
     MirMedia            mediaHandler=null;
     Entity              mediaType=null;
index 31eaff9..e3d2124 100755 (executable)
@@ -8,6 +8,8 @@ package  mircoders.media;
 import java.util.*;
 import java.io.*;
 
+import freemarker.template.SimpleList;
+
 import mir.media.*;
 import mir.entity.*;
 import mir.misc.*;
@@ -137,17 +139,11 @@ public class MediaHandlerGeneric implements MirMedia
         return "Generic media"; 
     }
 
-    public String getURL(Entity ent, Entity mediaTypeEnt)
+    public SimpleList 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());
+      SimpleList theList = new SimpleList();
+      theList.add(ent);
+      return theList;
     }
 
     public String getListView(Entity ent, Entity mediaTypeEnt)
@@ -155,8 +151,7 @@ public class MediaHandlerGeneric implements MirMedia
       //String title = ent.getValue("title")+
       //  " - "+mediaTypeEnt.getValue("name")+" "+
       //  ent.getValue("size")+" Bytes";
-      return StringUtil.createIMGLinks(imageHost+
-        getBigIcon(), null, null, null);
+      return getBigIcon();
     }
 
     public boolean isVideo()
index d5db1a1..b72ca18 100755 (executable)
@@ -6,6 +6,8 @@ import java.io.*;
 import java.util.*;
 import java.lang.reflect.*;
 
+import freemarker.template.SimpleList;
+
 import mir.media.*;
 import mir.misc.*;
 import mir.entity.*;
@@ -116,14 +118,6 @@ public class MediaHandlerImages implements MirMedia
     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");
@@ -132,6 +126,13 @@ public class MediaHandlerImages implements MirMedia
       null, ent.getValue("icon_height"), ent.getValue("icon_width"));
   }
 
+  public SimpleList getURL(Entity ent, Entity mediaTypeEnt)
+  {
+    SimpleList theList = new SimpleList();
+    theList.add(ent);
+    return theList;
+  }
+
   public String getStoragePath()
   {
     return MirConfig.getProp("Producer.Image.Path");
index 270bc64..26484fd 100755 (executable)
@@ -7,6 +7,9 @@ package  mircoders.media;
 
 import java.util.*;
 
+import freemarker.template.SimpleList;
+import freemarker.template.SimpleHash;
+
 import mir.media.*;
 import mir.entity.*;
 import mir.misc.*;
@@ -70,31 +73,34 @@ public class MediaHandlerMp3 extends MediaHandlerAudio implements MirMedia
       }
     }
 
-  public String getURL(Entity ent, Entity mediaTypeEnt)
+  public SimpleList 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;
-
-    }
+    SimpleList theList = new SimpleList();
+
+    //String stringSize = ent.getValue("size");
+    //int size = Integer.parseInt(stringSize, 10)/1024;
+    theList.add(ent);
+   
+    String basePath=StringUtil.regexpReplace(ent.getValue("publish_path"),
+                                            ".mp3$","");
+
+    // @todo the texts ("title") below urgently need to be sanely localizaeble
+    // somehow
+    SimpleHash m3uHash = new SimpleHash();
+    m3uHash.put("publish_path", basePath+".m3u");
+    m3uHash.put("publish_server", ent.getValue("publish_server"));
+    m3uHash.put("title", "stream URL");
+    theList.add(m3uHash);
+
+    SimpleHash plsHash = new SimpleHash();
+    plsHash.put("publish_path", basePath+".pls");
+    plsHash.put("publish_server", ent.getValue("publish_server"));
+    plsHash.put("title", "playlist URL");
+    theList.add(plsHash);
+
+    return theList;
+
+  }
 
 }
         
index 3536981..1b08664 100755 (executable)
@@ -7,6 +7,9 @@ package  mircoders.media;
 
 import java.util.*;
 
+import freemarker.template.SimpleList;
+import freemarker.template.SimpleHash;
+
 import mir.media.*;
 import mir.entity.*;
 import mir.misc.*;
@@ -53,16 +56,8 @@ public class MediaHandlerRealAudio extends MediaHandlerAudio implements
       }
     }
 
-    public String getURL(Entity ent, Entity mediaTypeEnt)
+    public String getStoragePath()
     {
-      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 String getStoragePath() {
       return MirConfig.getProp("Producer.RealMedia.Path");
     }
 
index a6e4e8d..91e888e 100755 (executable)
@@ -7,6 +7,9 @@ package  mircoders.media;
 
 import java.util.*;
 
+import freemarker.template.SimpleList;
+import freemarker.template.SimpleHash;
+
 import mir.media.*;
 import mir.entity.*;
 import mir.misc.*;
@@ -53,16 +56,8 @@ public class MediaHandlerRealVideo extends MediaHandlerVideo implements
       }
     }
 
-    public String getURL(Entity ent, Entity mediaTypeEnt)
+    public String getStoragePath()
     {
-      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 String getStoragePath() {
       return MirConfig.getProp("Producer.RealMedia.Path");
     }
 
index d50c5c1..632a013 100755 (executable)
                         <h2>${data.content.title}</h2>
                         <h4><i>${data.content.creator}, ${data.content.webdb_create_formatted}</i></h4>
                         <p><b>${data.content.description_parsed}</b>
-                       <!-- media -->
-                       <list data.content.to_media_audio as media>
-                       <p>
-                            ${media["url"]}
-                       </p>
+          <!-- media -->
+          <list data.content.to_media_audio as media>
+            <list media["url"] as audio>
+              <p>
+                <img src="/img/${media["big_icon"]}" border="0" alt="">
+                <a href="${audio["publish_server"]}${audio["publish_path"]}">
+                ${audio["title"]}</a>
+              </p>
             </list>
-                       <list data.content.to_media_video as media>
-                       <p>
-                            ${media["url"]}
-                       </p>
-                       </list>
-                       <list data.content.to_media_other as media>
-                       <p>
-                            ${media["url"]}
-                       </p>
-                       </list>
-                       <list data.content.to_media_images as media>
-                       <p> I
-                            ${media["url"]}
-                       </p>
-                       </list>
-                       <!-- media -->
-                       <p>${data.content.content_data_parsed}</p>
-                       <if content.creator_main_url || content.creator_email>
+          </list>
+          <list data.content.to_media_video as media>
+            <list media["url"] as video>
+              <p>
+                <img src="/img/${media["big_icon"]}" border="0" alt="">
+                <a href="${video["publish_server"]}${video["publish_path"]}">
+                ${video["title"]}</a>
+              </p>
+            </list>
+          </list>
+          <list data.content.to_media_other as media>
+            <list media["url"] as other>
+              <p>
+                <img src="/img/${media["big_icon"]}" border="0" alt="">
+                <a href="${other["publish_server"]}${other["publish_path"]}">
+                ${other["title"]}</a>
+              </p>
+            </list>
+          </list>
+          <list data.content.to_media_images as media>
+            <list media["url"] as image>
+              <p>
+                <img src="${image["publish_server"]}${image["publish_path"]}"
+                 border="0" width="${image["img_width"]}"
+                 height="${image["img_width"]}" alt="${image["title"]}">
+                 <br><i>${image["title"]}</i>
+              </p>
+            </list>
+          </list>
+          <!-- media -->
+          <p>${data.content.content_data_parsed}</p>
+          <if content.creator_main_url || content.creator_email>
                         <table width="100%" bgcolor="#FFFFFF">
                         <tr>
                            <td>