X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=source%2Fmir%2Fmedia%2FMediaHandlerGeneric.java;h=a466a9880d58e40c7e2bce01d5f80c868534e95d;hb=8bfa50e64be577a93d0d160b8d710dcc97114627;hp=df11bf08cc9af7004d60779e30d587189126056f;hpb=986ca960959af906d6b639d13ae50353b6c74dc5;p=mir.git diff --git a/source/mir/media/MediaHandlerGeneric.java b/source/mir/media/MediaHandlerGeneric.java index df11bf08..a466a988 100755 --- a/source/mir/media/MediaHandlerGeneric.java +++ b/source/mir/media/MediaHandlerGeneric.java @@ -13,59 +13,77 @@ import mir.storage.*; /** - * Interfacedefinition für Datenbank-Adpatoren. Die Adaptoren legen - * jeweils das Verhalten und die Befehlsmächtigkeit der Datenbank - * fest. + * This is the Generic MediaHandler. It stores the media data on + * the filesystem and keeps basic metadata (size, type...) in the + * DB. Usually only representation needs to be overridden. + * See the MediaHandlerAudio class to see an example of how one + * could override it. + *

+ * Most media handlers should override this class. + *

+ * In theory, it could be used to handle miscellaneous media that + * we don't have entered in the media_type table, (like RTF documents, + * PS, PDF, etc..) + *

+ * Of course it implements the MirMedia interface. * - * @author + * @see mir.media.MirMedia + * @author mh * @version 24.09.2001 */ public class MediaHandlerGeneric implements MirMedia { - private Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+"log/media.log"); - public boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt ) { + 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"); + 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); - //hack: make it a config option to use "dated" dirs - //we can't cause of stallman -mh - //if(FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData)) { - if(FileUtil.write(dir+"/"+mediaFname, uploadedData)) { - try { - ent.setValueForProperty("is_produced", "1"); - ent.setValueForProperty("icon_is_produced", "1"); - //hack: make it a config option to use "dated" dirs - //we can't cause of stallman -mh - //ent.setValueForProperty("publish_path",datePath+"/"+mediaFname); - ent.setValueForProperty("publish_path", mediaFname); - ent.setValueForProperty("publish_server", mediaHost); - ent.update(); - } catch (StorageObjectException e) { - theLog.printError("StorageObjectException: "+e.toString()); - return false; - } - } else { - theLog.printError("could not write FILE!"); - return false; + Integer size = new Integer(uploadedData.length); + try { + FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData); + //if(FileUtil.write(dir+"/"+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()); + throw new MirMediaException(e.toString()); } return true; } //a class that will probably never get used.. - private byte[] getFile (String fileName) { + private byte[] getFile (String fileName) + throws MirMediaException { + long size = FileUtil.getSize(fileName); if (size < 0) return null; byte[] container = new byte[(int)size]; - if(!FileUtil.read(fileName, container)) - return null; + try { + FileUtil.read(fileName, container); + } catch (Exception e) { + theLog.printError(e.toString()); + throw new MirMediaException(e.toString()); + } return container; } @@ -75,8 +93,7 @@ public class MediaHandlerGeneric implements MirMedia } public byte[] getIcon (Entity ent) { - String name = "/path/to/some/generic/icon"; - return getFile(name); + return null; } public String getStoragePath() @@ -93,6 +110,59 @@ public class MediaHandlerGeneric implements MirMedia { return MirConfig.getProp("Producer.Media.Host"); } + + public String getTinyIcon() + { + 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 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()); + } + + public String getListView(Entity ent, Entity mediaTypeEnt) + { + //String title = ent.getValue("title")+ + // " - "+mediaTypeEnt.getValue("name")+" "+ + // ent.getValue("size")+" Bytes"; + return StringUtil.createIMGLinks(imageHost+ + getBigIcon(), null, null, null); + } + + public boolean isVideo() + { + return false; + } + + public boolean isAudio() + { + return false; + } + + public boolean isImage() + { + return false; + } + }