restructuring producer content
authorrk <rk>
Tue, 5 Feb 2002 15:20:11 +0000 (15:20 +0000)
committerrk <rk>
Tue, 5 Feb 2002 15:20:11 +0000 (15:20 +0000)
source/mircoders/entity/EntityContent.java
source/mircoders/producer/ProducerContent.java

index 80cc7c6..d2bae16 100755 (executable)
@@ -4,11 +4,13 @@ import java.lang.*;
 import java.io.*;
 import java.util.*;
 import java.sql.*;
+import java.lang.reflect.*;
 
 import freemarker.template.*;
 
 import mir.entity.*;
 import mir.misc.*;
+import mir.media.*;
 import mir.storage.*;
 
 import mircoders.storage.*;
@@ -25,6 +27,11 @@ import mircoders.storage.*;
 public class EntityContent extends Entity
 {
 
+  String mirconf_extLinkName  = MirConfig.getProp("Producer.ExtLinkName");
+  String mirconf_intLinkName  = MirConfig.getProp("Producer.IntLinkName");
+  String mirconf_mailLinkName = MirConfig.getProp("Producer.MailLinkName");
+  String mirconf_imageRoot    = MirConfig.getProp("Producer.ImageRoot");
+
        // constructors
 
        public EntityContent()
@@ -143,9 +150,46 @@ public class EntityContent extends Entity
         return super.getValue(field);
     }
     return returnField;
+       }
+
+  public TemplateModel get(java.lang.String key) throws TemplateModelException
+  {
+    if (key!=null) {
+      if (key.equals("to_comments")) {
+        try {
+          return getComments();
+        }
+        catch (Exception ex) {
+          theLog.printWarning("-- getComments: could not fetch data " + ex.toString());
+          throw new TemplateModelException(ex.toString());
+        }
+      }
+      if (key.equals("to_media")) {
+        try {
+          return getUploadedMediaForContent();
+        }
+        catch (Exception ex) {
+          theLog.printWarning("-- getUploadedMediaForContent: could not fetch data " + ex.toString());
+          throw new TemplateModelException(ex.toString());
+        }
+      }
+      else if (key.equals("to_topics")) {
+        try {
+          HTMLTemplateProcessor.makeSimpleList(DatabaseContentToTopics.getInstance().getTopics(this));
+        }
+        catch (Exception ex) {
+          theLog.printWarning("-- getTopics: could not fetch data " + ex.toString());
+          throw new TemplateModelException(ex.toString());
+        }
+      }
+      else return new SimpleScalar(getValue(key));
+
+    }
+    return null;
+  }
+
 
 
-       }
 
        /**
         * overridden method setValues to patch creator_main_url
@@ -170,12 +214,9 @@ public class EntityContent extends Entity
       returnField=StringUtil.deleteForbiddenTags(returnField);
       //create http-links and email-links
       if (getValue("is_html").equals("0")) {
-        /** @todo the config stuff should be moved to StringUtil */
-        String extLinkName = MirConfig.getProp("Producer.ExtLinkName");
-        String intLinkName = MirConfig.getProp("Producer.IntLinkName");
-        String mailLinkName = MirConfig.getProp("Producer.MailLinkName");
-        String imageRoot = MirConfig.getProp("Producer.ImageRoot");
-        returnField = StringUtil.createHTML(returnField,imageRoot,mailLinkName,extLinkName,intLinkName);
+        returnField = StringUtil.createHTML(returnField,mirconf_imageRoot,
+                                            mirconf_mailLinkName,mirconf_extLinkName,
+                                            mirconf_intLinkName);
       }
       returnField = StringUtil.decodeHTMLinTags(returnField);
     }
@@ -188,12 +229,9 @@ public class EntityContent extends Entity
     if (returnField != null && returnField.length()>0) {
       returnField = StringUtil.deleteForbiddenTags(returnField);
       if (getValue("is_html").equals("0")) {
-        /** @todo the config stuff should be moved to StringUtil */
-        String extLinkName = MirConfig.getProp("Producer.ExtLinkName");
-        String intLinkName = MirConfig.getProp("Producer.IntLinkName");
-        String mailLinkName = MirConfig.getProp("Producer.MailLinkName");
-        String imageRoot = MirConfig.getProp("Producer.ImageRoot");
-        returnField = StringUtil.createHTML(returnField,imageRoot,mailLinkName,extLinkName,intLinkName);
+        returnField = StringUtil.createHTML(returnField,mirconf_imageRoot,
+                                            mirconf_mailLinkName,mirconf_extLinkName,
+                                            mirconf_intLinkName);
       }
       returnField = StringUtil.decodeHTMLinTags(returnField);
     }
@@ -209,5 +247,58 @@ public class EntityContent extends Entity
                return ((DatabaseContent)theStorageObject).getComments(this);
        }
 
+  private SimpleList getUploadedMediaForList() throws StorageObjectException
+  { return null; }
+
+  private SimpleList getUploadedMediaForContent()
+    throws StorageObjectException, TemplateModelException
+  {
+    SimpleList returnList=null;
+    EntityList currentMediaList = DatabaseContentToMedia.getInstance().getUploadedMedia(this);
+    if (currentMediaList!=null && currentMediaList.getCount()>=1)
+    {
+      Entity              upMedia,mediaType;
+      SimpleHash          upMediaSimpleHash;
+      Class               mediaHandlerClass,mediaStorageClass;
+      String              mediaStorageName,mediaHandlerName=null;
+      MirMedia            mediaHandler=null;
+      Database            mediaStorage=null;
+
+      returnList = 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");
+          try {
+            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);
+          }
+          catch (Exception ex) {
+            throw new TemplateModelException(ex.toString());
+          }
+
+          //we most likely need further info
+          upMedia = mediaStorage.selectById(upMedia.getId());
+          try {
+            upMediaSimpleHash.put("url", mediaHandler.getURL(upMedia, mediaType));
+          }
+          catch (Exception ex) {
+            throw new TemplateModelException(ex.toString());
+          }
+          upMediaSimpleHash.put("type",mediaType.getValue("classname"));
+          returnList.add(upMediaSimpleHash);
+        } //end if media_type != null
+      } //end for
+    } //end if currentMediaList != null
+    return returnList;
+  }
 
 }
index f466a3f..c430f21 100755 (executable)
@@ -2,13 +2,11 @@ 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.*;
@@ -45,39 +43,20 @@ public class ProducerContent extends Producer {
   }
 
 
-
-
-
   public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync, String id)
     throws StorageObjectException, ModuleException {
 
     String contentTemplate = MirConfig.getProp("Producer.Content.Template");
     int contentBatchsize = Integer.parseInt(MirConfig.getProp("Producer.Content.Batchsize"));
-    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              whereClause = " ";
     String              orderBy = " ";
     String              htmlFileName = null;
-    String              currentMediaId;
     EntityContent       currentContent;
     EntityList          batchEntityList;
-    SimpleHash          imageHash = new SimpleHash();
     EntityUsers         userEntity=null;
-    Entity              mediaType;
-    Entity              upMedia;
-    SimpleHash          upMediaSimpleHash;
-    Class               mediaHandlerClass;
-    Class               mediaStorageClass;
-    String              mediaStorageName;
-    String              mediaHandlerName=null;
-    MirMedia            mediaHandler=null;
-    Database            mediaStorage=null;
-
 
 
     // production of the content-pages
@@ -105,47 +84,10 @@ public class ProducerContent extends Producer {
             String date = currentContent.getValue("date");
             String year = date.substring(0,4);
             String month = date.substring(4,6);
-
             htmlFileName =  producerDocRoot
               + "/" + year + "/" + month + "/" +  currentContent.getValue("id") + ".shtml";
-
-            /** @todo all the following should take place in EntityContent */
-            // get the uploaded media
-            EntityList currentMediaList = DatabaseContentToMedia.getInstance().getUploadedMedia(currentContent);
-            if (currentMediaList!=null && currentMediaList.getCount()>=1) {
-              SimpleList mediaList = 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.getURL(upMedia, mediaType));
-                  upMediaSimpleHash.put("type",mediaType.getValue("classname"));
-                  mediaList.add(upMediaSimpleHash);
-                } //end if media_type != null
-              } //end for
-              mergeData.put("to_media", mediaList);
-            } //end if currentMediaList != null
-
-            // get the comments for the article
-            SimpleList commentList = currentContent.getComments();
-            mergeData.put("comments", commentList);
-
-            // get the topics of this article
-            mergeData.put("topics",HTMLTemplateProcessor.makeSimpleList(DatabaseContentToTopics.getInstance().getTopics(currentContent)));
-
             //produce html
-            boolean retVal = produce(contentTemplate, htmlFileName, mergeData, htmlout);
+            boolean retVal = produce(contentTemplate, htmlFileName, currentContent, htmlout);
             sessionConnectTime = new java.util.Date().getTime() - startTime;
             if (retVal == true && !"1".equals(currentContent.getValue("is_produced")))
                 currentContent.setProduced(true);
@@ -154,7 +96,6 @@ public class ProducerContent extends Producer {
           theLog.printError("Producer.Content ERROR while producing content ID: " + currentContent.getId() +",skipping it :: "+e.toString());
         }
 
-
       }//for
 
       if (batchEntityList.hasNextBatch()){