X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Fmedia%2FMediaHandlerGeneric.java;h=a466a9880d58e40c7e2bce01d5f80c868534e95d;hb=8bfa50e64be577a93d0d160b8d710dcc97114627;hp=471f06c11204ae9fcbf6a38f8ca726bccdc45396;hpb=53a936ecab884cd854446b8a43656d2cecb6b9cc;p=mir.git diff --git a/source/mir/media/MediaHandlerGeneric.java b/source/mir/media/MediaHandlerGeneric.java index 471f06c1..a466a988 100755 --- a/source/mir/media/MediaHandlerGeneric.java +++ b/source/mir/media/MediaHandlerGeneric.java @@ -13,20 +13,34 @@ 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 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 ) { + 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"); @@ -34,41 +48,42 @@ public class MediaHandlerGeneric implements MirMedia 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)) { - 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.setValueForProperty("size", size.toString()); - ent.update(); - } catch (StorageObjectException e) { - theLog.printError("StorageObjectException: "+e.toString()); - return false; - } - } else { - theLog.printError("could not write FILE!"); - return false; + 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; } @@ -78,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() @@ -114,13 +128,26 @@ public class MediaHandlerGeneric implements MirMedia 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")+" "+ - ent.getValue("size")+" Bytes"; - return StringUtil.createURLLinks(ent.getValue("publish_server")+ + 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;