moved logic to EntityUploadedMedia
authorrk <rk>
Fri, 8 Feb 2002 01:36:59 +0000 (01:36 +0000)
committerrk <rk>
Fri, 8 Feb 2002 01:36:59 +0000 (01:36 +0000)
source/mir/entity/Entity.java
source/mircoders/entity/EntityContent.java
source/mircoders/entity/EntityUploadedMedia.java
source/mircoders/storage/DatabaseContentToMedia.java

index 9b341b4..80a7586 100755 (executable)
@@ -172,7 +172,6 @@ public class Entity implements TemplateHashModel, TemplateModelRoot
     if (isField(theProp))
       theValuesHash.put(theProp, theValue);
     else {
-      System.err.println("Property not found: " + theProp+theValue);
       theLog.printWarning("Property not found: " + theProp+theValue);
     }
 
index 7468801..214e8ff 100755 (executable)
@@ -166,6 +166,8 @@ public class EntityContent extends Entity
       }
       if (key.equals("to_media_content")) {
         try {
+          /** @todo why this loggin to System.err and not
+           *  theLog.printDebugInfo() ? / rk */
           System.err.println("ASKED FOR MEDIA");
           SimpleList t = getUploadedMediaForContent();
           //SimpleHash o = t.next();
@@ -176,7 +178,7 @@ public class EntityContent extends Entity
             SimpleHash o = (SimpleHash)t.next();
             System.err.println("SCALAR: "+o.get("url"));
           }
-            
+
           t.rewind();
           //return getUploadedMediaForContent();
           return t;
@@ -362,7 +364,7 @@ public class EntityContent extends Entity
         upMedia = currentMediaList.elementAt(n);
         //upMediaSimpleHash = HTMLTemplateProcessor.makeSimpleHash(upMedia);
         mediaType = ((EntityMedia)upMedia).getMediaType();
-        
+
         try {
           // ############### TODO: merge these and the getURL call into one
           // getURL helper call that just takes the Entity as a parameter
@@ -416,60 +418,16 @@ public class EntityContent extends Entity
   private SimpleList getUploadedMediaForContent()
     throws StorageObjectException, TemplateModelException
   {
-    SimpleList returnList=null;
-    EntityList currentMediaList =
-        DatabaseContentToMedia.getInstance().getUploadedMedia(this);
-    if (currentMediaList!=null && currentMediaList.getCount()>=1)
-    {
-      System.err.println("LIST NOT NULL "+this.getId());
-      Entity              upMedia,mediaType;
-      SimpleHash          upMediaSimpleHash;
-      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();
-        try {
-          // ############### TODO: merge these and the getURL call into one
-          // getURL helper call that just takes the Entity as a parameter
-          // along with media_type
-          mediaHandler = MediaHelper.getHandler( mediaType );
-          mediaStorage = MediaHelper.getStorage( mediaType,
-                                                "mircoders.storage.Database");
-        } catch (MirMediaException ex) {
-          throw new TemplateModelException(ex.toString());
-        }
-    
-        // ########## TODO: this should be transparent
-        //we most likely need further info
-        upMedia = mediaStorage.selectById(upMedia.getId());
-        SimpleHash modelRoot = new SimpleHash();
-        try {
-          //upMediaSimpleHash.put("url", mediaHandler.getURL(upMedia, mediaType));
-          // ################# TODO: this is broken cause of field checking
-          // in Entity. must find a workaround
-          modelRoot.put("url", new SimpleScalar(mediaHandler.getURL(upMedia, mediaType)));
-          modelRoot.put("is_published", upMedia.getValue("is_published"));
-          //upMedia.setValueForProperty("url",
-                                    //mediaHandler.getURL(upMedia, mediaType));
-          System.err.println("URL "+mediaHandler.getURL(upMedia, mediaType));
-          System.err.println("URK'ED? "+modelRoot.get("url"));
-          System.err.println("PUB'ED? "+modelRoot.get("is_published"));
-        }
-        catch (Exception ex) {
-          throw new TemplateModelException(ex.toString());
-        }
-        //upMediaSimpleHash.put("type",mediaType.getValue("classname"));
-        //upMedia.setValueForProperty("type",mediaType.getValue("classname"));
-        modelRoot.put("type",mediaType.getValue("classname"));
-        returnList.add(modelRoot);
-      } //end for
-    } //end if currentMediaList != null
-    return returnList;
+    /** @todo all logic related to uploaded media should be moved
+     *  to EntityUploadedMedia, selection should just take place
+     *  on published media! .. will fix it later / rk
+     *
+     * ok i moved it... let's see what happens...
+     *
+     *  */
+
+    return HTMLTemplateProcessor.makeSimpleList(
+             DatabaseContentToMedia.getInstance().getUploadedMedia(this) );
   }
 
 }
index a5a4918..6528ce9 100755 (executable)
@@ -8,6 +8,7 @@ import java.sql.*;
 import mir.entity.*;
 import mir.misc.*;
 import mir.storage.*;
+import mir.media.*;
 
 import mircoders.storage.*;
 /**
@@ -41,6 +42,7 @@ public class EntityUploadedMedia extends Entity
                super.setValues(theStringValues);
        }
 
+
        /**
         * fetches the MediaType entry assiciated w/ this media
         *
@@ -56,4 +58,35 @@ public class EntityUploadedMedia extends Entity
         return ent;
        }
 
+  public String getValue(String key)
+  {
+    String returnValue=null;
+
+    if (key!=null) {
+      if (key.equals("url"))
+        returnValue=getUrl();
+      else
+        returnValue=super.getValue(key);
+    }
+    return returnValue;
+  }
+
+  private String getUrl()
+  {
+    MirMedia            mediaHandler=null;
+    Database            mediaStorage=null;
+    Entity              mediaType=null;
+
+    try {
+      mediaType = getMediaType();
+      mediaHandler = MediaHelper.getHandler( mediaType );
+      mediaStorage = MediaHelper.getStorage( mediaType, "mircoders.storage.Database");
+      return mediaHandler.getURL(this, mediaType);
+    } catch (Exception ex) {
+      theLog.printWarning("-- getUrl: could not fetch data " + ex.toString());
+    }
+    return null;
+  }
+
+
 }
index c2d2ac1..5a42010 100755 (executable)
@@ -92,7 +92,10 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
    *
    */
   public EntityList getUploadedMedia(EntityContent content)
-    throws StorageObjectException {
+    throws StorageObjectException
+  {
+    /** @todo this should only fetch published media / rk */
+
     EntityList returnList=null;
     if (content != null) {
       // get all to_topic from media_x_topic