2 * put your module comment here
6 package mircoders.media;
17 * This is the Generic MediaHandler. It stores the media data on
18 * the filesystem and keeps basic metadata (size, type...) in the
19 * DB. Usually only representation needs to be overridden.
20 * See the MediaHandlerAudio class to see an example of how one
23 * Most media handlers should override this class.
25 * In theory, it could be used to handle miscellaneous media that
26 * we don't have entered in the media_type table, (like RTF documents,
29 * Of course it implements the MirMedia interface.
31 * @see mir.media.MirMedia
32 * @author mh <heckmann@hbe.ca>
36 public class MediaHandlerGeneric implements MirMedia
39 protected String imageHost = MirConfig.getProp("Producer.Image.Host");
40 protected String imageRoot = MirConfig.getProp("Producer.ImageRoot");
41 protected Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+"log/media.log");
42 public boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt )
43 throws MirMediaException {
45 String ext = mediaTypeEnt.getValue("name");
46 String dir = MirConfig.getProp("Producer.Media.Path");
47 String mediaHost = MirConfig.getProp("Producer.Media.Host");
48 String mediaFname = ent.getId()+"."+ext;
49 String date = ent.getValue("date");
50 String datePath = StringUtil.webdbDate2path(date);
51 Integer size = new Integer(uploadedData.length);
53 FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData);
54 //if(FileUtil.write(dir+"/"+mediaFname, uploadedData)) {
55 //were done with the data, dereference.
58 ent.setValueForProperty("is_produced", "1");
59 ent.setValueForProperty("icon_is_produced", "1");
60 ent.setValueForProperty("publish_path",datePath+"/"+mediaFname);
61 //ent.setValueForProperty("publish_path", mediaFname);
62 ent.setValueForProperty("publish_server", mediaHost);
63 ent.setValueForProperty("size", size.toString());
65 } catch (Exception e) {
66 theLog.printError(e.toString());
67 throw new MirMediaException(e.toString());
73 //a method that will probably never get used..
74 private byte[] getFile (String fileName)
75 throws MirMediaException {
77 long size = FileUtil.getSize(fileName);
78 if (size < 0) return null;
80 byte[] container = new byte[(int)size];
83 FileUtil.read(fileName, container);
84 } catch (Exception e) {
85 theLog.printError(e.toString());
86 throw new MirMediaException(e.toString());
92 public byte[] get (Entity ent, Entity mediaTypeEnt) {
96 public byte[] getIcon (Entity ent) {
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 stringSize = ent.getValue("size");
133 if (stringSize == null)
135 int size = Integer.parseInt(stringSize, 10)/1024;
136 String title = ent.getValue("title")+
137 " - "+mediaTypeEnt.getValue("name")+" "+
139 return StringUtil.createURLLinks(ent.getValue("publish_server")+"/"+
140 ent.getValue("publish_path"), title, imageRoot, getBigIcon());
143 public String getListView(Entity ent, Entity mediaTypeEnt)
145 //String title = ent.getValue("title")+
146 // " - "+mediaTypeEnt.getValue("name")+" "+
147 // ent.getValue("size")+" Bytes";
148 return StringUtil.createIMGLinks(imageHost+
149 getBigIcon(), null, null, null);
152 public boolean isVideo()
157 public boolean isAudio()
162 public boolean isImage()