From 986ca960959af906d6b639d13ae50353b6c74dc5 Mon Sep 17 00:00:00 2001 From: mh Date: Fri, 28 Sep 2001 08:58:36 +0000 Subject: [PATCH] another media handling merge. -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. --- dbscripts/create_pg.sql | 27 ++--- dbscripts/populate_mediatyp.sql | 7 +- source/Mir.java | 2 +- source/mir/media/MediaHandlerGeneric.java | 30 ++++- source/mir/media/MediaHandlerImages.java | 16 +++ source/mir/media/MirMedia.java | 4 + source/mir/misc/HTMLTemplateProcessor.java | 5 +- source/mir/module/AbstractModule.java | 2 + source/mircoders/module/ModuleUploadedMedia.java | 42 +++++++ source/mircoders/producer/Producer.java | 2 + source/mircoders/producer/ProducerMedia.java | 131 +++++++++++++++++++++ .../mircoders/servlet/ServletModuleOpenIndy.java | 52 +------- source/mircoders/storage/DatabaseImages.java | 1 - .../mircoders/storage/DatabaseUploadedMedia.java | 3 +- source/mircoders/storage/DatabaseVideos.java | 1 - 15 files changed, 250 insertions(+), 75 deletions(-) create mode 100755 source/mircoders/module/ModuleUploadedMedia.java create mode 100755 source/mircoders/producer/ProducerMedia.java diff --git a/dbscripts/create_pg.sql b/dbscripts/create_pg.sql index 56cd1687..f5d620ff 100755 --- a/dbscripts/create_pg.sql +++ b/dbscripts/create_pg.sql @@ -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 diff --git a/dbscripts/populate_mediatyp.sql b/dbscripts/populate_mediatyp.sql index 3fd373ac..d7724a78 100755 --- a/dbscripts/populate_mediatyp.sql +++ b/dbscripts/populate_mediatyp.sql @@ -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: -- diff --git a/source/Mir.java b/source/Mir.java index 8ac8b84e..23b58527 100755 --- a/source/Mir.java +++ b/source/Mir.java @@ -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); diff --git a/source/mir/media/MediaHandlerGeneric.java b/source/mir/media/MediaHandlerGeneric.java index ae9a9e39..df11bf08 100755 --- a/source/mir/media/MediaHandlerGeneric.java +++ b/source/mir/media/MediaHandlerGeneric.java @@ -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"); + } } diff --git a/source/mir/media/MediaHandlerImages.java b/source/mir/media/MediaHandlerImages.java index d89f83cc..bf3f553e 100755 --- a/source/mir/media/MediaHandlerImages.java +++ b/source/mir/media/MediaHandlerImages.java @@ -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"); + } + } diff --git a/source/mir/media/MirMedia.java b/source/mir/media/MirMedia.java index 736a06b3..d4a0f0c0 100755 --- a/source/mir/media/MirMedia.java +++ b/source/mir/media/MirMedia.java @@ -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 diff --git a/source/mir/misc/HTMLTemplateProcessor.java b/source/mir/misc/HTMLTemplateProcessor.java index 5a30e990..1253f227 100755 --- a/source/mir/misc/HTMLTemplateProcessor.java +++ b/source/mir/misc/HTMLTemplateProcessor.java @@ -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"); diff --git a/source/mir/module/AbstractModule.java b/source/mir/module/AbstractModule.java index f82cc943..db40dd66 100755 --- a/source/mir/module/AbstractModule.java +++ b/source/mir/module/AbstractModule.java @@ -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 index 00000000..2d9e7187 --- /dev/null +++ b/source/mircoders/module/ModuleUploadedMedia.java @@ -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(); + } + +} diff --git a/source/mircoders/producer/Producer.java b/source/mircoders/producer/Producer.java index a588490a..46bcc026 100755 --- a/source/mircoders/producer/Producer.java +++ b/source/mircoders/producer/Producer.java @@ -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 index 00000000..8a9dea47 --- /dev/null +++ b/source/mircoders/producer/ProducerMedia.java @@ -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")); + } + + } 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":" ")); + + // 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."); + + } + +} diff --git a/source/mircoders/servlet/ServletModuleOpenIndy.java b/source/mircoders/servlet/ServletModuleOpenIndy.java index 53694f2a..abb7523e 100755 --- a/source/mircoders/servlet/ServletModuleOpenIndy.java +++ b/source/mircoders/servlet/ServletModuleOpenIndy.java @@ -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(); diff --git a/source/mircoders/storage/DatabaseImages.java b/source/mircoders/storage/DatabaseImages.java index ce36a578..f181f3de 100755 --- a/source/mircoders/storage/DatabaseImages.java +++ b/source/mircoders/storage/DatabaseImages.java @@ -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()); diff --git a/source/mircoders/storage/DatabaseUploadedMedia.java b/source/mircoders/storage/DatabaseUploadedMedia.java index 416f8903..8489e88e 100755 --- a/source/mircoders/storage/DatabaseUploadedMedia.java +++ b/source/mircoders/storage/DatabaseUploadedMedia.java @@ -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) { diff --git a/source/mircoders/storage/DatabaseVideos.java b/source/mircoders/storage/DatabaseVideos.java index 037de586..5c71b3ed 100755 --- a/source/mircoders/storage/DatabaseVideos.java +++ b/source/mircoders/storage/DatabaseVideos.java @@ -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()); -- 2.11.0