public class MediaHandlerGeneric implements MirMedia
{
- private String imageHost = MirConfig.getProp("Producer.Image.Host");
- private static String imageRoot = MirConfig.getProp("Producer.ImageRoot");
- private Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+"log/media.log");
- public boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt ) {
+ protected String imageHost = MirConfig.getProp("Producer.Image.Host");
+ protected String imageRoot = MirConfig.getProp("Producer.ImageRoot");
+ protected 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 dir = MirConfig.getProp("Producer.Media.Path");
String mediaHost = MirConfig.getProp("Producer.Media.Host");
String date = ent.getValue("date");
String datePath = StringUtil.webdbDate2path(date);
Integer size = new Integer(uploadedData.length);
- if(FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData)) {
- //if(FileUtil.write(dir+"/"+mediaFname, uploadedData)) {
+ try {
+ FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData);
+ //if(FileUtil.write(dir+"/"+mediaFname, uploadedData)) {
//were done with the data, dereference.
uploadedData=null;
- try {
- ent.setValueForProperty("is_produced", "1");
- ent.setValueForProperty("icon_is_produced", "1");
- ent.setValueForProperty("publish_path",datePath+"/"+mediaFname);
- //ent.setValueForProperty("publish_path", mediaFname);
- ent.setValueForProperty("publish_server", mediaHost);
- ent.setValueForProperty("size", size.toString());
- ent.update();
- } catch (StorageObjectException e) {
- theLog.printError("StorageObjectException: "+e.toString());
- return false;
- }
- } else {
- theLog.printError("could not write FILE!");
- return false;
+ ent.setValueForProperty("is_produced", "1");
+ ent.setValueForProperty("icon_is_produced", "1");
+ ent.setValueForProperty("publish_path",datePath+"/"+mediaFname);
+ //ent.setValueForProperty("publish_path", mediaFname);
+ ent.setValueForProperty("publish_server", mediaHost);
+ ent.setValueForProperty("size", size.toString());
+ ent.update();
+ } catch (Exception e) {
+ theLog.printError(e.toString());
+ throw new MirMediaException(e.toString());
}
return true;
}
//a class that will probably never get used..
- private byte[] getFile (String fileName) {
+ private byte[] getFile (String fileName)
+ throws MirMediaException {
+
long size = FileUtil.getSize(fileName);
if (size < 0) return null;
byte[] container = new byte[(int)size];
- if(!FileUtil.read(fileName, container))
- return null;
+ try {
+ FileUtil.read(fileName, container);
+ } catch (Exception e) {
+ theLog.printError(e.toString());
+ throw new MirMediaException(e.toString());
+ }
return container;
}
}
public byte[] getIcon (Entity ent) {
- String name = "/path/to/some/generic/icon";
- return getFile(name);
+ return null;
}
public String getStoragePath()
public String getURL(Entity ent, Entity mediaTypeEnt)
{
- int size = Integer.parseInt(ent.getValue("size"), 10)/1024;
+ String stringSize = ent.getValue("size");
+ if (stringSize == null)
+ return null;
+ int size = Integer.parseInt(stringSize, 10)/1024;
String title = ent.getValue("title")+
" - "+mediaTypeEnt.getValue("name")+" "+
size+" KB";