2 * put your module comment here
6 package mircoders.media;
11 import freemarker.template.SimpleList;
20 * This is the Generic MediaHandler. It stores the media data on
21 * the filesystem and keeps basic metadata (size, type...) in the
22 * DB. Usually only representation needs to be overridden.
23 * See the MediaHandlerAudio class to see an example of how one
26 * Most media handlers should override this class.
28 * In theory, it could be used to handle miscellaneous media that
29 * we don't have entered in the media_type table, (like RTF documents,
32 * Of course it implements the MirMedia interface.
34 * @see mir.media.MirMedia
35 * @author mh <heckmann@hbe.ca>
39 public class MediaHandlerGeneric implements MirMedia
41 protected String imageHost = MirConfig.getProp("Producer.Image.Host");
42 protected String imageRoot = MirConfig.getProp("Producer.ImageRoot");
43 protected Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+
45 public boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt )
46 throws MirMediaException {
48 String ext = mediaTypeEnt.getValue("name");
49 String mediaFname = ent.getId()+"."+ext;
50 String date = ent.getValue("date");
51 String datePath = StringUtil.webdbDate2path(date);
52 Integer size = new Integer(uploadedData.length);
54 FileUtil.write(getStoragePath()+"/"+datePath+"/"+mediaFname,
56 //were done with the data, dereference.
59 ent.setValueForProperty("publish_path",datePath+"/"+mediaFname);
60 ent.setValueForProperty("size", size.toString());
62 } catch (Exception e) {
63 theLog.printError(e.toString());
64 throw new MirMediaException(e.toString());
70 public void produce (Entity ent, Entity mediaTypeEnt )
71 throws MirMediaException {
73 //check first if the media file exist since produced
74 //location is also the storage location
75 String date = ent.getValue("date");
76 String datePath = StringUtil.webdbDate2path(date);
77 String relPath = datePath+ent.getId()+"."+mediaTypeEnt.getValue("name");
78 String fname = getStoragePath()+relPath;
79 if(! new File(fname).exists())
80 throw new MirMediaException("error in MirMedia.produce(): "+relPath+
85 //a method that will probably never get used..
86 private byte[] getFile (String fileName)
87 throws MirMediaException {
89 long size = FileUtil.getSize(fileName);
90 if (size < 0) return null;
92 byte[] container = new byte[(int)size];
95 FileUtil.read(fileName, container);
96 } catch (Exception e) {
97 theLog.printError(e.toString());
98 throw new MirMediaException(e.toString());
104 public byte[] get (Entity ent, Entity mediaTypeEnt) {
108 public byte[] getIcon (Entity ent) {
112 public String getStoragePath()
114 return MirConfig.getProp("Producer.Media.Path");
117 public String getIconStoragePath()
119 return MirConfig.getProp("Producer.Image.IconPath");
122 public String getPublishHost()
124 return MirConfig.getProp("Producer.Media.Host");
127 public String getTinyIcon()
129 return MirConfig.getProp("Producer.Icon.TinyText");
132 public String getBigIcon()
134 return MirConfig.getProp("Producer.Icon.BigText");
137 public String getIconAlt()
139 return "Generic media";
142 public SimpleList getURL(Entity ent, Entity mediaTypeEnt)
144 SimpleList theList = new SimpleList();
149 public boolean isVideo()
154 public boolean isAudio()
159 public boolean isImage()
164 public String getDescr()