another media handling merge.
authormh <mh>
Fri, 28 Sep 2001 08:58:36 +0000 (08:58 +0000)
committermh <mh>
Fri, 28 Sep 2001 08:58:36 +0000 (08:58 +0000)
-this one adds a ProducerMedia, and more or less finalizes the MirMedia interface

also here is another workaround for the quick hack actionroot. as idfx's fix
broke it more than before...

PS: error handling is not so hot for openposting right now, this needs to be
fixed.

15 files changed:
dbscripts/create_pg.sql
dbscripts/populate_mediatyp.sql
source/Mir.java
source/mir/media/MediaHandlerGeneric.java
source/mir/media/MediaHandlerImages.java
source/mir/media/MirMedia.java
source/mir/misc/HTMLTemplateProcessor.java
source/mir/module/AbstractModule.java
source/mircoders/module/ModuleUploadedMedia.java [new file with mode: 0755]
source/mircoders/producer/Producer.java
source/mircoders/producer/ProducerMedia.java [new file with mode: 0755]
source/mircoders/servlet/ServletModuleOpenIndy.java
source/mircoders/storage/DatabaseImages.java
source/mircoders/storage/DatabaseUploadedMedia.java
source/mircoders/storage/DatabaseVideos.java

index 56cd168..f5d620f 100755 (executable)
@@ -324,6 +324,7 @@ CREATE TABLE "media" (
        "publish_server" character varying(255),
        "publish_path" character varying(255),
        "is_published" boolean DEFAULT '0' NOT NULL,
+       "is_produced" boolean DEFAULT '0' NOT NULL,
        "to_feature" integer DEFAULT '0' NOT NULL,
        "to_media_folder" integer DEFAULT '0' NOT NULL,
        "to_media_type" smallint DEFAULT '0' NOT NULL,
@@ -342,11 +343,20 @@ CREATE TABLE "media" (
 -- Name: images Type: TABLE Owner: postgres
 --
 
+--
+-- TOC Entry ID 32 (OID 29446)
+--
+-- Name: uploaded_media Type: TABLE Owner: postgres
+--
+
+CREATE TABLE "uploaded_media" (
+       "icon_is_produced" boolean DEFAULT '0' NOT NULL,
+       "icon_path" character varying(255)
+) INHERITS ("media");
+
 CREATE TABLE "images" (
        "image_data" oid,
        "icon_data" oid,
-       "icon_path" character varying(255),
-       "icon_is_produced" boolean DEFAULT '0' NOT NULL,
        "year" character varying(40),
        "img_width" smallint,
        "img_height" smallint,
@@ -357,7 +367,7 @@ CREATE TABLE "images" (
        "icon_width" smallint,
        "icon_height" smallint
 )
-INHERITS ("media");
+INHERITS ("uploaded_media");
 
 --
 -- TOC Entry ID 29 (OID 29338)
@@ -372,7 +382,6 @@ CREATE TABLE "content" (
        "date_to" character varying(8),
        "date_name" character varying(255),
        "is_html" boolean DEFAULT '0' NOT NULL,
-       "is_produced" boolean DEFAULT '0' NOT NULL,
        "is_stored" boolean DEFAULT '0' NOT NULL,
        "is_mail_sent" boolean DEFAULT '1' NOT NULL,
        "is_digest_sent" boolean DEFAULT '1' NOT NULL,
@@ -408,16 +417,6 @@ CREATE TABLE "messages" (
 );
 
 --
--- TOC Entry ID 32 (OID 29446)
---
--- Name: uploaded_media Type: TABLE Owner: postgres
---
-
-CREATE TABLE "uploaded_media" (
-) INHERITS ("media");
-
---
 -- TOC Entry ID 33 (OID 30026)
 --
 -- Name: comment_status Type: TABLE Owner: postgres
index 3fd373a..d7724a7 100755 (executable)
@@ -2,7 +2,7 @@
 -- Selected TOC Entries:
 --
 --
--- Data for TOC Entry ID 2 (OID 28909)
+-- Data for TOC Entry ID 2 (OID 54758)
 --
 -- Name: media_type Type: TABLE DATA Owner: postgres
 --
@@ -14,13 +14,14 @@ UPDATE "pg_class" SET "reltriggers" = 0 WHERE "relname" = 'media_type';
 
 COPY "media_type"  FROM stdin;
 2      unknown application/octet-stream        --      UploadedMedia   \N
-3      gif     image/gif       ImagesGif       Images  \N
+3      jpg     image/gif       ImagesGif       Images  \N
+4      mp3     audio/mp3       Generic UploadedMedia   \N
 \.
 -- Enable triggers
 UPDATE pg_class SET reltriggers = (SELECT count(*) FROM pg_trigger where pg_class.oid = tgrelid) WHERE relname = 'media_type';
 
 --
--- TOC Entry ID 1 (OID 28890)
+-- TOC Entry ID 1 (OID 54706)
 --
 -- Name: media_type_id_seq Type: SEQUENCE SET Owner: 
 --
index 8ac8b84..23b5852 100755 (executable)
@@ -50,8 +50,8 @@ public class Mir extends AbstractServlet
     // get the configration
     if (!confed){
       confed = getConfig(req);
-      MirConfig.setServletName(getServletName());
     }
+    MirConfig.setServletName(getServletName());
 
     session = req.getSession(true);
 
index ae9a9e3..df11bf0 100755 (executable)
@@ -30,8 +30,18 @@ public class MediaHandlerGeneric implements MirMedia
         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);
+        //hack: make it a config option to use "dated" dirs
+        //we can't cause of stallman -mh
+        //if(FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData)) {
         if(FileUtil.write(dir+"/"+mediaFname, uploadedData)) {
             try {
+                ent.setValueForProperty("is_produced", "1");
+                ent.setValueForProperty("icon_is_produced", "1");
+                //hack: make it a config option to use "dated" dirs
+                //we can't cause of stallman -mh
+                //ent.setValueForProperty("publish_path",datePath+"/"+mediaFname);
                 ent.setValueForProperty("publish_path", mediaFname);
                 ent.setValueForProperty("publish_server", mediaHost);
                 ent.update();
@@ -61,16 +71,28 @@ public class MediaHandlerGeneric implements MirMedia
     }
 
     public byte[] get (Entity ent, Entity mediaTypeEnt) {
-        String ext = mediaTypeEnt.getValue("extension");
-        String dir = MirConfig.getProp("Producer.Media.Path");
-        String fullFname = dir+"/"+ent.getId()+"."+ext;
-        return getFile(fullFname);
+        return null;
     }
 
     public byte[] getIcon (Entity ent) {
         String name = "/path/to/some/generic/icon";
         return getFile(name);
     }
+
+    public String getStoragePath()
+    {
+        return MirConfig.getProp("Producer.Media.Path");
+    }
+
+    public String getIconStoragePath()
+    {
+        return MirConfig.getProp("Producer.Image.IconPath");
+    }
+
+    public String getPublishHost()
+    {
+        return MirConfig.getProp("Producer.Media.Host");
+    }
 }
         
         
index d89f83c..bf3f553 100755 (executable)
@@ -85,4 +85,20 @@ public class MediaHandlerImages
 
         return icon_data;
     }
+
+    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");
+    }
+        
 }
index 736a06b..d4a0f0c 100755 (executable)
@@ -28,6 +28,10 @@ public interface  MirMedia{
 
        public abstract byte[] get (Entity ent, Entity mediaTypeEnt);
 
+       public String getStoragePath ();
+       public String getIconStoragePath ();
+       public String getPublishHost ();
+
 
        /**
         * Liefert die URL für JDBC zurück, in den die Parameter user, pass und host
index 5a30e99..1253f22 100755 (executable)
@@ -45,7 +45,10 @@ public final class HTMLTemplateProcessor {
     templateCache.startAutoUpdate();
     theLog = Logfile.getInstance(MirConfig.getPropWithHome("HTMLTemplateProcessor.Logfile"));
     docRoot = MirConfig.getProp("RootUri");
-    actionRoot = docRoot + "/servlet/" + MirConfig.getProp("ServletName");
+    //the quick hack is back in effect as it was more broken than ever before
+    // -mh
+    //actionRoot = docRoot + "/servlet/" + MirConfig.getProp("ServletName");
+    actionRoot = docRoot + "/servlet/Mir";
     openAction = MirConfig.getProp("Producer.OpenAction");
     productionHost = MirConfig.getProp("Producer.ProductionHost");
     videoHost = MirConfig.getProp("Producer.VideoHost");
index f82cc94..db40dd6 100755 (executable)
@@ -63,6 +63,8 @@ public class AbstractModule {
                try {
                        if (theStorage == null)
                                throw  new ModuleException("Kein StorageObject gesetzt");
+            theLog = Logfile.getInstance(MirConfig.getProp("Home") + "log/media.log");
+            theLog.printError("aboot to run getByWhere...");
                        return theStorage.selectByWhereClause(whereClause, offset);
                }
                catch (StorageObjectException e){
diff --git a/source/mircoders/module/ModuleUploadedMedia.java b/source/mircoders/module/ModuleUploadedMedia.java
new file mode 100755 (executable)
index 0000000..2d9e718
--- /dev/null
@@ -0,0 +1,42 @@
+package mircoders.module;
+
+import java.io.*;
+import java.lang.*;
+import java.util.*;
+import java.sql.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+import freemarker.template.*;
+
+import mir.servlet.*;
+import mir.module.*;
+import mir.entity.*;
+import mir.misc.*;
+import mir.storage.*;
+
+import mircoders.storage.*;
+
+/*
+ *  ThemenModule -
+ *
+ *
+ * @author RK
+ */
+
+public class ModuleUploadedMedia extends AbstractModule
+{
+
+    static Logfile theLog;
+
+    public ModuleUploadedMedia(StorageObject theStorage) {
+           this.theStorage = theStorage;
+           if (theLog == null)
+             theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Module.Themen.Logfile"));
+    }
+
+    public SimpleList getUploadedMediaAsSimpleList() {
+           return ((DatabaseUploadedMedia)theStorage).getPopupData();
+    }
+
+}
index a588490..46bcc02 100755 (executable)
@@ -25,6 +25,7 @@ abstract public class Producer {
        protected static ModuleGruppen        gruppenModule;
        protected static ModuleContent        contentModule;
        protected static ModuleImages         imageModule;
+       protected static ModuleUploadedMedia  uploadedMediaModule;
 
   static {
                // init
@@ -35,6 +36,7 @@ abstract public class Producer {
                        schwerpunktModule = new ModuleSchwerpunkt(DatabaseFeature.getInstance());
                        featureModule = new ModuleFeature(DatabaseFeature.getInstance());
                        imageModule = new ModuleImages(DatabaseImages.getInstance());
+                       uploadedMediaModule = new ModuleUploadedMedia(DatabaseImages.getInstance());
                } catch(StorageObjectException e) {;}
   }
 
diff --git a/source/mircoders/producer/ProducerMedia.java b/source/mircoders/producer/ProducerMedia.java
new file mode 100755 (executable)
index 0000000..8a9dea4
--- /dev/null
@@ -0,0 +1,131 @@
+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 mir.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              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<batchEntityList.size();i++) {
+                try {
+                    currentMedia = (Entity)batchEntityList.elementAt(i);
+
+                    Entity currentMediaType = DatabaseUploadedMedia.getInstance().getMediaType(currentMedia);
+                    String mediaHandlerName = currentMediaType.getValue("classname");
+                    Class mediaHandlerClass = Class.forName("mir.media.MediaHandler"+mediaHandlerName);
+                    MirMedia currentMediaHandler = (MirMedia)mediaHandlerClass.newInstance();       
+                        
+                    String date = currentMedia.getValue("date");
+                    String datePath = StringUtil.webdbDate2path(date);
+
+                    // do icon
+                    if (currentMedia.getValue("icon_is_produced") != "1") {
+                        iconPath = currentMediaHandler.getIconStoragePath();
+                        iconFilename = producerDocRoot+iconPath+datePath+
+                            currentMedia.getId()+"."+currentMediaType.getValue("name");
+                        iconProduced = produceFile(iconFilename, currentMediaHandler.getIcon(currentMedia), htmlout, true);
+                        if(iconProduced) {
+                            currentMedia.setValueForProperty("icon_path",iconFilename);
+                            logHTML(htmlout,"icon : " + iconFilename + (( iconProduced==true )? " succeded":" <font color=\"Red\" failed!</font>"));
+                        }
+
+                    } else {
+                        iconProduced = true;
+                    }
+                    
+                    //now produce the media content
+
+                    mediaHost = currentMediaHandler.getPublishHost();
+                    mediaPath = currentMediaHandler.getStoragePath();
+                    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);
+
+                    mediaProduced = produceFile(productionPath, currentMediaHandler.get(currentMedia, currentMediaType), htmlout, false);
+                    logHTML(htmlout,"media: " + productionPath + ((mediaProduced==true)?" succeded":" <font color=\"Red\" failed!</font>"));
+
+                    // update media-data
+                    if (iconProduced && mediaProduced) {
+                        currentMedia.setValueForProperty("icon_is_produced", "1");
+                        currentMedia.setValueForProperty("is_produced", "1");
+                        currentMedia.update();
+                    }
+
+                } catch (Exception e) {
+                    theLog.printError("failed in reflection: "+e);
+                }
+                       }
+
+                       // 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.");
+
+       }
+
+}
index 53694f2..abb7523 100755 (executable)
@@ -257,11 +257,13 @@ public class ServletModuleOpenIndy extends ServletModule
                 mediaEnt.setValues(mediaValues);
                 mediaId = mediaEnt.insert();
 
+                theLog.printError("done inserting!!! ");
                 Class mediaHandlerClass = Class.forName("mir.media.MediaHandler"+mediaHandlerName);
                 MirMedia mediaHandler = (MirMedia)mediaHandlerClass.newInstance();
                 mediaHandler.set(mpReq.getMedia(), mediaEnt,mediaTypesList.elementAt(0));
+                theLog.printError("about to run ProduceMedia"+mediaId);
               if(mediaId!=null){
-                //new ProducerImages().handle(null, null, false, false, mediaId);
+                new ProducerMedia().handle(null, null, false, false, mediaId);
               }
           } catch (Exception e) {
                 theLog.printError("setting uploaded_media failed: "+e.toString());
@@ -280,53 +282,6 @@ public class ServletModuleOpenIndy extends ServletModule
           throw new ServletModuleException("ModuleException: One or more files of unrecognized types");
         }
           
-     
-            
-
-          
-
-        //MirUploadedMedia Media = MirUploadedMedia(mpReq, cid); 
-                //mediaValues.put("title",mediaTitle);
-
-        //mediaId = Media.add();
-         /*   // this is video !!
-            //theLog.printDebugInfo("--GOT VIDEO");
-            EntityVideo entVideo = new EntityVideo(DatabaseVideos.getInstance());
-            //notice the discr here..... (imageModule).
-            entVideo.setValues(mediaValues);
-            mediaId = entVideo.insert();
-            entVideo.setVideoData(mediaData);
-          }
-          //try content type first then go by xtension?
-          else if (contentType.equals("image/jpeg") || contentType.equals("image/gif")) {
-            // this is image !!
-            mediaId = imageModule.add(mediaValues);
-            EntityImages entImage = (EntityImages)imageModule.getById(mediaId);
-  
-            int fileType = -1;
-
-            //replace all this with DatabaseContentMedia.getInst().getEn(contentType).set(mediaData) ??? w/ a catch for error, then return form w/ and error
-            if (contentType.equals("image/jpeg")) fileType=0;
-            if (contentType.equals("image/gif")) fileType=1;
-            if (fileType>=0) {
-              entImage.setImage(mediaData, fileType);
-              // inserting content and media id in table content_x_media
-              try{
-                DatabaseContentToMedia.getInstance().addMedia(cid,mediaId);
-                theLog.printError("setting content_x_media success");
-              } catch (Exception e) {
-                theLog.printError("setting content_x_media failed");
-              }
-              
-              // producing new page
-              if(mediaId!=null){
-                new ProducerImages().handle(null, null, false, false, mediaId);
-              }
-            } else {
-              theLog.printDebugInfo("Wrong file uploaded!" + fileName);
-            }
-          }
-        }*/
       }
 
       // producing openpostinglist
@@ -336,7 +291,6 @@ public class ServletModuleOpenIndy extends ServletModule
       //if direct op producing startpage
       if (directOp.equals("yes")) new ProducerStartPage().handle(null,null);
       
-
       // sync the server
       //should be configureable
       int exitValue = Helper.rsync();
index ce36a57..f181f3d 100755 (executable)
@@ -61,7 +61,6 @@ public class DatabaseImages extends Database implements StorageObject{
 
        public String insert(Entity theEntity) throws StorageObjectException
        {
-               theEntity.setValueForProperty("to_media_type","1");
                String date = theEntity.getValue("date");
                if (date==null){
                        date = StringUtil.date2webdbDate(new GregorianCalendar());
index 416f890..8489e88 100755 (executable)
@@ -54,9 +54,10 @@ public class DatabaseUploadedMedia extends Database implements StorageObject {
    * returns the comments that belong to the article (via entityrelation)
    * where db-flag is_published is true
    */
-  public Entity getMediaType(EntityUploadedMedia ent) {
+  public Entity getMediaType(Entity ent) {
     Entity type=null;
     try {
+      theLog.printError("about to run relationMediaType");
       type = relationMediaType.getOne(ent);
     }
     catch (StorageObjectException e) {
index 037de58..5c71b3e 100755 (executable)
@@ -49,7 +49,6 @@ public class DatabaseVideos extends Database implements StorageObject{
 
        public void update(Entity theEntity) throws StorageObjectException
        {
-               theEntity.setValueForProperty("to_media_type","3");
                String date = theEntity.getValue("date");
                if (date==null){
                        date = StringUtil.date2webdbDate(new GregorianCalendar());