contentAdapterDefinition has been updated
authorzapata <zapata>
Mon, 13 May 2002 23:21:04 +0000 (23:21 +0000)
committerzapata <zapata>
Mon, 13 May 2002 23:21:04 +0000 (23:21 +0000)
source/mircoders/entity/adapter/ContentAdapterDefinition.java
source/mirlocal/indymedia.nl/IndyNLProducerLocalizer.java

index d5062e0..1d8a848 100755 (executable)
@@ -1,5 +1,6 @@
 package mircoders.entity.adapter;
 
+import mir.storage.*;
 import mir.entity.*;
 import mir.entity.adapter.*;
 import mircoders.storage.*;
@@ -24,14 +25,25 @@ public class ContentAdapterDefinition extends EntityAdapterDefinition {
     addDateField("date", "date");
     addCalculatedField("to_topics", new ContentToTopicsField());
     addCalculatedField("to_comments", new ContentToCommentsField());
+    try {
+      addCalculatedField("to_media_images", new ContentToMediaField(
+          DatabaseImages.getInstance(), ImagesAdapterDefinition.getInstance()));
+      addCalculatedField("to_media_audio", new ContentToMediaField(
+          DatabaseAudio.getInstance(), AudioAdapterDefinition.getInstance()));
+      addCalculatedField("to_media_video", new ContentToMediaField(
+          DatabaseVideo.getInstance(), VideoAdapterDefinition.getInstance()));
+      addCalculatedField("to_media_other", new ContentToMediaField(
+          DatabaseOther.getInstance(), OtherAdapterDefinition.getInstance()));
+      addCalculatedField("to_media_icon", new ContentToMediaField(
+          DatabaseUploadedMedia.getInstance(), UploadedMediaAdapterDefinition.getInstance()));
+    }
+    catch (Throwable t) {
+      System.out.println(t.getMessage());
+      t.printStackTrace(System.out);
+    }
+
     addCalculatedField("description_parsed", new FilteredField("description"));
     addCalculatedField("content_data_parsed", new FilteredField("content_data"));
-//      else if (field.equals(""))
-//        returnField = getDescriptionParsed();
-//      else if (field.equals("description_sentence"))
-//        returnField = getDescriptionSentence();
-//      else if (field.equals("content_data_parsed"))
-//        returnField = getContentDataParsed();
   }
 
   private class FilteredField implements CalculatedField {
@@ -80,6 +92,31 @@ public class ContentAdapterDefinition extends EntityAdapterDefinition {
       }
     }
   }
+
+  private class ContentToMediaField implements CalculatedField {
+    StorageObject storage;
+    EntityAdapterDefinition definition;
+
+    public ContentToMediaField(StorageObject aStorage, EntityAdapterDefinition aDefinition) {
+      definition = aDefinition;
+      storage = aStorage;
+    }
+
+    public Object getValue(EntityAdapter anEntityAdapter) {
+      try {
+        return getRelation(
+                    storage,
+                    "exists (select * from content_x_media where content_id="+anEntityAdapter.get("id")+" and media_id=id)",
+                    "title",
+                    definition);
+      }
+      catch (Throwable t) {
+        throw new RuntimeException(t.getMessage());
+      }
+    }
+  }
+
+
 }
 
 
@@ -101,47 +138,7 @@ public class ContentAdapterDefinition extends EntityAdapterDefinition {
 //      else if (field.equals("content_data_parsed"))
 //        returnField = getContentDataParsed();
 
-
-//      if (key.equals("to_media_images")) {
-//        try {
-//          _entCache.put(key, getImagesForContent());
-//          return (TemplateModel)_entCache.get(key);
-//        }
-//        catch (Exception ex) {
-//          theLog.printWarning("-- getImagesForContent: could not fetch data " + ex.toString());
-//          throw new TemplateModelException(ex.toString());
-//        }
-//      }
-//      if (key.equals("to_media_audio")) {
-//        try {
-////          _entCache.put(key, getAudioForContent());
-//          return (TemplateModel)_entCache.get(key);
-//        }
-//        catch (Exception ex) {
-//          theLog.printWarning("-- getAudioForContent: could not fetch data " + ex.toString());
-//          throw new TemplateModelException(ex.toString());
-//        }
-//      }
-//      if (key.equals("to_media_video")) {
-//        try {
-//          _entCache.put(key, getVideoForContent());
-/*          return (TemplateModel)_entCache.get(key);
-        }
-        catch (Exception ex) {
-          theLog.printWarning("-- getVideoForContent: could not fetch data " + ex.toString());
-          throw new TemplateModelException(ex.toString());
-        }
-      }
-      if (key.equals("to_media_other")) {
-        try {
-          _entCache.put(key, getOtherMediaForContent());
-          return (TemplateModel)_entCache.get(key);
-        }
-        catch (Exception ex) {
-          theLog.printWarning("-- getOtherMediaForContent: could not fetch data " + ex.toString());
-          throw new TemplateModelException(ex.toString());
-        }
-      }
+/*
       else if (key.equals("to_media_icon")) {
         try {
           _entCache.put(key, getUploadedMediaForNewswire());
@@ -152,123 +149,9 @@ public class ContentAdapterDefinition extends EntityAdapterDefinition {
           throw new TemplateModelException(ex.toString());
         }
       }
-      else if (key.equals("to_topics")) {
-        try {
-          _entCache.put(key,
-                        DatabaseContentToTopics.getInstance().getTopics(this));
-          return (TemplateModel)_entCache.get(key);
-        }
-        catch (Exception ex) {
-          theLog.printWarning("-- getTopics: could not fetch data " + ex.toString());
-          throw new TemplateModelException(ex.toString());
-        }
-      }
 */
 
-
-
-
 /*
-  private String getContentDataParsed() {
-    String returnField = getValue("content_data");
-    if (returnField!=null & returnField.length()>0 ) {
-      returnField=StringUtil.deleteForbiddenTags(returnField);
-      //create http-links and email-links
-      if (getValue("is_html").equals("0")) {
-        returnField = StringUtil.createHTML(returnField,mirconf_imageRoot,
-                                            mirconf_mailLinkName,mirconf_extLinkName,
-                                            mirconf_intLinkName);
-      }
-      returnField = StringUtil.decodeHTMLinTags(returnField);
-    }
-    return returnField;
-  }
-
-  private String getDescriptionSentence() {
-    String returnField = getValue("description");
-    if (returnField != null && returnField.length()>0) {
-       returnField = StringUtil.removeHTMLTags(returnField);
-       int endOfFirstSentence=StringUtil.findEndOfSentence(returnField,0);
-       if (endOfFirstSentence > 0){
-        returnField = returnField.substring(0,endOfFirstSentence);
-       }
-    }
-    return returnField;
-  }
-
-  private String getDescriptionParsed() {
-    String returnField = getValue("description");
-    if (returnField != null && returnField.length()>0) {
-      returnField = StringUtil.deleteForbiddenTags(returnField);
-      if (getValue("is_html").equals("0")) {
-        returnField = StringUtil.createHTML(returnField,mirconf_imageRoot,
-                                            mirconf_mailLinkName,mirconf_extLinkName,
-                                            mirconf_intLinkName);
-      }
-      returnField = StringUtil.decodeHTMLinTags(returnField);
-    }
-    return returnField;
-  }
-
-
-       private EntityList getComments() throws StorageObjectException {
-               return ((DatabaseContent)theStorageObject).getComments(this);
-       }
-
-  // @todo this needs to optimized. expensive SQL
-  private SimpleHash getUploadedMediaForNewswire()
-    throws StorageObjectException, TemplateModelException
-  {
-    // fetching/setting the images
-    // return to_media_icons
-    String        tinyIcon = null, iconAlt = null;
-    MirMedia      mediaHandler = null;
-    EntityUploadedMedia uploadedMedia;
-    Entity        mediaType;
-    SimpleHash    returnHash = new SimpleHash();
-
-    EntityList upMediaEntityList =
-                    DatabaseContentToMedia.getInstance().getUploadedMedia(this);
-    if (upMediaEntityList!=null && upMediaEntityList.getCount()>=1) {
-
-      for (int n=0; n < upMediaEntityList.size();n++) {
-        uploadedMedia = (EntityUploadedMedia)upMediaEntityList.elementAt(n);
-        mediaType = uploadedMedia.getMediaType();
-        try {
-          mediaHandler = MediaHelper.getHandler( mediaType );
-        } catch (MirMediaException ex) {
-          throw new TemplateModelException(ex.toString());
-        }
-        //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";
-    }
-    returnHash.put("tiny_icon", mirconf_imageRoot+"/"+tinyIcon);
-    returnHash.put("icon_alt", iconAlt);
-    return returnHash;
-  }
-
   private boolean hasMedia() throws StorageObjectException
   {
     if (_hasMedia == null) {
index c7562f9..bffe065 100755 (executable)
@@ -158,11 +158,11 @@ public class IndyNLProducerLocalizer extends MirBasicProducerLocalizer {
                     ),
                     new GeneratingProducerNode(
                         "/producer/indymedia.nl/articlepre.template",
-                        "${config.storageRoot}/${language.code}/articlepre.inc"
+                        "${config.storageRoot}/${language.code}/articlepre.shtml"
                     ),
                     new GeneratingProducerNode(
                         "/producer/indymedia.nl/articlepost.template",
-                        "${config.storageRoot}/${language.code}/articlepost.inc"
+                        "${config.storageRoot}/${language.code}/articlepost.shtml"
                     ),
                   } )
                 )