X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmircoders%2Fproducer%2FProducerStartPage.java;h=80309598a607efd79e04c03062b4b77e35aec1b7;hb=c60a95adcf91d0ca0705a1b781ee239df8e901fb;hp=5c69f20586135f3f4af587eb9629abf0876818d1;hpb=3a661e8f0f659ab5ed2ac0e4d982ac0b398d11f1;p=mir.git diff --git a/source/mircoders/producer/ProducerStartPage.java b/source/mircoders/producer/ProducerStartPage.java index 5c69f205..80309598 100755 --- a/source/mircoders/producer/ProducerStartPage.java +++ b/source/mircoders/producer/ProducerStartPage.java @@ -2,11 +2,13 @@ package mircoders.producer; import java.io.*; import java.lang.*; +import java.lang.reflect.*; import java.util.*; import freemarker.template.*; import mir.misc.*; +import mir.media.*; import mir.storage.*; import mir.module.*; import mir.entity.*; @@ -18,114 +20,307 @@ import mircoders.entity.*; public class ProducerStartPage extends Producer { - private static String startPageTemplate = Configuration.getProperty("Producer.StartPage.Template"); - private static int itemsPerPage = Integer.parseInt(Configuration.getProperty("Producer.StartPage.Items")); - private static int newsPerPage = Integer.parseInt(Configuration.getProperty("Producer.StartPage.Newswire")); - - public static void main(String argv[]){ - try { - Configuration.initConfig(argv[0]); - new ProducerStartPage().handle(new PrintWriter(System.out), null); - } catch(Exception e) { - System.err.println(e.toString()); - } - } - - public void handle(PrintWriter htmlout, EntityUsers user, boolean force,boolean sync) - throws StorageObjectException, ModuleException - { - printHTML(htmlout, "Producer.StartPage: started"); - - String extLinkName = Configuration.getProperty("Producer.ExtLinkName"); - String intLinkName = Configuration.getProperty("Producer.IntLinkName"); - String mailLinkName = Configuration.getProperty("Producer.MailLinkName"); - String imageRoot = Configuration.getProperty("Producer.ImageRoot"); - - long sessionConnectTime = 0; - long startTime = (new java.util.Date()).getTime(); - String nowWebdbDate = StringUtil.date2webdbDate(new GregorianCalendar()); - String whereClause; - String orderBy; - FileWriter outputFile; - String htmlFileName; - EntityContent currentContent; - EntityList entityList; - SimpleHash startPageModel; - SimpleList contentList; - String currentMediaId; - SimpleHash imageHash = new SimpleHash(); - - // get the topiclist - entityList = topicsModule.getByWhereClause("","title",-1); - SimpleList topicList = HTMLTemplateProcessor.makeSimpleList(entityList); - - // get the newswire - whereClause="is_published=true AND to_article_type >= 1"; - entityList = contentModule.getContent(whereClause,"date desc, webdb_create desc",0,newsPerPage); - SimpleList newsWireList = HTMLTemplateProcessor.makeSimpleList(entityList); - - // get the startarticle and the related images - whereClause="is_published=true AND to_article_type=4"; - entityList = contentModule.getContent(whereClause,"date desc, webdb_create desc",0,1); - //if no startspecial exists - if (entityList==null || entityList.size()==0){ - whereClause="is_published=true AND to_article_type=3"; - entityList = contentModule.getContent(whereClause,"date desc, webdb_create desc",0,1); - } - SimpleList startItemList = HTMLTemplateProcessor.makeSimpleList(entityList); - for (int i=0; i < entityList.size();i++) { - currentContent = (EntityContent)entityList.elementAt(i); - currentMediaId = currentContent.getValue("to_media"); - if (currentMediaId!=null && !currentMediaId.equals("")) { - imageHash.put(currentMediaId, HTMLTemplateProcessor.makeSimpleHash(imageModule.getById(currentMediaId))); - } - } - - // get the breaking news - // only the first 5 - ModuleBreaking breakingModule = new ModuleBreaking(DatabaseBreaking.getInstance()); - entityList = breakingModule.getByWhereClause(null,"webdb_create desc",0,5); - SimpleList breakingList = HTMLTemplateProcessor.makeSimpleList(entityList); - - // get the articles - whereClause="is_published=true AND to_article_type=2"; - orderBy="date desc, webdb_create desc"; - entityList = contentModule.getContent(whereClause, orderBy, 0, itemsPerPage); - for (int i=0; i < entityList.size();i++) { - currentContent = (EntityContent)entityList.elementAt(i); - /** - if (currentContent.get("is_html").equals("0")) { - currentContent.put("content_data",StringUtil.createHTML((String)currentContent.get("content_data"),imageRoot,mailLinkName,extLinkName,intLinkName)); - currentContent.put("description",StringUtil.createHTML((String)currentContent.get("description"),imageRoot,mailLinkName,extLinkName,intLinkName)); - } - */ - currentMediaId = currentContent.getValue("to_media"); - if (currentMediaId!=null && !currentMediaId.equals("")) { - imageHash.put(currentMediaId, HTMLTemplateProcessor.makeSimpleHash(imageModule.getById(currentMediaId))); - } - } - SimpleList itemList = HTMLTemplateProcessor.makeSimpleList(entityList); - - // Zusaetzlich Informationen - startPageModel = new SimpleHash(); - startPageModel.put("breaking", breakingList); - startPageModel.put("topics", topicList); - startPageModel.put("newswire", newsWireList); - startPageModel.put("start", startItemList); - startPageModel.put("items", itemList); - startPageModel.put("images", imageHash); - - htmlFileName = producerDocRoot + "/index.shtml"; - - produce(startPageTemplate, htmlFileName, startPageModel, new LineFilterWriter(htmlout)); - - // Finish - sessionConnectTime = new java.util.Date().getTime() - startTime; - logHTML(htmlout, "Producer.Startseite finished: " + sessionConnectTime + " ms."); - if(sync==true){ - Helper.rsync(); - logHTML(htmlout, "Producer.Startseite: rsync done"); - } - } + private static String startPageTemplate = MirConfig.getProp("Producer.StartPage.Template"); + private static int itemsPerPage = Integer.parseInt(MirConfig.getProp("Producer.StartPage.Items")); + private static int newsPerPage = Integer.parseInt(MirConfig.getProp("Producer.StartPage.Newswire")); + Entity mediaType; + Entity upMedia; + SimpleHash upMediaSimpleHash; + Class mediaHandlerClass; + Class mediaStorageClass; + String mediaStorageName; + + + + public static void main(String argv[]){ + try { + // Why are we reloading the configuration here? + // is there something I'm missing? + // mh. + // Configuration.initConfig(argv[0]); + new ProducerStartPage().handle(new PrintWriter(System.out), null); + } catch(Exception e) { + System.err.println(e.toString()); + } + } + + public void handle(PrintWriter htmlout, EntityUsers user, boolean force,boolean sync) + throws StorageObjectException, ModuleException + { + printHTML(htmlout, "Producer.StartPage: started"); + + String extLinkName = MirConfig.getProp("Producer.ExtLinkName"); + String intLinkName = MirConfig.getProp("Producer.IntLinkName"); + String mailLinkName = MirConfig.getProp("Producer.MailLinkName"); + String imageRoot = MirConfig.getProp("Producer.ImageRoot"); + + long sessionConnectTime = 0; + long startTime = (new java.util.Date()).getTime(); + String nowWebdbDate = StringUtil.date2webdbDate(new GregorianCalendar()); + String whereClause; + String orderBy; + FileWriter outputFile; + String htmlFileName; + EntityContent currentContent; + EntityList entityList; + SimpleHash startPageModel; + SimpleList contentList; + String currentMediaId; + EntityList upMediaEntityList; + EntityList imageEntityList; + EntityList currentMediaList; + Entity mediaType; + EntityMedia uploadedMedia; + Class mediaHandlerClass=null; + MirMedia mediaHandler=null; + String mediaHandlerName=null; + Database mediaStorage=null; + String tinyIcon; + String iconAlt; + Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home") + "/" +MirConfig.getProp("Producer.Logfile")); + + SimpleList mediaList; + SimpleHash contentHash; + + // get the topiclist + entityList = topicsModule.getByWhereClause("","title",-1); + SimpleList topicList = HTMLTemplateProcessor.makeSimpleList(entityList); + + // get the imclinks + entityList = linksImcsModule.getByWhereClause("", "sortpriority, title", -1); + SimpleList imcList = HTMLTemplateProcessor.makeSimpleList(entityList); + + EntityList theParentList = linksImcsModule.getByWhereClause("to_parent_id=NULL", "sortpriority, title", -1); + SimpleList parentList = HTMLTemplateProcessor.makeSimpleList(theParentList); + + // get the newswire + whereClause="is_published=true AND to_article_type = 1"; + entityList = contentModule.getContent(whereClause,"date desc, webdb_create desc",0,newsPerPage); + SimpleList newsWireList = HTMLTemplateProcessor.makeSimpleList(entityList); + for (int i=0; i < entityList.size();i++) { + currentContent = (EntityContent)entityList.elementAt(i); + try { + //fetching/setting the images + upMediaEntityList = DatabaseContentToMedia.getInstance().getUploadedMedia(currentContent); + if (upMediaEntityList!=null && upMediaEntityList.getCount()>=1) { + tinyIcon = null; + iconAlt = null; + mediaHandler = null; + mediaHandlerName = null; + for (int n=0; n < upMediaEntityList.size();n++) { + uploadedMedia = (EntityMedia)upMediaEntityList.elementAt(n); + mediaType = uploadedMedia.getMediaType(); + + //must of had a non-existant to_media_type entry.. + //let's save our ass. + if (mediaType != null) { + mediaHandlerName = mediaType.getValue("classname"); + mediaHandlerClass = Class.forName("mir.media.MediaHandler"+mediaHandlerName); + mediaHandler = (MirMedia)mediaHandlerClass.newInstance(); + + //the "best" media type to show + if (mediaHandler.isVideo()) { + tinyIcon = MirConfig.getProp("Producer.Icon.TinyVideo"); + iconAlt = "Video"; + break; + } else if (mediaHandler.isAudio()) { + tinyIcon = MirConfig.getProp("Producer.Icon.TinyAudio"); + iconAlt = "Audio"; + } else if (tinyIcon == null && !mediaHandler.isImage()) { + tinyIcon = mediaHandler.getTinyIcon(); + iconAlt = mediaHandler.getIconAlt(); + } + } + } + //it only has image(s) + if (tinyIcon == null) { + tinyIcon = MirConfig.getProp("Producer.Icon.TinyImage"); + iconAlt = "Image"; + } + + // uploadedMedia Entity list is empty. + // we only have text + } else { + tinyIcon = MirConfig.getProp("Producer.Icon.TinyText"); + iconAlt = "Text"; + } + + //mediaList = HTMLTemplateProcessor.makeSimpleList(upMediaEntityList); + contentHash = (SimpleHash)newsWireList.get(i); + contentHash.put("tiny_icon", imageRoot+"/"+tinyIcon); + contentHash.put("icon_alt", iconAlt); + } catch (Exception e) { + logHTML(htmlout, "Producer.StartPage error id: " + currentContent.getId() + ", skipping"); + theLog.printError("Producer.StartPage error id: " + currentContent.getId() + ", skipping"+e.toString()); + } + } + theLog.printDebugInfo("############### got newswire"); + + // get the startarticle and the related images + whereClause="is_published=true AND to_article_type=4"; + entityList = contentModule.getContent(whereClause,"date desc, webdb_create desc",0,1); + //if no startspecial exists + if (entityList==null || entityList.size()==0){ + whereClause="is_published=true AND to_article_type=3"; + entityList = contentModule.getContent(whereClause,"date desc, webdb_create desc",0,1); + } + SimpleList startItemList = HTMLTemplateProcessor.makeSimpleList(entityList); + for (int k=0; k < entityList.size();k++) { + currentContent = (EntityContent)entityList.elementAt(k); + try { + //media to content + currentMediaList = DatabaseContentToMedia.getInstance().getUploadedMedia(currentContent); + contentHash = (SimpleHash)startItemList.get(k); + if (currentMediaList!=null && currentMediaList.getCount()>=1) { + SimpleList mediaListAudio = new SimpleList(); + SimpleList mediaListImages = new SimpleList(); + SimpleList mediaListVideo = new SimpleList(); + SimpleList mediaListOther = new SimpleList(); + for (int n=0; n < currentMediaList.size();n++) { + upMedia = currentMediaList.elementAt(n); + upMediaSimpleHash = HTMLTemplateProcessor.makeSimpleHash(upMedia); + mediaType = ((EntityMedia)upMedia).getMediaType(); + //must be a non-existant to_media_type entry.. + if (mediaType != null) { + mediaHandlerName = mediaType.getValue("classname"); + mediaStorageName = mediaType.getValue("tablename"); + mediaStorageClass = Class.forName("mircoders.storage.Database"+mediaStorageName); + mediaHandlerClass = Class.forName("mir.media.MediaHandler"+mediaHandlerName); + mediaHandler = (MirMedia)mediaHandlerClass.newInstance(); + Method m = mediaStorageClass.getMethod("getInstance", null); + mediaStorage = (Database)m.invoke(null, null); + //we most likely need further info + upMedia = mediaStorage.selectById(upMedia.getId()); + upMediaSimpleHash.put("url", mediaHandler.getListView(upMedia, mediaType)); + if (upMedia.getValue("is_published") == "1") { + if (mediaHandler.isImage()) { + mediaListImages.add(upMediaSimpleHash); + } else if (mediaHandler.isAudio()) { + mediaListAudio.add(upMediaSimpleHash); + } else if (mediaHandler.isVideo()) { + mediaListVideo.add(upMediaSimpleHash); + } else { + mediaListOther.add(upMediaSimpleHash); + } + } //end if is_published + } //end if media_type != null + } //end for + contentHash.put("to_media_audio", mediaListAudio); + contentHash.put("to_media_images", mediaListImages); + contentHash.put("to_media_video", mediaListVideo); + contentHash.put("to_media_other", mediaListOther); + } //end if currentMediaList != null + //convert to html + if ( ((SimpleScalar)contentHash.get("is_html")).getAsString().equals("0") ) { + SimpleScalar tempScalar = (SimpleScalar)contentHash.get("description"); + String temp = StringUtil.createHTML(tempScalar.getAsString(),imageRoot,mailLinkName,extLinkName,intLinkName); + temp = StringUtil.decodeHTMLinTags(temp); + contentHash.put("description",temp); + } + + } catch (Exception e) { + logHTML(htmlout, "Producer.StartPage error id: " + currentContent.getId() + ", skipping"); + theLog.printError("Producer.StartPage error id: " + currentContent.getId() + ", skipping"+e.toString()); + } + } //enf for featurueList.size.. + + theLog.printDebugInfo("############### got startitems"); + + // get the breaking news + // only the first 5 + // todo: the number of breaking_news items have to be configurable + ModuleBreaking breakingModule = new ModuleBreaking(DatabaseBreaking.getInstance()); + entityList = breakingModule.getByWhereClause(null,"webdb_create desc",0,5); + SimpleList breakingList = HTMLTemplateProcessor.makeSimpleList(entityList); + theLog.printDebugInfo("############### got breaking"); + + // get the articles + whereClause="is_published=true AND to_article_type=2"; + orderBy="date desc, webdb_create desc"; + entityList = contentModule.getContent(whereClause, orderBy, 0, itemsPerPage); + SimpleList featureList = HTMLTemplateProcessor.makeSimpleList(entityList); + for (int k=0; k < entityList.size();k++) { + currentContent = (EntityContent)entityList.elementAt(k); + try { + //media to content + currentMediaList = DatabaseContentToMedia.getInstance().getUploadedMedia(currentContent); + contentHash = (SimpleHash)featureList.get(k); + if (currentMediaList!=null && currentMediaList.getCount()>=1) { + SimpleList mediaListAudio = new SimpleList(); + SimpleList mediaListImages = new SimpleList(); + SimpleList mediaListVideo = new SimpleList(); + SimpleList mediaListOther = new SimpleList(); + for (int n=0; n < currentMediaList.size();n++) { + upMedia = currentMediaList.elementAt(n); + upMediaSimpleHash = HTMLTemplateProcessor.makeSimpleHash(upMedia); + mediaType = ((EntityMedia)upMedia).getMediaType(); + //must be a non-existant to_media_type entry.. + if (mediaType != null) { + mediaHandlerName = mediaType.getValue("classname"); + mediaStorageName = mediaType.getValue("tablename"); + mediaStorageClass = Class.forName("mircoders.storage.Database"+mediaStorageName); + mediaHandlerClass = Class.forName("mir.media.MediaHandler"+mediaHandlerName); + mediaHandler = (MirMedia)mediaHandlerClass.newInstance(); + Method m = mediaStorageClass.getMethod("getInstance", null); + mediaStorage = (Database)m.invoke(null, null); + //we most likely need further info + upMedia = mediaStorage.selectById(upMedia.getId()); + upMediaSimpleHash.put("url", mediaHandler.getListView(upMedia, mediaType)); + if (upMedia.getValue("is_published") == "1") { + if (mediaHandler.isImage()) { + mediaListImages.add(upMediaSimpleHash); + } else if (mediaHandler.isAudio()) { + mediaListAudio.add(upMediaSimpleHash); + } else if (mediaHandler.isVideo()) { + mediaListVideo.add(upMediaSimpleHash); + } else { + mediaListOther.add(upMediaSimpleHash); + } + } //end if is_published + } //end if media_type != null + } //end for + contentHash.put("to_media_audio", mediaListAudio); + contentHash.put("to_media_images", mediaListImages); + contentHash.put("to_media_video", mediaListVideo); + contentHash.put("to_media_other", mediaListOther); + } //end if currentMediaList != null + + //convert to html + if ( ((SimpleScalar)contentHash.get("is_html")).getAsString().equals("0") ) { + SimpleScalar tempScalar = (SimpleScalar)contentHash.get("description"); + String temp = StringUtil.createHTML(tempScalar.getAsString(),imageRoot,mailLinkName,extLinkName,intLinkName); + temp = StringUtil.decodeHTMLinTags(temp); + contentHash.put("description",temp); + } + + } catch (Exception e) { + logHTML(htmlout, "Producer.StartPage error id: " + currentContent.getId() + ", skipping"); + theLog.printError("Producer.StartPage error id: " + currentContent.getId() + ", skipping"+e.toString()); + } + } //enf for featurueList.size.. + theLog.printDebugInfo("############### got featurelist"); + + // Zusaetzlich Informationen + startPageModel = new SimpleHash(); + startPageModel.put("breakingnews", breakingList); + startPageModel.put("topics", topicList); + startPageModel.put("imclist", imcList); + startPageModel.put("parentlist", parentList); + startPageModel.put("newswire", newsWireList); + startPageModel.put("startspecial", startItemList); + startPageModel.put("features", featureList); + + htmlFileName = producerDocRoot + "/index.shtml"; + + produce(startPageTemplate, htmlFileName, startPageModel, htmlout); + + // Finish + sessionConnectTime = new java.util.Date().getTime() - startTime; + logHTML(htmlout, "Producer.Startseite finished: " + sessionConnectTime + " ms."); + if(sync==true){ + Helper.rsync(); + logHTML(htmlout, "Producer.Startseite: rsync done"); + } + } }