-public class MediaHandlerGeneric implements MirMedia
-{
- protected static String imageHost = MirConfig.getProp("Producer.Image.Host");
- protected static String imageRoot = MirConfig.getProp("Producer.ImageRoot");
- protected static 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 mediaFname = ent.getId()+"."+ext;
- String date = ent.getValue("date");
- String datePath = StringUtil.webdbDate2path(date);
- Integer size = new Integer(uploadedData.length);
- try {
- FileUtil.write(getStoragePath()+"/"+datePath+"/"+mediaFname,
- uploadedData);
- //were done with the data, dereference.
- uploadedData=null;
-
- ent.setValueForProperty("publish_path",datePath+"/"+mediaFname);
- ent.setValueForProperty("size", size.toString());
- ent.update();
- } catch (Exception e) {
- theLog.printError(e.toString());
- throw new MirMediaException(e.toString());
- }
-
- return true;
- }
-
- public void produce (Entity ent, Entity mediaTypeEnt )
- throws MirMediaException {
-
- //check first if the media file exist since produced
- //location is also the storage location
- String date = ent.getValue("date");
- String datePath = StringUtil.webdbDate2path(date);
- String relPath = datePath+ent.getId()+"."+mediaTypeEnt.getValue("name");
- String fname = getStoragePath()+relPath;
- if(! new File(fname).exists())
- throw new MirMediaException("error in MirMedia.produce(): "+relPath+
- "does not exist!");
- }
-