merge changes from MIR_1_0 branch that add humanreadable size output for media files
authormh <mh>
Thu, 28 Nov 2002 07:28:24 +0000 (07:28 +0000)
committermh <mh>
Thu, 28 Nov 2002 07:28:24 +0000 (07:28 +0000)
24 files changed:
bundles/admin_de.properties
bundles/admin_en.properties
bundles/admin_es.properties
bundles/admin_gn.properties
bundles/admin_qu.properties
etc/producer/article.template
source/mir/misc/NumberUtils.java [new file with mode: 0755]
source/mircoders/entity/EntityUploadedMedia.java
source/mircoders/media/MediaHandlerAudio.java
source/mircoders/media/MediaHandlerImages.java
source/mircoders/media/MediaHandlerImagesPng.java
source/mircoders/media/MediaHandlerMp3.java
source/mircoders/media/MediaHandlerRealAudio.java
source/mircoders/media/MediaHandlerRealVideo.java
source/mircoders/media/MediaHandlerVideo.java
source/mircoders/media/MediaRequest.java
templates/admin/audio.template
templates/admin/audiolist.template
templates/admin/image.template
templates/admin/imagelist.template
templates/admin/media.template
templates/admin/medialist.template
templates/admin/video.template
templates/admin/videolist.template

index 85645b9..54b39b1 100755 (executable)
@@ -1,6 +1,6 @@
 ########## admin ##########
 # language: deutsch / german
-# $Id: admin_de.properties,v 1.15 2002/10/08 14:03:29 bruno Exp $
+# $Id: admin_de.properties,v 1.16 2002/11/28 07:28:24 mh Exp $
 
 # general
 yes=ja
@@ -40,6 +40,7 @@ media.rights=Copyright
 media.type=Typ
 media.mediafolder=Mediafolder
 media.title=Titel
+media.size=Grösser
 media.description=Beschreibung
 media.date=Datum/Zusatz
 media.location=Ort
index 955f094..61fcafb 100755 (executable)
@@ -1,6 +1,6 @@
 ########## admin ##########
 # language: english
-# $Id: admin_en.properties,v 1.23 2002/11/20 17:47:39 zapata Exp $
+# $Id: admin_en.properties,v 1.24 2002/11/28 07:28:24 mh Exp $
 
 # general
 yes=yes
@@ -44,6 +44,7 @@ media.rights=copyright status
 media.type=type
 media.mediafolder=Media folder
 media.title=title
+media.size=size
 media.description=description
 media.date=date
 media.location=location
index e1f4f4a..14ff567 100755 (executable)
@@ -1,6 +1,6 @@
 ########## admin ##########
 # language: espanol / spanish
-# $Id: admin_es.properties,v 1.7 2002/11/20 17:47:39 zapata Exp $
+# $Id: admin_es.properties,v 1.8 2002/11/28 07:28:24 mh Exp $
 
 # general
 yes=sí
@@ -38,6 +38,7 @@ media.rights=Copyright
 media.type=Tipo
 media.mediafolder=Carpeta de recursos mediáticos
 media.title=Título
+media.size=Tamaño
 media.description=Descripción
 media.date=Fecha
 media.location=Lugar de origen
index 901849b..26b36f3 100755 (executable)
@@ -33,6 +33,7 @@ media.published=publicado
 media.format=Formato
 media.rights=Copyright
 media.type=Tipo
+media.size=Tamaño
 media.mediafolder=Carpeta de recursos mediáticos
 media.title=Título
 media.description=Descripción
index 6221170..fb3a9d6 100755 (executable)
@@ -35,6 +35,7 @@ media.rights=Copyright
 media.type=Tipo
 media.mediafolder=Carpeta de recursos mediáticos
 media.title=Título
+media.size=Tamaño
 media.description=Descripción
 media.date=Fecha
 media.location=Lugar de origen
index 96112eb..92a41a6 100755 (executable)
@@ -76,7 +76,7 @@
                                        <list article.to_media_audio as media>
                                        <p>
                                        <a href="${media["publish_server"]}${media["publish_path"]}">
-                                       ${media["title"]} - ${media["descr"]}
+                                       ${media["title"]} - ${media["descr"]} ${media["size"]}
                                        </a>
                                        </p>
                                        </list>
                                        <p>
                                        <img src="../../../img/${media["big_icon"]}" border="0" alt="">
                                        <a href="${media["publish_server"]}${media["publish_path"]}">
-                                       ${media["title"]} - ${media["descr"]}</a>
+                                       ${media["title"]} - ${media["descr"]} ${media["size"]}</a>
                                        </p>
                                        </list>
                                        <list article.to_media_other as media>
                                        <p>
                                        <img src="../../../img/${media["big_icon"]}" border="0" alt="">
                                        <a href="${media["publish_server"]}${media["publish_path"]}">
-                                       ${media["title"]} - ${media["descr"]}</a>
+                                       ${media["title"]} - ${media["descr"]} ${media["size"]}</a>
                                        </p>
                                        </list>
                                        
diff --git a/source/mir/misc/NumberUtils.java b/source/mir/misc/NumberUtils.java
new file mode 100755 (executable)
index 0000000..0d83684
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2001, 2002  The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mir is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with the com.oreilly.servlet library, any library
+ * licensed under the Apache Software License, The Sun (tm) Java Advanced
+ * Imaging library (JAI), The Sun JIMI library (or with modified versions of
+ * the above that use the same license as the above), and distribute linked
+ * combinations including the two.  You must obey the GNU General Public
+ * License in all respects for all of the code used other than the above
+ * mentioned libraries.  If you modify this file, you may extend this exception
+ * to your version of the file, but you are not obligated to do so.  If you do
+ * not wish to do so, delete this exception statement from your version.
+ */
+
+package  mir.misc;
+
+import freemarker.template.*;
+
+import java.text.NumberFormat;
+import java.util.List; 
+
+/**
+ * Help methods for number handling.
+ *
+ * @version $Id: NumberUtils.java,v 1.2 2002/11/28 07:28:24 mh Exp $
+ * @author mh, Mir-coders group
+ *
+ */
+
+public final class NumberUtils {
+
+  /* 
+   * Uses a suffix indicating multiples of 1024 (K), 
+   * 1024*1024 (M), and 1024*1024*1024 (G).  For example, 
+   * 8500 would be converted to 8.3K, 133456345 to 
+   * 127M, 56990456345 to 53G, and so on.  Numbers 
+   * smaller than 1024 aren't modified.
+   *
+   * @param bytes The number of bytes.
+   * @return A text representation of the number of bytes,
+   *     abbreviated for larger quantities.
+   */
+  public static String humanReadableSize(double bytes)
+  {
+    String suffix;
+      
+    if( bytes >= 1024 * 1024 * 1024 )
+    {
+      bytes /= (1024 * 1024 * 1024);
+      suffix = "G";
+    }
+    else if( bytes >= 1024 * 1024 )
+    {
+      bytes /= (1024 * 1024);
+      suffix = "M";
+    }
+    else if( bytes >= 1024 )
+    {
+      bytes /= 1024;
+      suffix = "K";
+    }
+    else
+    {
+      suffix = "";
+    }
+    int frac = (bytes >= 10  ||  bytes == 0)  ?  0  :  1;
+    NumberFormat nf = NumberFormat.getInstance();
+    nf.setMinimumFractionDigits(frac);
+    nf.setMaximumFractionDigits(frac);
+    System.out.println(nf.getMinimumIntegerDigits());
+    nf.setGroupingUsed(false);
+    return nf.format(bytes) + suffix;
+  }
+
+}
+
index caf2ab6..619f5ef 100755 (executable)
@@ -40,6 +40,7 @@ import mir.media.MediaHelper;
 import mir.media.MirMedia;
 import mir.storage.StorageObject;
 import mir.storage.StorageObjectException;
+import mir.misc.NumberUtils;
 import mircoders.storage.DatabaseUploadedMedia;
 
 import java.util.HashMap;
@@ -48,7 +49,7 @@ import java.util.HashMap;
  * Diese Klasse enthält die Daten eines MetaObjekts
  *
  * @author mh, mir-coders group
- * @version $Id: EntityUploadedMedia.java,v 1.12 2002/11/27 08:57:31 mh Exp $
+ * @version $Id: EntityUploadedMedia.java,v 1.13 2002/11/28 07:28:24 mh Exp $
  */
 
 
@@ -101,6 +102,11 @@ public class EntityUploadedMedia extends Entity {
         returnValue = getMediaTypeString();
       else if (key.equals("mimetype"))
         returnValue = getMimeType();
+      else if (key.equals("size")) {
+        String size = super.getValue(key);
+        if (size != null)
+          returnValue = NumberUtils.humanReadableSize(Double.parseDouble(size));
+      }
       else
         returnValue = super.getValue(key);
     }
index 5d7e244..6717d2e 100755 (executable)
@@ -45,8 +45,8 @@ import mir.storage.*;
  *
  * @see mir.media.MediaHandlerGeneric
  * @see mir.media.MirMedia
- * @author mh <heckmann@hbe.ca>
- * @version 24.09.2001
+ * @author mh <mh@nadir.org>
+ * @version $Id: MediaHandlerAudio.java,v 1.6 2002/11/28 07:28:24 mh Exp $
  */
 
 public class MediaHandlerAudio extends MediaHandlerGeneric implements MirMedia
index 974f097..53a9a8c 100755 (executable)
@@ -59,7 +59,7 @@ import mircoders.entity.EntityImages;
  *
  * @see mir.media.MirMedia
  * @author mh
- * @version $Id: MediaHandlerImages.java,v 1.12 2002/11/27 08:57:32 mh Exp $
+ * @version $Id: MediaHandlerImages.java,v 1.13 2002/11/28 07:28:24 mh Exp $
  */
 
 
index b2c87c1..631b47b 100755 (executable)
@@ -45,7 +45,7 @@ import mir.entity.Entity;
  * @see mir.media.MirMedia
  * @see mircoders.media.MediaHandlerImages
  * @author mh ,mir-coders
- * @version $Id: MediaHandlerImagesPng.java,v 1.3 2002/11/27 08:57:32 mh Exp $
+ * @version $Id: MediaHandlerImagesPng.java,v 1.4 2002/11/28 07:28:24 mh Exp $
  */
 
 
index 489f6bc..1144207 100755 (executable)
@@ -66,8 +66,8 @@ import mir.storage.*;
  * If the web server is not apache, then your on your own.
  * 
  * @see mir.media.MirMedia
- * @author mh <heckmann@hbe.ca>
- * @version 01.12.2001
+ * @author mh <mh@nadir.org>
+ * @version $Id: MediaHandlerMp3.java,v 1.9 2002/11/28 07:28:24 mh Exp $
  */
 
 public class MediaHandlerMp3 extends MediaHandlerAudio implements MirMedia
@@ -131,7 +131,7 @@ public class MediaHandlerMp3 extends MediaHandlerAudio implements MirMedia
 
   public String getDescr(Entity mediaType)
   {
-    return "Mp3 audio";
+    return "mp3";
   }
 
 }
index bab016b..23416a8 100755 (executable)
@@ -52,7 +52,7 @@ import mir.storage.*;
  * @see mir.media.MediaHandlerGeneric
  * @see mir.media.MirMedia
  * @author john <john@manifestor.org>, mh <heckmann@hbe.ca>
- * @version 11.10.2001
+ * @version $Id: MediaHandlerRealAudio.java,v 1.13 2002/11/28 07:28:24 mh Exp $
  */
 
 
@@ -113,7 +113,7 @@ public class MediaHandlerRealAudio extends MediaHandlerAudio implements
 
   public String getDescr(Entity mediaType)
   {
-    return "RealMedia Audio";
+    return "RealMedia";
   }
 
   public String getPublishHost()
index c268079..c93d333 100755 (executable)
@@ -51,8 +51,8 @@ import mir.storage.*;
  *
  * @see mir.media.MediaHandlerGeneric
  * @see mir.media.MirMedia
- * @author john <john@manifestor.org>, mh <heckmann@hbe.ca>
- * @version $Id: MediaHandlerRealVideo.java,v 1.12 2002/11/27 08:57:32 mh Exp $
+ * @author john <john@manifestor.org>, mh <mh@nadir.org>
+ * @version $Id: MediaHandlerRealVideo.java,v 1.13 2002/11/28 07:28:24 mh Exp $
  */
 
 
@@ -113,7 +113,7 @@ public class MediaHandlerRealVideo extends MediaHandlerVideo implements
 
   public String getDescr(Entity mediaType)
   {
-    return "RealMedia Video";
+    return "RealMedia";
   }
 
   public String getPublishHost()
index 08144e4..4c1ca4a 100755 (executable)
@@ -47,7 +47,7 @@ import mir.storage.*;
  * @see mir.media.MediaHandlerGeneric
  * @see mir.media.MirMedia
  * @author john <john@manifestor.org>
- * @version 11.10.2001
+ * @version $Id: MediaHandlerVideo.java,v 1.5 2002/11/28 07:28:24 mh Exp $
  */
 
 public class MediaHandlerVideo extends MediaHandlerGeneric implements MirMedia
index b559515..ce6fd2e 100755 (executable)
@@ -55,7 +55,7 @@ import mir.media.*;
  *    appropriate media objects are set.
  *
  * @author mh
- * @version $Id: MediaRequest.java,v 1.6 2002/11/27 08:06:54 mh Exp $
+ * @version $Id: MediaRequest.java,v 1.7 2002/11/28 07:28:24 mh Exp $
  *
  */
 
index 6f4a526..e02ec79 100755 (executable)
@@ -34,6 +34,7 @@ function openWin(url) {
         <if data.webdb_lastchange>/ ${lang("media.changed")} ${data.webdb_lastchange}</if><br>
                <if data.is_published=="1">${lang("media.published")}: ${data.publish_date} / ${data.publish_server}${data.publish_path}<br></if>
                ${lang("media.format")}: ${data.mimetype} / ${data.descr}<br>
+               ${lang("media.size")}: ${data.size}<br>
                ${lang("media.rights")}: <b>${data.rightsHashdata[to_rights]["name"]}</b><br>
        </td>
        </tr>
index da922f5..22e21f6 100755 (executable)
@@ -61,6 +61,8 @@
        <td><span class="witesmall">
        <b>${lang("media.title")}</b></span></td>
     <td><span class="witesmall">
+       <b>${lang("media.size")}</b></span></td>
+    <td><span class="witesmall">
        <b>${lang("media.mediafolder")}</b></span></td>
     <td><span class="witesmall">
        <b>${lang("media.creator")}</b></span></td>
@@ -73,6 +75,7 @@
          <img src="${config.docRoot}/img/${entry.big_icon}" border=0></a></span></td>
   <td>${entry.title}&nbsp;
          <if entry.description><br>${entry.description}</if></td>
+  <td>${entry.size}&nbsp;</td>
   <td>${data.mediafolderHashdata[entry.to_media_folder]["name"]}&nbsp;</td>
   <td>${entry.creator}&nbsp;</td>
   <td><span class="text">&nbsp;
index ebe936f..97cf45d 100755 (executable)
@@ -49,6 +49,7 @@ function openWin(url) {
                ${lang("media.created")}: ${data.webdb_create} <if data.webdb_lastchange>/ ${lang("media.changed")} ${data.webdb_lastchange}</if><br>
                <if data.is_published=="1">${lang("media.published")}: ${data.publish_date} / ${data.publish_server}${data.publish_path}<br></if>
                ${lang("media.format")}: ${data.img_width}x${data.img_height} / ${data.imgformatHashdata[to_img_format]["name"]} / ${data.imglayoutHashdata[to_img_layout]["name"]} /  ${data.imgcolorHashdata[to_img_color]["name"]}<br>
+               ${lang("media.size")}: ${data.size}<br>
                ${lang("media.rights")}: <b>${data.rightsHashdata[to_rights]["name"]}</b><br>
                ${lang("media.type")}: <b>${data.imgtypeHashdata[to_img_type]["name"]}</b><br>
       </span>
index 90ba7f6..aeb8e1d 100755 (executable)
@@ -61,6 +61,8 @@
        <td><span class="witesmall">
        <b>${lang("media.title")}</b></span></td>
     <td><span class="witesmall">
+       <b>${lang("media.size")}</b></span></td>
+    <td><span class="witesmall">
        <b>${lang("media.mediafolder")}</b></span></td>
     <td><span class="witesmall">
        <b>${lang("media.creator")}</b></span></td>
@@ -75,6 +77,7 @@
        </if>
   <td>${entry.title}&nbsp;
          <if entry.description><br>${entry.description}</if></td>
+  <td>${entry.size}&nbsp;</td>
   <td>${data.mediafolderHashdata[entry.to_media_folder]["name"]}&nbsp;</td>
   <td>${entry.creator}&nbsp;</td>
   <td><span class="text">&nbsp;
index d08b547..a5ca0ea 100755 (executable)
@@ -34,6 +34,7 @@ function openWin(url) {
         <if data.webdb_lastchange>/ ${lang("media.changed")} ${data.webdb_lastchange}</if><br>
                <if data.is_published=="1">${lang("media.published")}: ${data.publish_date} / ${data.publish_server}${data.publish_path}<br></if>
                ${lang("media.format")}: ${data.mimetype} / ${data.descr}<br>
+               ${lang("media.size")}: ${data.size}<br>
                ${lang("media.rights")}: <b>${data.rightsHashdata[to_rights]["name"]}</b><br>
        </td>
        </tr>
index 75ec340..6c04bce 100755 (executable)
@@ -61,6 +61,8 @@
        <td><span class="witesmall">
        <b>${lang("media.title")}</b></span></td>
     <td><span class="witesmall">
+       <b>${lang("media.size")}</b></span></td>
+    <td><span class="witesmall">
        <b>${lang("media.mediafolder")}</b></span></td>
     <td><span class="witesmall">
        <b>${lang("media.creator")}</b></span></td>
@@ -73,6 +75,7 @@
          <img src="${config.docRoot}/img/${entry.big_icon}" border=0></a></span></td>
   <td>${entry.title}&nbsp;
          <if entry.description><br>${entry.description}</if></td>
+  <td>${entry.size}&nbsp;</td>
   <td>${data.mediafolderHashdata[entry.to_media_folder]["name"]}&nbsp;</td>
   <td>${entry.creator}&nbsp;</td>
   <td><span class="text">&nbsp;
index 62975a1..c613390 100755 (executable)
@@ -34,6 +34,7 @@ function openWin(url) {
         <if data.webdb_lastchange>/ ${lang("media.changed")} ${data.webdb_lastchange}</if><br>
                <if data.is_published=="1">${lang("media.published")}: ${data.publish_date} / ${data.publish_server}${data.publish_path}<br></if>
                ${lang("media.format")}: ${data.mimetype} / ${data.descr}<br>
+               ${lang("media.size")}: ${data.size}<br>
                ${lang("media.rights")}: <b>${data.rightsHashdata[to_rights]["name"]}</b><br>
        </td>
        </tr>
index b9c6369..590a733 100755 (executable)
@@ -61,6 +61,8 @@
        <td><span class="witesmall">
        <b>${lang("media.title")}</b></span></td>
     <td><span class="witesmall">
+       <b>${lang("media.size")}</b></span></td>
+    <td><span class="witesmall">
        <b>${lang("media.mediafolder")}</b></span></td>
     <td><span class="witesmall">
        <b>${lang("media.creator")}</b></span></td>
@@ -73,6 +75,7 @@
          <img src="${config.docRoot}/img/${entry.big_icon}" border=1></a></span></td>
   <td>${entry.title}&nbsp;
          <if entry.description><br>${entry.description}</if></td>
+  <td>${entry.size}&nbsp;</td>
   <td>${data.mediafolderHashdata[entry.to_media_folder]["name"]}&nbsp;</td>
   <td>${entry.creator}&nbsp;</td>
   <td><span class="text">&nbsp;