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 protected String imageHost = MirConfig.getProp("Producer.Image.Host");
39 protected String imageRoot = MirConfig.getProp("Producer.ImageRoot");
40 protected Logfile theLog = Logfile.getInstance(this.getClass().getName());
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 if(FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData)) {
50 //if(FileUtil.write(dir+"/"+mediaFname, uploadedData)) {
51 //were done with the data, dereference.
55 ent.setValueForProperty("is_produced", "1");
56 ent.setValueForProperty("icon_is_produced", "1");
57 ent.setValueForProperty("publish_path",datePath+"/"+mediaFname);
58 //ent.setValueForProperty("publish_path", mediaFname);
59 ent.setValueForProperty("publish_server", mediaHost);
60 ent.setValueForProperty("size", size.toString());
62 } catch (StorageObjectException e) {
63 theLog.printError("StorageObjectException: "+e.toString());
67 theLog.printError("could not write FILE!");
74 //a class that will probably never get used..
75 private byte[] getFile (String fileName) {
76 long size = FileUtil.getSize(fileName);
77 if (size < 0) return null;
79 byte[] container = new byte[(int)size];
81 if(!FileUtil.read(fileName, container))
87 public byte[] get (Entity ent, Entity mediaTypeEnt) {
91 public byte[] getIcon (Entity ent) {
92 String name = "/path/to/some/generic/icon";
96 public String getStoragePath()
98 return MirConfig.getProp("Producer.Media.Path");
101 public String getIconStoragePath()
103 return MirConfig.getProp("Producer.Image.IconPath");
106 public String getPublishHost()
108 return MirConfig.getProp("Producer.Media.Host");
111 public String getTinyIcon()
113 return MirConfig.getProp("Producer.Icon.TinyText");
116 public String getBigIcon()
118 return MirConfig.getProp("Producer.Icon.BigText");
121 public String getIconAlt()
123 return "Generic media";
126 public String getURL(Entity ent, Entity mediaTypeEnt)
128 String stringSize = ent.getValue("size");
129 if (stringSize == null)
131 int size = Integer.parseInt(stringSize, 10)/1024;
132 String title = ent.getValue("title")+
133 " - "+mediaTypeEnt.getValue("name")+" "+
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()