really splitting log
[mir.git] / source / mircoders / entity / EntityContent.java
index 588ee88..68e4a77 100755 (executable)
@@ -164,11 +164,27 @@ public class EntityContent extends Entity
           throw new TemplateModelException(ex.toString());
         }
       }
-      if (key.equals("to_media")) {
+      if (key.equals("to_media_content")) {
         try {
-          return getUploadedMediaForContent();
+          /** @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();
+
+          if (t == null) {
+            System.err.println("NULL -- LIST "+this.getId());
+          } else {
+            SimpleHash o = (SimpleHash)t.next();
+            System.err.println("SCALAR: "+o.get("url"));
+          }
+
+          t.rewind();
+          //return getUploadedMediaForContent();
+          return t;
         }
         catch (Exception ex) {
+          System.err.println("ASKED EXCE");
           theLog.printWarning("-- getUploadedMediaForContent: could not fetch data " + ex.toString());
           throw new TemplateModelException(ex.toString());
         }
@@ -263,7 +279,7 @@ public class EntityContent extends Entity
         *
         * @return freemarker.template.SimpleList
         */
-       public SimpleList getComments() throws StorageObjectException {
+       private SimpleList getComments() throws StorageObjectException {
                return ((DatabaseContent)theStorageObject).getComments(this);
        }
 
@@ -348,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
@@ -402,56 +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());
-        try {
-          //upMediaSimpleHash.put("url", mediaHandler.getURL(upMedia, mediaType));
-          // ################# TODO: this is broken cause of field checking
-          // in Entity. must find a workaround
-          upMedia.setValueForProperty("url",
-                                    mediaHandler.getURL(upMedia, mediaType));
-          System.err.println("URL "+mediaHandler.getURL(upMedia, mediaType));
-          System.err.println("URK'ED? "+upMedia.get("url"));
-          System.err.println("PUB'ED? "+upMedia.get("is_published"));
-        }
-        catch (Exception ex) {
-          throw new TemplateModelException(ex.toString());
-        }
-        //upMediaSimpleHash.put("type",mediaType.getValue("classname"));
-        upMedia.setValueForProperty("type",mediaType.getValue("classname"));
-        returnList.add(upMedia);
-      } //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) );
   }
 
 }