2 * put your module comment here
16 * This is the Generic MediaHandler. It stores the media data on
17 * the filesystem and keeps basic metadata (size, type...) in the
18 * DB. Usually only representation needs to be overridden.
19 * See the MediaHandlerAudio class to see an example of how one
22 * Most media handlers should override this class.
24 * In theory, it could be used to handle miscellaneous media that
25 * we don't have entered in the media_type table, (like RTF documents,
28 * Of course it implements the MirMedia interface.
30 * @see mir.media.MirMedia
31 * @author mh <heckmann@hbe.ca>
35 public class MediaHandlerGeneric implements MirMedia
38 private String imageHost = MirConfig.getProp("Producer.Image.Host");
39 private static String imageRoot = MirConfig.getProp("Producer.ImageRoot");
40 private Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+"log/media.log");
41 public boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt ) {
42 String ext = mediaTypeEnt.getValue("name");
43 String dir = MirConfig.getProp("Producer.Media.Path");
44 String mediaHost = MirConfig.getProp("Producer.Media.Host");
45 String mediaFname = ent.getId()+"."+ext;
46 String date = ent.getValue("date");
47 String datePath = StringUtil.webdbDate2path(date);
48 Integer size = new Integer(uploadedData.length);
49 //hack: make it a config option to use "dated" dirs
50 //we can't cause of stallman -mh
51 //if(FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData)) {
52 if(FileUtil.write(dir+"/"+mediaFname, uploadedData)) {
53 //were done with the data, dereference.
57 ent.setValueForProperty("is_produced", "1");
58 ent.setValueForProperty("icon_is_produced", "1");
59 //hack: make it a config option to use "dated" dirs
60 //we can't cause of stallman -mh
61 //ent.setValueForProperty("publish_path",datePath+"/"+mediaFname);
62 ent.setValueForProperty("publish_path", mediaFname);
63 ent.setValueForProperty("publish_server", mediaHost);
64 ent.setValueForProperty("size", size.toString());
66 } catch (StorageObjectException e) {
67 theLog.printError("StorageObjectException: "+e.toString());
71 theLog.printError("could not write FILE!");
78 //a class that will probably never get used..
79 private byte[] getFile (String fileName) {
80 long size = FileUtil.getSize(fileName);
81 if (size < 0) return null;
83 byte[] container = new byte[(int)size];
85 if(!FileUtil.read(fileName, container))
91 public byte[] get (Entity ent, Entity mediaTypeEnt) {
95 public byte[] getIcon (Entity ent) {
96 String name = "/path/to/some/generic/icon";
100 public String getStoragePath()
102 return MirConfig.getProp("Producer.Media.Path");
105 public String getIconStoragePath()
107 return MirConfig.getProp("Producer.Image.IconPath");
110 public String getPublishHost()
112 return MirConfig.getProp("Producer.Media.Host");
115 public String getTinyIcon()
117 return MirConfig.getProp("Producer.Icon.TinyText");
120 public String getBigIcon()
122 return MirConfig.getProp("Producer.Icon.BigText");
125 public String getIconAlt()
127 return "Generic media";
130 public String getURL(Entity ent, Entity mediaTypeEnt)
132 String title = ent.getValue("title")+
133 " - "+mediaTypeEnt.getValue("name")+" "+
134 ent.getValue("size")+" Bytes";
135 return StringUtil.createURLLinks(ent.getValue("publish_server")+"/"+
136 ent.getValue("publish_path"), title, imageRoot, getBigIcon());
139 public String getListView(Entity ent, Entity mediaTypeEnt)
141 //String title = ent.getValue("title")+
142 // " - "+mediaTypeEnt.getValue("name")+" "+
143 // ent.getValue("size")+" Bytes";
144 return StringUtil.createIMGLinks(imageHost+
145 getBigIcon(), null, null, null);
148 public boolean isVideo()
153 public boolean isAudio()
158 public boolean isImage()