-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.
"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,
-- 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,
"icon_width" smallint,
"icon_height" smallint
)
-INHERITS ("media");
+INHERITS ("uploaded_media");
--
-- TOC Entry ID 29 (OID 29338)
"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,
);
--
--- 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
-- 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
--
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:
--
// get the configration
if (!confed){
confed = getConfig(req);
- MirConfig.setServletName(getServletName());
}
+ MirConfig.setServletName(getServletName());
session = req.getSession(true);
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();
}
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");
+ }
}
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");
+ }
+
}
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
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");
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){
--- /dev/null
+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();
+ }
+
+}
protected static ModuleGruppen gruppenModule;
protected static ModuleContent contentModule;
protected static ModuleImages imageModule;
+ protected static ModuleUploadedMedia uploadedMediaModule;
static {
// init
schwerpunktModule = new ModuleSchwerpunkt(DatabaseFeature.getInstance());
featureModule = new ModuleFeature(DatabaseFeature.getInstance());
imageModule = new ModuleImages(DatabaseImages.getInstance());
+ uploadedMediaModule = new ModuleUploadedMedia(DatabaseImages.getInstance());
} catch(StorageObjectException e) {;}
}
--- /dev/null
+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.");
+
+ }
+
+}
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());
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
//if direct op producing startpage
if (directOp.equals("yes")) new ProducerStartPage().handle(null,null);
-
// sync the server
//should be configureable
int exitValue = Helper.rsync();
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());
* 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) {
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());