From: mh Date: Sat, 23 Mar 2002 22:14:57 +0000 (+0000) Subject: rework of media handling vis a vis storage and producing. making it more X-Git-Tag: prexmlproducerconfig~255 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=432f4c6d092da6434effc53ee863d14615b51322;p=mir.git rework of media handling vis a vis storage and producing. making it more consitent. --- diff --git a/dbscripts/create_pg.sql b/dbscripts/create_pg.sql index 997dfcd3..703176f2 100755 --- a/dbscripts/create_pg.sql +++ b/dbscripts/create_pg.sql @@ -439,7 +439,6 @@ CREATE TABLE "links_imcs" ( -- CREATE TABLE "audio" ( - "audio_data" oid, "kbits" smallint ) INHERITS ("uploaded_media"); @@ -451,7 +450,6 @@ INHERITS ("uploaded_media"); -- CREATE TABLE "video" ( - "video_data" oid ) INHERITS ("uploaded_media"); diff --git a/source/mir/media/MirMedia.java b/source/mir/media/MirMedia.java index 3597a1fc..0431e9b4 100755 --- a/source/mir/media/MirMedia.java +++ b/source/mir/media/MirMedia.java @@ -72,7 +72,11 @@ public interface MirMedia{ * @return boolean, success/fail * @see mir.entity.Entity */ - public abstract boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt ) throws MirMediaException; + public abstract boolean set (byte[] uploadedData, Entity ent, + Entity mediaTypeEnt ) throws MirMediaException; + + public abstract void produce (Entity ent, Entity mediaTypeEnt ) + throws MirMediaException; /** * Get's the media data from storage and returns it as a byte array @@ -84,8 +88,8 @@ public interface MirMedia{ * @return byte[] * @see mir.entity.Entity */ - public abstract byte[] get (Entity ent, Entity mediaTypeEnt) - throws MirMediaException; + public abstract byte[] get (Entity ent, Entity mediaTypeEnt) + throws MirMediaException; /** * Pretty much like get() above. But get's the specific Icon @@ -94,7 +98,7 @@ public interface MirMedia{ * @return byte[] * @see mir.entity.Entity */ - public abstract byte[] getIcon (Entity ent) throws MirMediaException; + public abstract byte[] getIcon (Entity ent) throws MirMediaException; /** * gets the final content representation for the media @@ -148,7 +152,7 @@ public interface MirMedia{ * @return String, the path. * @see mir.misc.MirConfig */ - public abstract String getIconStoragePath () throws MirMediaException; + public abstract String getIconStoragePath () throws MirMediaException; /** * Returns the base URL to that the media is accessible from @@ -161,7 +165,7 @@ public interface MirMedia{ * @return String, the base URL to the host. * @see mir.misc.MirConfig */ - public abstract String getPublishHost () throws MirMediaException; + public abstract String getPublishHost () throws MirMediaException; /** * Returns the file name of the Icon representing the media type. @@ -172,7 +176,7 @@ public interface MirMedia{ * @return String, the icon filename. * @see mir.misc.MirConfig */ - public abstract String getBigIcon (); + public abstract String getBigIcon (); /** * Returns the file name of the small Icon representing @@ -184,14 +188,14 @@ public interface MirMedia{ * @return String, the icon filename. * @see mir.misc.MirConfig */ - public abstract String getTinyIcon (); + public abstract String getTinyIcon (); /** * Returns the IMG SRC "ALT" text to be used * for the Icon representations * @return String, the ALT text. */ - public abstract String getIconAlt (); + public abstract String getIconAlt (); /** * your all smart enough to figure it out. @@ -203,13 +207,13 @@ public interface MirMedia{ * your all smart enough to figure it out. * @return boolean. */ - public abstract boolean isAudio (); + public abstract boolean isAudio (); /** * your all smart enough to figure it out. * @return boolean. */ - public abstract boolean isImage (); + public abstract boolean isImage (); } diff --git a/source/mircoders/media/MediaHandlerGeneric.java b/source/mircoders/media/MediaHandlerGeneric.java index 98bb183a..31eaff9b 100755 --- a/source/mircoders/media/MediaHandlerGeneric.java +++ b/source/mircoders/media/MediaHandlerGeneric.java @@ -6,6 +6,7 @@ package mircoders.media; import java.util.*; +import java.io.*; import mir.media.*; import mir.entity.*; @@ -35,31 +36,25 @@ import mir.storage.*; public class MediaHandlerGeneric implements MirMedia { - 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"); + 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 mediaFname = ent.getId()+"."+ext; String date = ent.getValue("date"); String datePath = StringUtil.webdbDate2path(date); Integer size = new Integer(uploadedData.length); try { - FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData); - //if(FileUtil.write(dir+"/"+mediaFname, uploadedData)) { + FileUtil.write(getStoragePath()+"/"+datePath+"/"+mediaFname, + uploadedData); //were done with the data, dereference. uploadedData=null; - 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) { @@ -70,6 +65,21 @@ public class MediaHandlerGeneric implements MirMedia 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!"); + } + + //a method that will probably never get used.. private byte[] getFile (String fileName) throws MirMediaException { diff --git a/source/mircoders/media/MediaHandlerImages.java b/source/mircoders/media/MediaHandlerImages.java index c24add82..d5db1a1f 100755 --- a/source/mircoders/media/MediaHandlerImages.java +++ b/source/mircoders/media/MediaHandlerImages.java @@ -32,113 +32,149 @@ import mircoders.entity.EntityImages; public class MediaHandlerImages implements MirMedia { - private Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+ + private Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+ "log/media.log"); public byte[] get(Entity ent, Entity mediaTypeEnt) - throws MirMediaException + throws MirMediaException { - byte[] image_data = null; - - try { - image_data = ((EntityImages)ent).getImage(); - } catch ( StorageObjectException e) { - theLog.printDebugInfo("MediaHandlerImages.get: "+e.toString()); - throw new MirMediaException(e.toString()); - } + byte[] image_data = null; + try { + image_data = ((EntityImages)ent).getImage(); + } catch ( StorageObjectException e) { + theLog.printDebugInfo("MediaHandlerImages.get: "+e.toString()); + throw new MirMediaException(e.toString()); + } - return image_data; - } + return image_data; + } public boolean set(byte[] uploadData, Entity ent, Entity mediaTypeEnt) - throws MirMediaException { - - try { - ((EntityImages)ent).setImage(uploadData); - } catch ( StorageObjectException e) { - theLog.printDebugInfo("MediaHandlerImages.set: "+e.toString()); - throw new MirMediaException(e.toString()); - } - //deref. -mh - uploadData=null; - - return true; - } - - public byte[] getIcon(Entity ent) throws MirMediaException - { - byte[] icon_data = null; - - try { - icon_data = ((EntityImages)ent).getIcon(); - } catch ( StorageObjectException e) { - theLog.printDebugInfo("MediaHandlerImages.getIcon: "+e.toString()); - throw new MirMediaException(e.toString()); - } + throws MirMediaException { - return icon_data; + try { + ((EntityImages)ent).setImage(uploadData); + } catch ( StorageObjectException e) { + theLog.printError("MediaHandlerImages.set: "+e.toString()); + throw new MirMediaException(e.toString()); } + //deref. -mh + uploadData=null; - public String getURL(Entity ent, Entity mediaTypeEnt) - { - String title = ent.getValue("title"); - return StringUtil.createIMGLinks(ent.getValue("publish_server")+ - ent.getValue("publish_path"), title, ent.getValue("img_height"), - ent.getValue("img_width")); - } - - public String getListView(Entity ent, Entity mediaTypeEnt) - { - //String title = ent.getValue("title"); - return StringUtil.createIMGLinks( MirConfig.getProp("Producer.ProductionHost")+ - ent.getValue("icon_path"), null, ent.getValue("icon_height"), - ent.getValue("icon_width")); - } + return true; + } - public String getStoragePath() - { - return MirConfig.getProp("Producer.Image.Path"); + public void produce(Entity ent, Entity mediaTypeEnt) throws MirMediaException + { + String date = ent.getValue("date"); + String datePath = StringUtil.webdbDate2path(date); + String ext = "."+mediaTypeEnt.getValue("name"); + String filepath = datePath+ent.getId()+ext; + String iconFilePath = MirConfig.getProp("Producer.StorageRoot") + +getIconStoragePath() + filepath; + String productionFilePath = getStoragePath() + "/" + filepath; + + + if (ent.getValue("icon_data")!= null && + ent.getValue("image_data")!= null) { + // make icon + try { + FileUtil.write(iconFilePath,((EntityImages)ent).getIcon()); + FileUtil.write(productionFilePath,((EntityImages)ent).getImage()); + ent.setValueForProperty("icon_path",getIconStoragePath()+filepath); + ent.setValueForProperty("publish_path",filepath); + //ent.setValueForProperty("publish_server", getPublishHost()); + //ent.setValueForProperty("icon_is_produced","1"); + //ent.setValueForProperty("is_produced","1"); + ent.update(); + } catch ( Exception e) { + String msg = "MediaHandlerImages.produce - Error: " + e.toString(); + theLog.printError(msg); + throw new MirMediaException(msg); + } + } else { + String msg="MediaHandlerImages.produce - missing image or icon OID for: "+ + ent.getId(); + theLog.printError(msg); + throw new MirMediaException(msg); } + } + - public String getIconStoragePath() - { - return MirConfig.getProp("Producer.Image.IconPath"); - } + public byte[] getIcon(Entity ent) throws MirMediaException + { + byte[] icon_data = null; - public String getPublishHost() - { - return MirConfig.getProp("Producer.Image.Host"); + try { + icon_data = ((EntityImages)ent).getIcon(); + } catch ( StorageObjectException e) { + theLog.printDebugInfo("MediaHandlerImages.getIcon: "+e.toString()); + throw new MirMediaException(e.toString()); } - public String getTinyIcon () - { - return MirConfig.getProp("Producer.Icon.TinyImage"); - } - - public String getBigIcon () - { - return MirConfig.getProp("Producer.Icon.BigImage"); - } - - public String getIconAlt () - { - return "Image"; - } - - public boolean isVideo () - { - return false; - } - - public boolean isAudio () - { - return false; - } - - public boolean isImage () - { - return true; - } + return icon_data; + } + + public String getURL(Entity ent, Entity mediaTypeEnt) + { + String title = ent.getValue("title"); + return StringUtil.createIMGLinks(ent.getValue("publish_server")+ + ent.getValue("publish_path"), title, ent.getValue("img_height"), + ent.getValue("img_width")); + } + + public String getListView(Entity ent, Entity mediaTypeEnt) + { + //String title = ent.getValue("title"); + return StringUtil.createIMGLinks( + MirConfig.getProp("Producer.ProductionHost")+ent.getValue("icon_path"), + null, ent.getValue("icon_height"), ent.getValue("icon_width")); + } + + public String getStoragePath() + { + return MirConfig.getProp("Producer.Image.Path"); + } + + public String getIconStoragePath() + { + return MirConfig.getProp("Producer.Image.IconPath"); + } + + public String getPublishHost() + { + return MirConfig.getProp("Producer.Image.Host"); + } + + public String getTinyIcon () + { + return MirConfig.getProp("Producer.Icon.TinyImage"); + } + + public String getBigIcon () + { + return MirConfig.getProp("Producer.Icon.BigImage"); + } + + public String getIconAlt () + { + return "Image"; + } + + public boolean isVideo () + { + return false; + } + + public boolean isAudio () + { + return false; + } + + public boolean isImage () + { + return true; + } } diff --git a/source/mircoders/media/MediaHandlerMp3.java b/source/mircoders/media/MediaHandlerMp3.java index 2ac0aa03..270bc642 100755 --- a/source/mircoders/media/MediaHandlerMp3.java +++ b/source/mircoders/media/MediaHandlerMp3.java @@ -43,48 +43,35 @@ import mir.storage.*; public class MediaHandlerMp3 extends MediaHandlerAudio implements MirMedia { - 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); - String baseName = ent.getId(); - String mediaFname = baseName+"."+ext; - String mp3Pointer = mediaHost+datePath+mediaFname; - String mpegURLFile = baseName+".m3u"; - String playlistFile = baseName+".pls"; - Integer size = new Integer(uploadedData.length); - try { - FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData); - //FileUtil.write(dir+"/"+mediaFname, uploadedData); - //were done with the data, dereference. - uploadedData=null; - - //write the "meta" files - //first the .m3u since it only contains one line - FileUtil.write(dir+"/"+datePath+"/"+mpegURLFile,mp3Pointer.getBytes()); - //now the .pls file - FileUtil.write(dir+"/"+datePath+"/"+playlistFile,mp3Pointer.getBytes()); - 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; + public void produce (Entity ent, Entity mediaTypeEnt ) + throws MirMediaException { + + // first check if the file exists + super.produce(ent, mediaTypeEnt); + + String baseName = ent.getId(); + String date = ent.getValue("date"); + String datePath = StringUtil.webdbDate2path(date); + String mp3Pointer = getPublishHost()+ent.getValue("publish_path"); + String mpegURLFile = baseName+".m3u"; + String playlistFile = baseName+".pls"; + + try { + //write the "meta" files + //first the .m3u since it only contains one line + FileUtil.write(getStoragePath()+"/"+datePath+"/"+mpegURLFile, + mp3Pointer.getBytes()); + //now the .pls file + FileUtil.write(getStoragePath()+"/"+datePath+"/"+playlistFile, + mp3Pointer.getBytes()); + } catch (Exception e) { + theLog.printError(e.toString()); + throw new MirMediaException(e.toString()); + } } - public String getURL(Entity ent, Entity mediaTypeEnt) - { + public String getURL(Entity ent, Entity mediaTypeEnt) + { String stringSize = ent.getValue("size"); if (stringSize == null) return null; diff --git a/source/mircoders/media/MediaHandlerRealAudio.java b/source/mircoders/media/MediaHandlerRealAudio.java index d8875ccd..3536981f 100755 --- a/source/mircoders/media/MediaHandlerRealAudio.java +++ b/source/mircoders/media/MediaHandlerRealAudio.java @@ -15,53 +15,55 @@ import mir.storage.*; /** - * Handles real audio. like MediaHandlerAudio, except it manages the ram file, too. + * Handles realAudio .it manages the ram file. + * + * 03.2002 - reworked Realmedia handling. -mh * * @see mir.media.MediaHandlerGeneric * @see mir.media.MirMedia - * @author john + * @author john , mh * @version 11.10.2001 */ -public class MediaHandlerRealAudio extends MediaHandlerAudio implements MirMedia +public class MediaHandlerRealAudio extends MediaHandlerAudio implements + MirMedia { + public void produce (Entity ent, Entity mediaTypeEnt ) + throws MirMediaException { + + // first see if the file exists + super.produce(ent, mediaTypeEnt); + + String baseName = ent.getId(); + String date = ent.getValue("date"); + String datePath = StringUtil.webdbDate2path(date); + String rtspDir = MirConfig.getProp("Producer.RealMedia.Path"); + String rtspMediaHost = MirConfig.getProp("Producer.RealMedia.Host"); + + String RealMediaPointer = rtspMediaHost+ent.getValue("publish_path"); + String RealMediaFile = datePath+ent.getId()+".ram"; + try { + //write an rm (ram?. -mh) file + FileUtil.write(super.getStoragePath()+"/"+RealMediaFile, + RealMediaPointer.getBytes()); + } catch (Exception e) { + theLog.printError(e.toString()); + throw new MirMediaException(e.toString()); + } + } + + public String getURL(Entity ent, Entity mediaTypeEnt) + { + int size = Integer.parseInt(ent.getValue("size"), 10)/1024; + String title = ent.getValue("title")+" - "+mediaTypeEnt.getValue("name")+ + " "+size+" KB"; + return StringUtil.createURLLinks(ent.getValue("publish_server")+"/"+ + ent.getValue("publish_path"), title, imageRoot, getBigIcon()); + } - public boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt ) - throws MirMediaException { - String ext = mediaTypeEnt.getValue("name"); - String dir = MirConfig.getProp("Producer.Media.Path"); - String rtspDir = MirConfig.getProp("Producer.RealMedia.Path"); - String mediaHost = MirConfig.getProp("Producer.Media.Host"); - String rtspMediaHost = MirConfig.getProp("Producer.RealMedia.Host"); - - String date = ent.getValue("date"); - String datePath = StringUtil.webdbDate2path(date); - String mediaFname = ent.getId()+"."+ext; - String realMediaPointer = rtspMediaHost+datePath+mediaFname; - String realMediaFile = ent.getId()+".ram"; - Integer size = new Integer(uploadedData.length); - try { - FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData); - //FileUtil.write(rtspDir+"/"+mediaFname, uploadedData); - //were done with the data, dereference. - uploadedData=null; - - //write a ram file - FileUtil.write(dir+"/"+datePath+"/"+realMediaFile,realMediaPointer.getBytes()); - ent.setValueForProperty("is_produced", "1"); - ent.setValueForProperty("icon_is_produced", "1"); - ent.setValueForProperty("publish_path",datePath+"/"+realMediaFile); - //ent.setValueForProperty("publish_path", realMediaFile); - 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; + public String getStoragePath() { + return MirConfig.getProp("Producer.RealMedia.Path"); } } diff --git a/source/mircoders/media/MediaHandlerRealVideo.java b/source/mircoders/media/MediaHandlerRealVideo.java index e960ec36..a6e4e8d2 100755 --- a/source/mircoders/media/MediaHandlerRealVideo.java +++ b/source/mircoders/media/MediaHandlerRealVideo.java @@ -15,103 +15,55 @@ import mir.storage.*; /** - * Handles real video. like MediaHandlerAudio, except it manages the ram file, too. + * Handles realVideo .it manages the ram file. + * + * 03.2002 - reworked Realmedia handling. -mh * * @see mir.media.MediaHandlerGeneric * @see mir.media.MirMedia - * @author john + * @author john , mh * @version 11.10.2001 */ -public class MediaHandlerRealVideo extends MediaHandlerGeneric implements MirMedia +public class MediaHandlerRealVideo extends MediaHandlerVideo 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 ) - throws MirMediaException { - - String ext = mediaTypeEnt.getValue("name"); - String dir = MirConfig.getProp("Producer.Media.Path"); - String rtspDir = MirConfig.getProp("Producer.RealMedia.Path"); - String mediaHost = MirConfig.getProp("Producer.Media.Host"); - String rtspMediaHost = MirConfig.getProp("Producer.RealMedia.Host"); - - String mediaFname = ent.getId()+"."+ext; - String RealMediaPointer = rtspMediaHost+mediaFname; - String RealMediaFile = ent.getId()+".ram"; - String date = ent.getValue("date"); - String datePath = StringUtil.webdbDate2path(date); - Integer size = new Integer(uploadedData.length); - try { - FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData); - //FileUtil.write(rtspDir+"/"+mediaFname, uploadedData); - //were done with the data, dereference. - uploadedData=null; - - //write an rm file - FileUtil.write(dir+"/"+RealMediaFile,RealMediaPointer.getBytes()); - ent.setValueForProperty("is_produced", "1"); - ent.setValueForProperty("icon_is_produced", "1"); - ent.setValueForProperty("publish_path",datePath+"/"+mediaFname); - //ent.setValueForProperty("publish_path", RealMediaFile); - 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; + public void produce (Entity ent, Entity mediaTypeEnt ) + throws MirMediaException { + + // first see if the file exists + super.produce(ent, mediaTypeEnt); + + String baseName = ent.getId(); + String date = ent.getValue("date"); + String datePath = StringUtil.webdbDate2path(date); + String rtspDir = MirConfig.getProp("Producer.RealMedia.Path"); + String rtspMediaHost = MirConfig.getProp("Producer.RealMedia.Host"); + + String RealMediaPointer = rtspMediaHost+ent.getValue("publish_path"); + String RealMediaFile = datePath+ent.getId()+".ram"; + try { + //write an rm (ram?. -mh) file + FileUtil.write(super.getStoragePath()+"/"+RealMediaFile, + RealMediaPointer.getBytes()); + } catch (Exception e) { + theLog.printError(e.toString()); + throw new MirMediaException(e.toString()); + } } - - - - - public String getPublishHost() - { - return MirConfig.getProp("Producer.Media.Host"); - } - - - public String getURL(Entity ent, Entity mediaTypeEnt) { int size = Integer.parseInt(ent.getValue("size"), 10)/1024; - String title = ent.getValue("title")+ - " - "+mediaTypeEnt.getValue("name")+" "+ - size+" KB"; + String title = ent.getValue("title")+" - "+mediaTypeEnt.getValue("name")+ + " "+size+" KB"; return StringUtil.createURLLinks(ent.getValue("publish_server")+"/"+ ent.getValue("publish_path"), title, imageRoot, getBigIcon()); } - - private static String tinyIcon = MirConfig.getProp("Producer.Icon.TinyVideo"); - private static String bigIcon = MirConfig.getProp("Producer.Icon.BigVideo"); - - public String getTinyIcon() - { - return tinyIcon; - } - - public String getBigIcon() - { - return bigIcon; - } - - public String getIconAlt() - { - return "Video"; - } - - public boolean isVideo() - { - return true; + public String getStoragePath() { + return MirConfig.getProp("Producer.RealMedia.Path"); } } diff --git a/source/mircoders/producer/Producer.java b/source/mircoders/producer/Producer.java index 2d4d638d..75b130a7 100755 --- a/source/mircoders/producer/Producer.java +++ b/source/mircoders/producer/Producer.java @@ -102,37 +102,6 @@ abstract public class Producer { } } - public boolean produceFile(String filename, byte[] in, PrintWriter htmlout, boolean icon) { - - boolean retVal = false; - - if (in!=null) { - try { - File f = null; - if(icon==false){ - f = new File(filename); - theLog.printDebugInfo("image: " + filename); - } else { - f = new File(producerStorageRoot + filename); - theLog.printDebugInfo("icon: " + filename); - } - File dir = new File(f.getParent()); - dir.mkdirs(); - - FileOutputStream outStream; - outStream = new FileOutputStream(f); - outStream.write(in); - outStream.close(); - retVal = true; - } catch(IOException exception) { - logHTML(htmlout, "Producer: File could not be written: " + filename); - } - } - return retVal; - } - - - // // filename methods diff --git a/source/mircoders/producer/ProducerAll.java b/source/mircoders/producer/ProducerAll.java index c07463fb..f98c0fa2 100755 --- a/source/mircoders/producer/ProducerAll.java +++ b/source/mircoders/producer/ProducerAll.java @@ -35,11 +35,28 @@ public class ProducerAll extends Producer{ long startTime = (new java.util.Date()).getTime(); try { - //new ProducerImages().handle(htmlout, user, force,sync); - new ProducerMedia().handle(htmlout, user, force,sync); + new ProducerImages().handle(htmlout, user, force,sync); } catch (Exception e) { logHTML(htmlout, "Producer.All ERROR:" - +" in Producer.Media continuing "+ e.toString()); + +" in ProducerImages continuing "+ e.toString()); + } + try { + new ProducerAudio().handle(htmlout, user, force,sync); + } catch (Exception e) { + logHTML(htmlout, "Producer.All ERROR:" + +" in ProducerAudio continuing "+ e.toString()); + } + try { + new ProducerVideo().handle(htmlout, user, force,sync); + } catch (Exception e) { + logHTML(htmlout, "Producer.All ERROR:" + +" in ProducerVideo continuing "+ e.toString()); + } + try { + new ProducerOther().handle(htmlout, user, force,sync); + } catch (Exception e) { + logHTML(htmlout, "Producer.All ERROR:" + +" in ProducerOther continuing "+ e.toString()); } try { new ProducerStartPage().handle(htmlout, user, force,sync); diff --git a/source/mircoders/producer/ProducerAudio.java b/source/mircoders/producer/ProducerAudio.java new file mode 100755 index 00000000..bf895719 --- /dev/null +++ b/source/mircoders/producer/ProducerAudio.java @@ -0,0 +1,24 @@ +package mircoders.producer; + +import java.io.*; +import java.lang.*; +import java.util.*; + +import freemarker.template.*; + +import mir.misc.*; +import mir.storage.*; +import mir.module.*; +import mir.entity.*; + +import mircoders.entity.*; +import mircoders.storage.*; + + +public class ProducerAudio extends ProducerMedia { + + protected Database getStorage() throws StorageObjectException { + return DatabaseAudio.getInstance(); + } + +} diff --git a/source/mircoders/producer/ProducerImages.java b/source/mircoders/producer/ProducerImages.java index 0e0f94a3..f75af224 100755 --- a/source/mircoders/producer/ProducerImages.java +++ b/source/mircoders/producer/ProducerImages.java @@ -12,126 +12,13 @@ import mir.module.*; import mir.entity.*; import mircoders.entity.*; -import mir.storage.*; - - - -public class ProducerImages extends Producer { - - public static void main(String argv[]){ - try { - new ProducerContent().handle(new PrintWriter(System.out), null, - false,false); - } catch(Exception e) { System.err.println(e.toString()); } - } - - public void handle(PrintWriter htmlout, EntityUsers user, boolean force, - boolean sync) - throws StorageObjectException, ModuleException { - handle(htmlout,user,force,sync,null); - } - - public void handle(PrintWriter htmlout, EntityUsers user, boolean force, - boolean sync, String id) - throws StorageObjectException, ModuleException - { - long sessionConnectTime = 0; - long startTime = (new java.util.Date()).getTime(); - String whereClause; - String iconFilename; - String imageFilename; - String productionPath; - EntityImages currentImage; - EntityList batchEntityList; - String orderBy = "date desc, webdb_lastchange desc"; - - int contentBatchsize = Integer.parseInt(MirConfig.getProp( - "Producer.Content.Batchsize")); - String imageHost = MirConfig.getProp("Producer.Image.Host"); - String imagePath = MirConfig.getProp("Producer.Image.Path"); - String iconPath = MirConfig.getProp("Producer.Image.IconPath"); - - // get batch of non-produced images, that are to be published - whereClause="is_published='1'"; - if (id!= null) - whereClause += " and id="+id; - if (force==false) whereClause += " and icon_is_produced='0'"; - - batchEntityList = imageModule.getByWhereClause(whereClause, orderBy, 0, - contentBatchsize); - theLog.printDebugInfo("whereclause: " + whereClause); - - - while (batchEntityList != null) { - for(int i=0;i")); - // make image - boolean imageProduced = produceFile(productionPath, - currentImage.getImage(), - htmlout, false); - logHTML(htmlout,"image: "+productionPath + - ((imageProduced==true)? - " succeded":" ")); - - // update image-data - if (iconProduced && imageProduced) { - currentImage.setValueForProperty("icon_is_produced", - "1"); - currentImage.update(); - } +import mircoders.storage.*; - } - } catch (Exception e) { - logHTML(htmlout, "Producer.Images ERROR with: image ID "+ - currentImage.getId() + - " failed!"); - } - }//end for - // if next batch get it... - if (batchEntityList.hasNextBatch()){ - batchEntityList = imageModule.getByWhereClause(whereClause, - orderBy, batchEntityList.getNextBatch(), - contentBatchsize); - } else { - batchEntityList=null; - } - } - // Finish - sessionConnectTime = new java.util.Date().getTime() - startTime; - logHTML(htmlout, "Producer.Images finished: " + sessionConnectTime + - " ms."); +public class ProducerImages extends ProducerMedia { - } + protected Database getStorage() throws StorageObjectException { + return DatabaseImages.getInstance(); + } } diff --git a/source/mircoders/producer/ProducerMedia.java b/source/mircoders/producer/ProducerMedia.java index 5d38acb8..0eb99dbb 100755 --- a/source/mircoders/producer/ProducerMedia.java +++ b/source/mircoders/producer/ProducerMedia.java @@ -4,7 +4,7 @@ import java.io.*; import java.lang.*; import java.util.*; -import freemarker.template.*; +//import freemarker.template.*; import mir.misc.*; import mir.storage.*; @@ -15,128 +15,79 @@ import mir.media.*; import mircoders.media.*; import mircoders.entity.*; import mircoders.storage.*; -import mir.storage.*; - - - -public class ProducerMedia extends Producer { - - public static void main(String argv[]){ - try { - new ProducerContent().handle(new PrintWriter(System.out), null, false,false); - } catch(Exception e) { System.err.println(e.toString()); } - } - - public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync) - throws StorageObjectException, ModuleException { - handle(htmlout,user,force,sync,null); - } - - public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync, String id) - throws StorageObjectException, ModuleException - { - long sessionConnectTime = 0; - long startTime = (new java.util.Date()).getTime(); - boolean iconProduced = false; - boolean mediaProduced = false; - String whereClause; - String mediaHost; - String id2=null; - String iconPath; - String mediaPath; - String iconFilename; - String mediaFilename; - String productionPath; - Entity currentMedia; - EntityList batchEntityList; - - int contentBatchsize = Integer.parseInt(MirConfig.getProp("Producer.Content.Batchsize")); - - // get batch of non-produced medias, that are to be published - whereClause="is_published='1'"; - if (id!= null) - whereClause += " and id="+id; - if (force==false) whereClause += " and is_produced='0'"; - - batchEntityList = uploadedMediaModule.getByWhereClause(whereClause, null, 0, contentBatchsize); - - while (batchEntityList != null) { - for(int i=0;i failed!")); - } - - } else { - iconProduced = true; - } - - //now produce the media content - - mediaHost = currentMediaHandler.getPublishHost(); - mediaPath = currentMediaHandler.getStoragePath(); - id2 = currentMedia.getId(); - mediaFilename = currentMedia.getId()+"."+currentMediaType.getValue("name"); - //hack: make this a config option. -mh - productionPath = mediaPath+datePath+"/"+ mediaFilename ; - //productionPath = mediaPath+"/"+mediaFilename ; - - //hack: see above. -mh. - currentMedia.setValueForProperty("publish_path",datePath+"/"+mediaFilename); - //currentMedia.setValueForProperty("publish_path",mediaFilename); - currentMedia.setValueForProperty("publish_server", mediaHost); - - theLog.printError("ABOUT OT FILE"+id2); - mediaProduced = produceFile(productionPath, currentMediaHandler.get(currentMedia, currentMediaType), htmlout, false); - logHTML(htmlout,"media: " + productionPath + ((mediaProduced==true)?" succeded":" failed!")); - - // update media-data - if (iconProduced && mediaProduced) { - currentMedia.setValueForProperty("icon_is_produced", "1"); - currentMedia.setValueForProperty("is_produced", "1"); - currentMedia.update(); - } - } catch (MirMediaException e) { - theLog.printError("media exception: "+id+e.toString()); - logHTML(htmlout, "problem with media id: " - +id+" failed!: " - +e.toString()); - } catch (Exception e) { - theLog.printError("failed in reflection: "+id+e.toString()); - logHTML(htmlout, "reflection problem in media id: " - +id+" failed!: " - +e.toString()); - } - } - - // if next batch get it... - if (batchEntityList.hasNextBatch()){ - batchEntityList = uploadedMediaModule.getByWhereClause(whereClause, null, batchEntityList.getNextBatch(),contentBatchsize); - } else { - batchEntityList=null; - } - } - // Finish - sessionConnectTime = new java.util.Date().getTime() - startTime; - logHTML(htmlout, "Producer.Media finished: " + sessionConnectTime + " ms."); - } +abstract public class ProducerMedia extends Producer { + + abstract Database getStorage() throws StorageObjectException; + + public void handle(PrintWriter htmlout, EntityUsers user, boolean force, + boolean sync) throws StorageObjectException, ModuleException { + handle(htmlout,user,force,sync,null); + } + + public void handle(PrintWriter htmlout,EntityUsers user,boolean force, + boolean sync, String id) throws StorageObjectException, ModuleException + { + long sessionConnectTime = 0; + long startTime = (new java.util.Date()).getTime(); + String whereClause; + Entity currentMedia; + MirMedia currentMediaHandler; + EntityList batchEntityList; + + int contentBatchsize = + Integer.parseInt(MirConfig.getProp("Producer.Content.Batchsize")); + + // get batch of non-produced medias, that are to be published + whereClause="is_published='1'"; + if (id!= null) { + whereClause += " and id="+id; + // optimization to avoid select count(*).. + contentBatchsize = -1; + } + if (force==false) whereClause += " and is_produced='0'"; + + batchEntityList = getStorage().selectByWhereClause(whereClause, + null, 0, contentBatchsize); + + while (batchEntityList != null) { + for(int i=0;i failed!: "+e.toString()); + } + } + + // if next batch get it... + if (batchEntityList.hasNextBatch()){ + batchEntityList = uploadedMediaModule.getByWhereClause(whereClause, + null, batchEntityList.getNextBatch(),contentBatchsize); + } else { + batchEntityList=null; + } + } + // Finish + sessionConnectTime = new java.util.Date().getTime() - startTime; + logHTML(htmlout, "Producer.Media finished: " + sessionConnectTime + " ms."); + } } diff --git a/source/mircoders/producer/ProducerOther.java b/source/mircoders/producer/ProducerOther.java new file mode 100755 index 00000000..f13065df --- /dev/null +++ b/source/mircoders/producer/ProducerOther.java @@ -0,0 +1,24 @@ +package mircoders.producer; + +import java.io.*; +import java.lang.*; +import java.util.*; + +import freemarker.template.*; + +import mir.misc.*; +import mir.storage.*; +import mir.module.*; +import mir.entity.*; + +import mircoders.entity.*; +import mircoders.storage.*; + + +public class ProducerOther extends ProducerMedia { + + protected Database getStorage() throws StorageObjectException { + return DatabaseOther.getInstance(); + } + +} diff --git a/source/mircoders/producer/ProducerVideo.java b/source/mircoders/producer/ProducerVideo.java new file mode 100755 index 00000000..4ead0e04 --- /dev/null +++ b/source/mircoders/producer/ProducerVideo.java @@ -0,0 +1,24 @@ +package mircoders.producer; + +import java.io.*; +import java.lang.*; +import java.util.*; + +import freemarker.template.*; + +import mir.misc.*; +import mir.storage.*; +import mir.module.*; +import mir.entity.*; + +import mircoders.entity.*; +import mircoders.storage.*; + + +public class ProducerVideo extends ProducerMedia { + + protected Database getStorage() throws StorageObjectException { + return DatabaseVideo.getInstance(); + } + +} diff --git a/source/mircoders/servlet/ServletModuleImages.java b/source/mircoders/servlet/ServletModuleImages.java index ed220773..8992cd0e 100755 --- a/source/mircoders/servlet/ServletModuleImages.java +++ b/source/mircoders/servlet/ServletModuleImages.java @@ -121,7 +121,7 @@ public class ServletModuleImages extends mir.servlet.ServletModule mpReq=null; if(mediaId!=null){ - new ProducerMedia().handle(null, null, false, false, mediaId); + new ProducerImages().handle(null, null, false, false, mediaId); } } catch (Exception e) { theLog.printError("setting uploaded_media failed: "+e.toString()); diff --git a/source/mircoders/servlet/ServletModuleOpenIndy.java b/source/mircoders/servlet/ServletModuleOpenIndy.java index 6e10b89c..55fa553e 100755 --- a/source/mircoders/servlet/ServletModuleOpenIndy.java +++ b/source/mircoders/servlet/ServletModuleOpenIndy.java @@ -329,6 +329,7 @@ public class ServletModuleOpenIndy extends ServletModule String mediaTypeId = null; MirMedia mediaHandler; Database mediaStorage; + ProducerMedia mediaProducer; //if we found an entry matching the //content-type int the table. @@ -356,7 +357,10 @@ public class ServletModuleOpenIndy extends ServletModule mediaHandler = MediaHelper.getHandler(mediaType); mediaStorage = MediaHelper.getStorage(mediaType, "mircoders.storage.Database"); - } catch (MirMediaException e) { + Class prodCls = Class.forName("mircoders.producer.Producer" + +mediaType.getValue("tablename")); + mediaProducer = (ProducerMedia)prodCls.newInstance(); + } catch (Exception e) { theLog.printError("getting media handler failed: "+e.toString()); contentModule.deleteById(cid); throw new ServletModuleException("getting media handler failed: " @@ -381,11 +385,12 @@ public class ServletModuleOpenIndy extends ServletModule //were done with mpReq at this point, dereference it. //as it contains mucho mem. -mh 01.10.2001 mpReq=null; - + //we got this far, associate the media to the article mediaEnt.setValueForProperty("is_published","1"); mediaEnt.update(); - new ProducerMedia().handle(null,null,false,false,mediaId); + //produce it + mediaProducer.handle(null, null, false, false, mediaId); DatabaseContentToMedia.getInstance().addMedia(cid,mediaId); } catch (Exception e) { theLog.printError("setting media failed: "+e.toString());