debug info
[mir.git] / source / mircoders / producer / ProducerStartPage.java
index 133b698..8030959 100755 (executable)
@@ -77,7 +77,7 @@ public class ProducerStartPage extends Producer {
     Database            mediaStorage=null;
     String              tinyIcon;
     String              iconAlt;
-    Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Producer.Logfile"));
+    Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home") + "/" +MirConfig.getProp("Producer.Logfile"));
 
     SimpleList mediaList;
     SimpleHash contentHash;
@@ -99,71 +99,62 @@ public class ProducerStartPage extends Producer {
     SimpleList newsWireList = HTMLTemplateProcessor.makeSimpleList(entityList);
     for (int i=0; i < entityList.size();i++) {
       currentContent = (EntityContent)entityList.elementAt(i);
-      //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) {
-              /*
-               * grrr. why doesn't getId return an int! if It
-               * did I could just compare the value of getId and
-               * pick the biggest one. or is there
-               * another way around this that I am missing?
-               * can we make getIdasInt() or can we just have
-               * another getId() that returns an Int and the VM
-               * will handle it transparantly? -mh
-               */
-              try {
-                mediaHandlerName = mediaType.getValue("classname");
-                mediaHandlerClass = Class.forName("mir.media.MediaHandler"+mediaHandlerName);
-                mediaHandler = (MirMedia)mediaHandlerClass.newInstance();
-              } catch (Exception e) {
-                theLog.printError("ProducerStartpage:problem in reflection: "+mediaHandlerName);
-              }
+      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
-              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();
+                  //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";
           }
-        }
-        //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";
-      }
 
-      try{
-        //mediaList = HTMLTemplateProcessor.makeSimpleList(upMediaEntityList);
-        contentHash = (SimpleHash)newsWireList.get(i);
-        contentHash.put("tiny_icon", imageRoot+"/"+tinyIcon);
-        contentHash.put("icon_alt", iconAlt);
-      } catch (Exception e){}
+          //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";
@@ -176,62 +167,72 @@ public class ProducerStartPage extends Producer {
     SimpleList startItemList = HTMLTemplateProcessor.makeSimpleList(entityList);
     for (int k=0; k < entityList.size();k++) {
       currentContent = (EntityContent)entityList.elementAt(k);
-      //media to content
-      currentMediaList = DatabaseContentToMedia.getInstance().getUploadedMedia(currentContent);
-      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) {
-            try {
-              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());
-            } catch (Exception e) {
-              theLog.printError("ProducerList: problem in reflection: "+mediaHandlerName);
-            } //end catch
-            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
-        try{
+      try {
+          //media to content
+          currentMediaList = DatabaseContentToMedia.getInstance().getUploadedMedia(currentContent);
           contentHash = (SimpleHash)startItemList.get(k);
-          contentHash.put("to_media_audio", mediaListAudio);
-          contentHash.put("to_media_images", mediaListImages);
-          contentHash.put("to_media_video", mediaListVideo);
-          contentHash.put("to_media_other", mediaListOther);
-        } catch (Exception e){}
-      } //end if currentMediaList != null
+                                       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";
@@ -240,55 +241,64 @@ public class ProducerStartPage extends Producer {
     SimpleList featureList = HTMLTemplateProcessor.makeSimpleList(entityList);
     for (int k=0; k < entityList.size();k++) {
       currentContent = (EntityContent)entityList.elementAt(k);
-      //media to content
-      currentMediaList = DatabaseContentToMedia.getInstance().getUploadedMedia(currentContent);
-      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) {
-            try {
-              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());
-            } catch (Exception e) {
-              theLog.printError("ProducerList: problem in reflection: "+mediaHandlerName);
-            } //end catch
-            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
-        try{
+      try {
+          //media to content
+          currentMediaList = DatabaseContentToMedia.getInstance().getUploadedMedia(currentContent);
           contentHash = (SimpleHash)featureList.get(k);
-          contentHash.put("to_media_audio", mediaListAudio);
-          contentHash.put("to_media_images", mediaListImages);
-          contentHash.put("to_media_video", mediaListVideo);
-          contentHash.put("to_media_other", mediaListOther);
-        } catch (Exception e){}
-      } //end if currentMediaList != null
+                                       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();