testing extension xml parser for producer.xml
authorrk <rk>
Mon, 24 Nov 2003 23:37:18 +0000 (23:37 +0000)
committerrk <rk>
Mon, 24 Nov 2003 23:37:18 +0000 (23:37 +0000)
12 files changed:
source/mir/producer/EntityBatchingProducerNode.java
source/mir/producer/EntityEnumeratingProducerNode.java
source/mir/producer/EntityListProducerNode.java
source/mir/producer/reader/DefaultProducerNodeBuilders.java
source/mir/storage/Database.java
source/mircoders/entity/EntityUploadedMedia.java
source/mircoders/localizer/basic/MirBasicDataModelLocalizer.java
source/mircoders/pdf/PDFGenerator.java
source/mircoders/producer/PDFPreFormattingProducerNode.java
source/mircoders/servlet/ServletModuleUploadedMedia.java
source/mircoders/storage/DatabaseCommentToMedia.java
source/mircoders/storage/DatabaseContentToMedia.java

index 1aa17cd..cb13837 100755 (executable)
@@ -59,6 +59,8 @@ public class EntityBatchingProducerNode implements ProducerNode {
   private String batchInfoKey;
   private String batchDataKey;
   private EntityAdapterModel model;
+  private String mainTablePrefix;
+  private List extraTables;
   private String definition;
   private String whereClause;
   private String orderByClause;
@@ -73,6 +75,8 @@ public class EntityBatchingProducerNode implements ProducerNode {
         String aBatchDataKey,
         String aBatchInfoKey,
         EntityAdapterModel aModel,
+        String aMainTablePrefix,
+        List   someExtraTables,
         String aDefinition,
         String aWhereClause,
         String anOrderByClause,
@@ -89,6 +93,8 @@ public class EntityBatchingProducerNode implements ProducerNode {
     batchDataKey = aBatchDataKey;
     batchInfoKey = aBatchInfoKey;
     model = aModel;
+    mainTablePrefix = aMainTablePrefix;
+    extraTables = someExtraTables;
     definition = aDefinition;
     whereClause = aWhereClause;
     orderByClause = anOrderByClause;
@@ -97,7 +103,7 @@ public class EntityBatchingProducerNode implements ProducerNode {
     minNrEntitiesInFirstBatchExpression = aminNrEntitiesInFirstBatchExpression;
     nrBatchesToProcessExpression = aNrBatchesToProcessExpression;
   }
-
   protected boolean isAborted(Map aValueMap) {
     Object producerValue = aValueMap.get(NodedProducer.PRODUCER_KEY);
     return (
@@ -190,7 +196,7 @@ public class EntityBatchingProducerNode implements ProducerNode {
           else
             batchData.put("next", null);
 
-          Iterator j = new EntityIteratorAdapter(expandedWhereClause, expandedOrderByClause,
+          Iterator j = new EntityIteratorAdapter(mainTablePrefix, extraTables, expandedWhereClause, expandedOrderByClause,
                     location.nrEntities, model, definition, location.nrEntities, location.firstEntity);
           List entities = new Vector();
 
index 5986d14..da7bd9e 100755 (executable)
@@ -30,6 +30,7 @@
 package mir.producer;
 
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import mir.entity.adapter.EntityAdapterModel;
@@ -41,6 +42,8 @@ public class EntityEnumeratingProducerNode extends ProducerNodeDecorator {
   private String key;
   private EntityAdapterModel model;
   private String definition;
+  private String mainTablePrefix;
+  private List extraTables;
   private String skip;
   private String limit;
   private String whereClause;
@@ -48,7 +51,8 @@ public class EntityEnumeratingProducerNode extends ProducerNodeDecorator {
 
   public EntityEnumeratingProducerNode(
               String aKey,
-              EntityAdapterModel aModel, String aDefinition,
+              EntityAdapterModel aModel, String aMainTablePrefix,
+              List someExtraTables, String aDefinition,
               String aWhereClause, String anOrderByClause,
               String aLimit, String aSkip,
               ProducerNode aSubNode) {
@@ -57,7 +61,8 @@ public class EntityEnumeratingProducerNode extends ProducerNodeDecorator {
     model = aModel;
     definition = aDefinition;
     key = aKey;
-
+    mainTablePrefix=aMainTablePrefix;
+    extraTables=someExtraTables;
     whereClause = aWhereClause;
     orderByClause = anOrderByClause;
 
@@ -70,6 +75,8 @@ public class EntityEnumeratingProducerNode extends ProducerNodeDecorator {
 
     try {
       browser = new EntityIteratorAdapter(
+          mainTablePrefix,
+          extraTables,
           ParameterExpander.expandExpression( aValueMap, whereClause ),
           ParameterExpander.expandExpression( aValueMap, orderByClause ),
           100,
index 123c15b..9b151d1 100755 (executable)
@@ -29,6 +29,7 @@
  */
 package mir.producer;
 
+import java.util.List;
 import java.util.Map;
 import java.util.Vector;
 
@@ -42,6 +43,8 @@ public class EntityListProducerNode extends ProducerNodeDecorator {
   private String key;
   private String whereClause;
   private String orderByClause;
+  private String mainTablePrefix;
+  private List extraTables;
   private int batchSize;
   private EntityAdapterModel model;
   private String definition;
@@ -49,12 +52,14 @@ public class EntityListProducerNode extends ProducerNodeDecorator {
   private String skipExpression;
 
   public EntityListProducerNode(String aKey,
-      EntityAdapterModel aModel, String aDefinition,
-      String aWhereClause, String anOrderByClause,
+      EntityAdapterModel aModel, String aMainTablePrefix, List someExtraTables,
+      String aDefinition, String aWhereClause, String anOrderByClause,
       String aLimitExpression, String aSkipExpression, ProducerNode aSubNode) {
     super(aSubNode);
 
     model = aModel;
+    mainTablePrefix = aMainTablePrefix;
+    extraTables = someExtraTables;
     definition = aDefinition;
     key = aKey;
     whereClause = aWhereClause;
@@ -64,11 +69,12 @@ public class EntityListProducerNode extends ProducerNodeDecorator {
   }
 
   public EntityListProducerNode(String aKey,
-      EntityAdapterModel aModel, String aDefinition,
-      String aWhereClause, String anOrderByClause,
+      EntityAdapterModel aModel, String aMainTablePrefix, List someExtraTables,
+      String aDefinition, String aWhereClause, String anOrderByClause,
       int aLimit, int aSkip, ProducerNode aSubNode) {
-    this(aKey,  aModel, aDefinition, aWhereClause, anOrderByClause,
-         Integer.toString(aLimit), Integer.toString(aSkip), aSubNode);
+    this(aKey,  aModel, aMainTablePrefix, someExtraTables,
+          aDefinition, aWhereClause, anOrderByClause,
+          Integer.toString(aLimit), Integer.toString(aSkip), aSubNode);
   }
 
   public void produce(Map aValueMap, String aVerb, LoggerWrapper aLogger) throws ProducerFailure, ProducerExc {
@@ -83,7 +89,7 @@ public class EntityListProducerNode extends ProducerNodeDecorator {
         aValueMap,
         key,
         new CachingRewindableIterator(
-          new EntityIteratorAdapter(
+          new EntityIteratorAdapter( mainTablePrefix, extraTables,
             ParameterExpander.expandExpression( aValueMap, whereClause ),
             ParameterExpander.expandExpression( aValueMap, orderByClause ),
             Math.min(50, limit),
index b52086d..a277407 100755 (executable)
@@ -33,6 +33,7 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -61,7 +62,7 @@ import mir.producer.RDFAggregatorProducerNode;
 import mir.producer.RSSProducerNode;
 import mir.producer.ResourceBundleProducerNode;
 import mir.producer.ScriptCallingProducerNode;
-import mir.producer.reader.ProducerNodeBuilder.ProducerNodeBuilderFactory;
+import mir.util.StringRoutines;
 import mir.util.XMLReader;
 import mir.util.XMLReaderTool;
 
@@ -200,14 +201,17 @@ public class DefaultProducerNodeBuilders {
     private final static String   ENUMERATION_DEFAULT_SUBNODE = "default";
     private final static String   ENUMERATION_LIMIT_ATTRIBUTE = LIMIT_ATTRIBUTE;
     private final static String   ENUMERATION_SKIP_ATTRIBUTE = SKIP_ATTRIBUTE;
+    private final static String   ENUMERATION_EXTRATABLES_ATTRIBUTE = "extratables";
     private final static String[] ENUMERATION_LIST_REQUIRED_ATTRIBUTES = { ENUMERATION_LIST_ATTRIBUTE, ENUMERATION_KEY_ATTRIBUTE };
     private final static String[] ENUMERATION_LIST_OPTIONAL_ATTRIBUTES = { };
     private final static String[] ENUMERATION_QUERY_REQUIRED_ATTRIBUTES = { ENUMERATION_DEFINITION_ATTRIBUTE, ENUMERATION_KEY_ATTRIBUTE };
-    private final static String[] ENUMERATION_QUERY_OPTIONAL_ATTRIBUTES = { ENUMERATION_SELECTION_ATTRIBUTE, ENUMERATION_ORDER_ATTRIBUTE, ENUMERATION_LIMIT_ATTRIBUTE, ENUMERATION_SKIP_ATTRIBUTE};
+    private final static String[] ENUMERATION_QUERY_OPTIONAL_ATTRIBUTES = { ENUMERATION_SELECTION_ATTRIBUTE, ENUMERATION_ORDER_ATTRIBUTE, ENUMERATION_LIMIT_ATTRIBUTE, ENUMERATION_SKIP_ATTRIBUTE,ENUMERATION_EXTRATABLES_ATTRIBUTE};
     private final static String[] ENUMERATION_SUBNODES = {ENUMERATION_DEFAULT_SUBNODE};
 
     private String key;
     private String definition;
+    private String mainTablePrefix;
+    private List   extraTables;
     private String list;
     private String selection;
     private String order;
@@ -240,11 +244,18 @@ public class DefaultProducerNodeBuilders {
       order = (String) XMLReaderTool.getStringAttributeWithDefault(anAttributes, ENUMERATION_ORDER_ATTRIBUTE, "");
       limit = (String) anAttributes.get(ENUMERATION_LIMIT_ATTRIBUTE);
       skip = (String) anAttributes.get(ENUMERATION_SKIP_ATTRIBUTE);
+      extraTables = StringRoutines.splitString(XMLReaderTool.getStringAttributeWithDefault(anAttributes, ENUMERATION_EXTRATABLES_ATTRIBUTE,"").trim(), ",");
+      List parts = StringRoutines.splitString(definition.trim()," ");
+      if (parts.size()==1) mainTablePrefix=(String)parts.get(0);
+      if (parts.size()==2) { 
+          mainTablePrefix=(String)parts.get(1);
+          definition=(String)parts.get(0);
+      }
     };
 
     public ProducerNode constructNode() {
       if (definition!=null)
-        return new EntityEnumeratingProducerNode(key, model, definition, selection, order, limit, skip, getSubNode(ENUMERATION_DEFAULT_SUBNODE ));
+        return new EntityEnumeratingProducerNode(key, model, mainTablePrefix, extraTables, definition, selection, order, limit, skip, getSubNode(ENUMERATION_DEFAULT_SUBNODE ));
       else
         return new ListEnumeratingProducerNode(key, list, getSubNode(ENUMERATION_DEFAULT_SUBNODE ));
     };
@@ -397,16 +408,19 @@ public class DefaultProducerNodeBuilders {
     private final static String   LIST_KEY_ATTRIBUTE = KEY_ATTRIBUTE;
     private final static String   LIST_DEFINITION_ATTRIBUTE = DEFINITION_ATTRIBUTE;
     private final static String   LIST_SELECTION_ATTRIBUTE = SELECTION_ATTRIBUTE;
+    private final static String   LIST_EXTRATABLES_ATTRIBUTE = "extratables";
     private final static String   LIST_ORDER_ATTRIBUTE = ORDER_ATTRIBUTE;
     private final static String   LIST_DEFAULT_SUBNODE = "default";
     private final static String   LIST_LIMIT_ATTRIBUTE = LIMIT_ATTRIBUTE;
     private final static String   LIST_SKIP_ATTRIBUTE = SKIP_ATTRIBUTE;
     private final static String[] LIST_REQUIRED_ATTRIBUTES = { LIST_KEY_ATTRIBUTE, LIST_DEFINITION_ATTRIBUTE };
-    private final static String[] LIST_OPTIONAL_ATTRIBUTES = { LIST_SELECTION_ATTRIBUTE, LIST_ORDER_ATTRIBUTE, LIST_SKIP_ATTRIBUTE, LIST_LIMIT_ATTRIBUTE};
+    private final static String[] LIST_OPTIONAL_ATTRIBUTES = { LIST_SELECTION_ATTRIBUTE, LIST_ORDER_ATTRIBUTE, LIST_SKIP_ATTRIBUTE, LIST_LIMIT_ATTRIBUTE,LIST_EXTRATABLES_ATTRIBUTE};
     private final static String[] LIST_SUBNODES = {};
 
     private String key;
     private String definition;
+    private String mainTablePrefix;
+    private List   extraTables;
     private String selection;
     private String order;
     private String limit;
@@ -428,10 +442,17 @@ public class DefaultProducerNodeBuilders {
       order = (String) XMLReaderTool.getStringAttributeWithDefault(anAttributes, LIST_ORDER_ATTRIBUTE, "");
       limit = (String) anAttributes.get(LIST_LIMIT_ATTRIBUTE);
       skip = (String) anAttributes.get(LIST_SKIP_ATTRIBUTE);
+      extraTables = StringRoutines.splitString(XMLReaderTool.getStringAttributeWithDefault(anAttributes, LIST_EXTRATABLES_ATTRIBUTE,"").trim(), ",");
+      List parts = StringRoutines.splitString(definition.trim()," ");
+      if (parts.size()==1) mainTablePrefix=(String)parts.get(0);
+      if (parts.size()==2) { 
+          mainTablePrefix=(String)parts.get(1);
+          definition=(String)parts.get(0);
+      }
     };
 
     public ProducerNode constructNode() {
-      return new EntityListProducerNode(key, model, definition, selection, order, limit, skip, null );
+      return new EntityListProducerNode(key, model, mainTablePrefix, extraTables, definition, selection, order, limit, skip, null );
     };
 
     public static class factory implements ProducerNodeBuilderFactory {
@@ -812,16 +833,19 @@ public class DefaultProducerNodeBuilders {
     private final static String   BATCHER_SKIP_ATTRIBUTE = SKIP_ATTRIBUTE;
 
     private final static String   BATCHER_PROCESS_ATTRIBUTE = "process";
+    private final static String   BATCHER_EXTRATABLES_ATTRIBUTE = "extratables";
 
     private final static String   BATCHER_BATCH_SUBNODE = "batches";
     private final static String   BATCHER_BATCHLIST_SUBNODE = "batchlist";
     private final static String[] BATCHER_REQUIRED_ATTRIBUTES = { BATCHER_DATAKEY_ATTRIBUTE, BATCHER_INFOKEY_ATTRIBUTE, BATCHER_DEFINITION_ATTRIBUTE, BATCHER_BATCHSIZE_ATTRIBUTE };
-    private final static String[] BATCHER_OPTIONAL_ATTRIBUTES = { BATCHER_SELECTION_ATTRIBUTE, BATCHER_ORDER_ATTRIBUTE, BATCHER_MINBATCHSIZE_ATTRIBUTE, BATCHER_SKIP_ATTRIBUTE, BATCHER_PROCESS_ATTRIBUTE };
+    private final static String[] BATCHER_OPTIONAL_ATTRIBUTES = { BATCHER_SELECTION_ATTRIBUTE, BATCHER_ORDER_ATTRIBUTE, BATCHER_MINBATCHSIZE_ATTRIBUTE, BATCHER_SKIP_ATTRIBUTE, BATCHER_PROCESS_ATTRIBUTE, BATCHER_EXTRATABLES_ATTRIBUTE };
     private final static String[] BATCHER_SUBNODES = { BATCHER_BATCH_SUBNODE, BATCHER_BATCHLIST_SUBNODE };
 
     private EntityAdapterModel model;
     private String batchDataKey;
     private String batchInfoKey;
+    private String mainTablePrefix;
+    private List extraTables;
     private String definition;
     private String selection;
     private String order;
@@ -848,7 +872,14 @@ public class DefaultProducerNodeBuilders {
       batchSize = XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_BATCHSIZE_ATTRIBUTE, "20" );
       minBatchSize = XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_MINBATCHSIZE_ATTRIBUTE, "0" );
       skip = XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_SKIP_ATTRIBUTE, "0" );
-      process = XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_PROCESS_ATTRIBUTE, "-1" );
+      process = XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_PROCESS_ATTRIBUTE, "-1" );    
+      extraTables = StringRoutines.splitString(XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_EXTRATABLES_ATTRIBUTE,"").trim(), ",");
+      List parts = StringRoutines.splitString(definition.trim()," ");
+      if (parts.size()==1) mainTablePrefix=(String)parts.get(0);
+      if (parts.size()==2) { 
+          mainTablePrefix=(String)parts.get(1);
+          definition=(String)parts.get(0);
+      }
     };
 
     public ProducerNode constructNode() {
@@ -856,6 +887,8 @@ public class DefaultProducerNodeBuilders {
           batchDataKey,
           batchInfoKey,
           model,
+          mainTablePrefix,
+          extraTables,
           definition,
           selection,
           order,
index 757235e..c0caf6d 100755 (executable)
@@ -75,7 +75,7 @@ import com.codestudio.util.SQLManager;
  * Treiber, Host, User und Passwort, ueber den der Zugriff auf die
  * Datenbank erfolgt.
  *
- * @version $Id: Database.java,v 1.44.2.10 2003/11/24 22:02:52 rk Exp $
+ * @version $Id: Database.java,v 1.44.2.11 2003/11/24 23:37:18 rk Exp $
  * @author rk
  *
  */
@@ -580,6 +580,7 @@ public class Database implements StorageObject {
       String aWhereClause, String anOrderByClause,
                        int offset, int limit) throws StorageObjectFailure {
     
+    
     String useTable = theTable;
     String selectStar = "*";
     if (mainTablePrefix!=null && mainTablePrefix.trim().length()>0) {
index d48ed40..71c7cd8 100755 (executable)
-/*\r
- * Copyright (C) 2001, 2002 The Mir-coders group\r
- *\r
- * This file is part of Mir.\r
- *\r
- * Mir is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Mir is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with Mir; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
- *\r
- * In addition, as a special exception, The Mir-coders gives permission to link\r
- * the code of this program with  any library licensed under the Apache Software License,\r
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library\r
- * (or with modified versions of the above that use the same license as the above),\r
- * and distribute linked combinations including the two.  You must obey the\r
- * GNU General Public License in all respects for all of the code used other than\r
- * the above mentioned libraries.  If you modify this file, you may extend this\r
- * exception to your version of the file, but you are not obligated to do so.\r
- * If you do not wish to do so, delete this exception statement from your version.\r
- */\r
-package mircoders.entity;\r
-\r
-import java.sql.SQLException;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import mir.entity.Entity;\r
-import mir.log.LoggerWrapper;\r
-import mir.media.MediaHelper;\r
-import mir.media.MirMedia;\r
-import mir.misc.NumberUtils;\r
-import mir.storage.StorageObject;\r
-import mir.storage.StorageObjectFailure;\r
-import mircoders.storage.DatabaseUploadedMedia;\r
-\r
-/**\r
- *\r
- * @author mh, mir-coders group\r
- * @version $Id: EntityUploadedMedia.java,v 1.26.2.1 2003/09/03 17:49:39 zapata Exp $\r
- */\r
-\r
-\r
-public class EntityUploadedMedia extends Entity {\r
-\r
-\r
-  public EntityUploadedMedia() {\r
-    super();\r
-\r
-    logger = new LoggerWrapper("Entity.UploadedMedia");\r
-  }\r
-\r
-  public EntityUploadedMedia(StorageObject theStorage) {\r
-    this();\r
-    setStorage(theStorage);\r
-  }\r
-\r
-  public void update() throws StorageObjectFailure {\r
-    super.update();\r
-    try {\r
-      theStorageObject.executeUpdate("update content set is_produced='0' where exists(select * from content_x_media where to_content=content.id and to_media=" + getId()+")");\r
-    }\r
-    catch (SQLException e) {\r
-      throwStorageObjectFailure(e, "EntityAudio :: update :: failed!! ");\r
-    }\r
-  }\r
-\r
-  public void setValues(Map theStringValues) {\r
-    if (theStringValues != null) {\r
-      if (!theStringValues.containsKey("is_published"))\r
-        theStringValues.put("is_published", "0");\r
-    }\r
-    super.setValues(theStringValues);\r
-  }\r
-\r
-\r
-  /**\r
-   * fetches the MediaType entry assiciated w/ this media\r
-   *\r
-   * @return mir.entity.Entity\r
-   */\r
-  public Entity getMediaType() throws StorageObjectFailure {\r
-    Entity ent = null;\r
-    try {\r
-      ent = DatabaseUploadedMedia.getInstance().getMediaType(this);\r
-    }\r
-    catch (StorageObjectFailure e) {\r
-      throwStorageObjectFailure(e, "get MediaType failed -- ");\r
-    }\r
-    return ent;\r
-  }\r
-\r
-  public String getValue(String key) {\r
-    String returnValue = null;\r
-\r
-    if (key != null) {\r
-      if (key.equals("big_icon"))\r
-        returnValue = getBigIconName();\r
-      else if (key.equals("descr") || key.equals("media_descr"))\r
-        returnValue = getDescr();\r
-      else if (key.equals("mediatype"))\r
-        returnValue = getMediaTypeString();\r
-      else if (key.equals("mimetype"))\r
-        returnValue = getMimeType();\r
-      else if (key.equals("human_readable_size")) {\r
-        String size = super.getValue("size");\r
-        if (size != null)\r
-          returnValue = NumberUtils.humanReadableSize(Double.parseDouble(size));\r
-      }\r
-      else\r
-        returnValue = super.getValue(key);\r
-    }\r
-    return returnValue;\r
-  }\r
-\r
-  // @todo  all these methods should be merged into 1\r
-  // and the MediaHandler should be cached somehow.\r
-  private String getMediaTypeString() {\r
-    MirMedia mediaHandler = null;\r
-    Entity mediaType = null;\r
-\r
-    try {\r
-      mediaType = getMediaType();\r
-      mediaHandler = MediaHelper.getHandler(mediaType);\r
-      String t;\r
-      if (mediaHandler.isAudio())\r
-        return "audio";\r
-      else if (mediaHandler.isImage())\r
-        return "image";\r
-      else if (mediaHandler.isVideo())\r
-        return "video";\r
-      else\r
-        return "other";\r
-    }\r
-    catch (Exception ex) {\r
-      logger.warn("EntityUploadedMedia.getMediaTypeString: could not fetch data: " + ex.toString());\r
-    }\r
-    return null;\r
-  }\r
-\r
-  private String getBigIconName() {\r
-    MirMedia mediaHandler = null;\r
-    Entity mediaType = null;\r
-\r
-    try {\r
-      mediaType = getMediaType();\r
-      mediaHandler = MediaHelper.getHandler(mediaType);\r
-      return mediaHandler.getBigIconName();\r
-    }\r
-    catch (Exception ex) {\r
-      logger.warn("EntityUploadedMedia.getBigIconName: could not fetch data: " + ex.toString());\r
-    }\r
-    return null;\r
-  }\r
-\r
-  private List getUrl() {\r
-    MirMedia mediaHandler = null;\r
-    Entity mediaType = null;\r
-\r
-    try {\r
-      mediaType = getMediaType();\r
-      mediaHandler = MediaHelper.getHandler(mediaType);\r
-      return mediaHandler.getURL(this, mediaType);\r
-    }\r
-    catch (Throwable t) {\r
-      logger.warn("EntityUploadedMedia.getUrl: could not fetch data: " + t.toString());\r
-    }\r
-    return null;\r
-  }\r
-\r
-  private String getDescr() {\r
-    MirMedia mediaHandler = null;\r
-    Entity mediaType = null;\r
-\r
-    try {\r
-      mediaType = getMediaType();\r
-      mediaHandler = MediaHelper.getHandler(mediaType);\r
-      return mediaHandler.getDescr(mediaType);\r
-    }\r
-    catch (Exception ex) {\r
-      logger.warn("EntityUploadedMedia.getDescr: could not fetch data: " + ex.toString());\r
-    }\r
-    return null;\r
-  }\r
-  private String getMimeType() {\r
-    Entity mediaType = null;\r
-\r
-    try {\r
-      mediaType = getMediaType();\r
-      return mediaType.getValue("mime_type");\r
-    }\r
-    catch (Exception ex) {\r
-      logger.warn("EntityUploadedMedia.getBigIconName: could not fetch data: " + ex.toString());\r
-    }\r
-    return null;\r
-  }\r
-\r
-}\r
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mir is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with  any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two.  You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries.  If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+package mircoders.entity;
+
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Map;
+
+import mir.entity.Entity;
+import mir.log.LoggerWrapper;
+import mir.media.MediaHelper;
+import mir.media.MirMedia;
+import mir.misc.NumberUtils;
+import mir.storage.StorageObject;
+import mir.storage.StorageObjectFailure;
+import mircoders.storage.DatabaseUploadedMedia;
+
+/**
+ *
+ * @author mh, mir-coders group
+ * @version $Id: EntityUploadedMedia.java,v 1.26.2.2 2003/11/24 23:37:18 rk Exp $
+ */
+
+
+public class EntityUploadedMedia extends Entity {
+
+
+  public EntityUploadedMedia() {
+    super();
+
+    logger = new LoggerWrapper("Entity.UploadedMedia");
+  }
+
+  public EntityUploadedMedia(StorageObject theStorage) {
+    this();
+    setStorage(theStorage);
+  }
+
+  public void update() throws StorageObjectFailure {
+    super.update();
+    try {
+      // TODO rewrite as relational sql
+      theStorageObject.executeUpdate("update content set is_produced='0' where exists(select * from content_x_media where to_content=content.id and to_media=" + getId()+")");
+    }
+    catch (SQLException e) {
+      throwStorageObjectFailure(e, "EntityAudio :: update :: failed!! ");
+    }
+  }
+
+  public void setValues(Map theStringValues) {
+    if (theStringValues != null) {
+      if (!theStringValues.containsKey("is_published"))
+        theStringValues.put("is_published", "0");
+    }
+    super.setValues(theStringValues);
+  }
+
+
+  /**
+   * fetches the MediaType entry assiciated w/ this media
+   *
+   * @return mir.entity.Entity
+   */
+  public Entity getMediaType() throws StorageObjectFailure {
+    Entity ent = null;
+    try {
+      ent = DatabaseUploadedMedia.getInstance().getMediaType(this);
+    }
+    catch (StorageObjectFailure e) {
+      throwStorageObjectFailure(e, "get MediaType failed -- ");
+    }
+    return ent;
+  }
+
+  public String getValue(String key) {
+    String returnValue = null;
+
+    if (key != null) {
+      if (key.equals("big_icon"))
+        returnValue = getBigIconName();
+      else if (key.equals("descr") || key.equals("media_descr"))
+        returnValue = getDescr();
+      else if (key.equals("mediatype"))
+        returnValue = getMediaTypeString();
+      else if (key.equals("mimetype"))
+        returnValue = getMimeType();
+      else if (key.equals("human_readable_size")) {
+        String size = super.getValue("size");
+        if (size != null)
+          returnValue = NumberUtils.humanReadableSize(Double.parseDouble(size));
+      }
+      else
+        returnValue = super.getValue(key);
+    }
+    return returnValue;
+  }
+
+  // @todo  all these methods should be merged into 1
+  // and the MediaHandler should be cached somehow.
+  private String getMediaTypeString() {
+    MirMedia mediaHandler = null;
+    Entity mediaType = null;
+
+    try {
+      mediaType = getMediaType();
+      mediaHandler = MediaHelper.getHandler(mediaType);
+      String t;
+      if (mediaHandler.isAudio())
+        return "audio";
+      else if (mediaHandler.isImage())
+        return "image";
+      else if (mediaHandler.isVideo())
+        return "video";
+      else
+        return "other";
+    }
+    catch (Exception ex) {
+      logger.warn("EntityUploadedMedia.getMediaTypeString: could not fetch data: " + ex.toString());
+    }
+    return null;
+  }
+
+  private String getBigIconName() {
+    MirMedia mediaHandler = null;
+    Entity mediaType = null;
+
+    try {
+      mediaType = getMediaType();
+      mediaHandler = MediaHelper.getHandler(mediaType);
+      return mediaHandler.getBigIconName();
+    }
+    catch (Exception ex) {
+      logger.warn("EntityUploadedMedia.getBigIconName: could not fetch data: " + ex.toString());
+    }
+    return null;
+  }
+
+  private List getUrl() {
+    MirMedia mediaHandler = null;
+    Entity mediaType = null;
+
+    try {
+      mediaType = getMediaType();
+      mediaHandler = MediaHelper.getHandler(mediaType);
+      return mediaHandler.getURL(this, mediaType);
+    }
+    catch (Throwable t) {
+      logger.warn("EntityUploadedMedia.getUrl: could not fetch data: " + t.toString());
+    }
+    return null;
+  }
+
+  private String getDescr() {
+    MirMedia mediaHandler = null;
+    Entity mediaType = null;
+
+    try {
+      mediaType = getMediaType();
+      mediaHandler = MediaHelper.getHandler(mediaType);
+      return mediaHandler.getDescr(mediaType);
+    }
+    catch (Exception ex) {
+      logger.warn("EntityUploadedMedia.getDescr: could not fetch data: " + ex.toString());
+    }
+    return null;
+  }
+  private String getMimeType() {
+    Entity mediaType = null;
+
+    try {
+      mediaType = getMediaType();
+      return mediaType.getValue("mime_type");
+    }
+    catch (Exception ex) {
+      logger.warn("EntityUploadedMedia.getBigIconName: could not fetch data: " + ex.toString());
+    }
+    return null;
+  }
+
+}
index 7cb4b7f..8538265 100755 (executable)
@@ -461,7 +461,8 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer {
       topicOrder = aTopicOrder;
     }
 
-        // TODO rewrite as relational select
+        // TODO rewrite as relational select 
+   // take care of topic-condition
     public Object getValue(EntityAdapter anEntityAdapter) {
       try {
         String condition = "exists (select * from content_x_topic where content_id="+anEntityAdapter.get("id")+" and topic_id=id)";
@@ -494,19 +495,13 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer {
 
     public Object getValue(EntityAdapter anEntityAdapter) {
       try {
-        // TODO rewrite as relational select
-        // select * from content where exists 
-        // (select * from content_x_media where content_id="+
-        // anEntityAdapter.get("id")+" and media_id=id)        
         String condition = "cxm.content_id="+ anEntityAdapter.get("id") +
           " and cxm.media_id = m.id";        
-        List extraTables = new Vector();
-        extraTables.add("content_x_media cxm");        
-        // String condition = "exists (select * from content_x_media where content_id="+anEntityAdapter.get("id")+" and media_id=id)";
         if (published)
           condition = "is_published='t' and " + condition;
-        // return anEntityAdapter.getRelation(
-        //    condition, "id", definition);
+
+        List extraTables = new Vector();
+        extraTables.add("content_x_media cxm");        
           
         return anEntityAdapter.getComplexRelation("m", extraTables, condition, "id", definition);
       }
@@ -531,14 +526,16 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer {
 
     public Object getValue(EntityAdapter anEntityAdapter) {
       try {
-               // TODO rewrite as relational select
-        String condition = "exists (select * from comment_x_media where comment_id="+anEntityAdapter.get("id")+" and media_id=id)";
+
+        String condition = "cxm.comment_id="+ anEntityAdapter.get("id") +
+                  " and cxm.media_id = m.id";        
         if (published)
-          condition = "is_published='t' and " + condition;
-        return anEntityAdapter.getRelation(
-           condition,
-          "id",
-          definition);
+           condition = "is_published='t' and " + condition;
+
+        List extraTables = new Vector();
+        extraTables.add("comment_x_media cxm");          
+        return anEntityAdapter.getComplexRelation("m", extraTables, condition, "id", definition);
+
       }
       catch (Throwable t) {
         throw new RuntimeException(t.getMessage());
@@ -637,6 +634,7 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer {
 
     public Object getValue(EntityAdapter anEntityAdapter) {
       try {
+        // TODO rewrite as relational select / very expensive
         String subQuery = "select * from "+table+" where id = media_id";
         if (published)
           subQuery = subQuery + " and is_published='t'";
index 9fcd4a1..99c094c 100755 (executable)
@@ -638,6 +638,7 @@ public class PDFGenerator{
     */
 
    Iterator images = new EntityBrowser(
+      // TODO rewrite as relational select
       DatabaseImages.getInstance(),
        "exists (select * from content_x_media where content_id=" + entityContent.getId() + " and media_id=id)",
        "id desc", 30, -1, 0);
index 4b7e9eb..261ab65 100755 (executable)
@@ -104,6 +104,7 @@ public class PDFPreFormattingProducerNode implements ProducerNode {
       ArrayList brokenUpContent = new ArrayList();
 
       Iterator images = new EntityBrowser(
+         // TODO rewrite as relational sql, see also PDF Generator
          DatabaseImages.getInstance(),
           "exists (select * from content_x_media where content_id=" + entity.getId() + " and media_id=id)",
           "id desc", 30, -1, 0);
index db06146..6005ef6 100755 (executable)
@@ -525,7 +525,7 @@ public abstract class ServletModuleUploadedMedia extends ServletModule {
     if (idParam!=null && !idParam.equals("")) {
       try {
         EntityUploadedMedia entity = (EntityUploadedMedia) mainModule.getById(idParam);
-
+        // TODO rewrite as relational sql
         ServletModuleContent.getInstance().returnList(
             aRequest,
             aResponse,
@@ -544,7 +544,7 @@ public abstract class ServletModuleUploadedMedia extends ServletModule {
     if (idParam!=null && !idParam.equals("")) {
       try {
         EntityUploadedMedia entity = (EntityUploadedMedia) mainModule.getById(idParam);
-
+        // TODO rewrite as relational sql
         ServletModuleComment.getInstance().returnList(
             aRequest,
             aResponse,
index e0424d4..475f208 100755 (executable)
 
 package mircoders.storage;
 
-import java.sql.Connection;\r
-import java.sql.ResultSet;\r
-import java.sql.Statement;\r
-\r
-import mir.entity.EntityList;\r
-import mir.log.LoggerWrapper;\r
-import mir.storage.Database;\r
-import mir.storage.StorageObject;\r
-import mir.storage.StorageObjectExc;\r
-import mir.storage.StorageObjectFailure;\r
-import mircoders.entity.EntityComment;\r
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+
+import mir.entity.EntityList;
+import mir.log.LoggerWrapper;
+import mir.storage.Database;
+import mir.storage.StorageObject;
+import mir.storage.StorageObjectExc;
+import mir.storage.StorageObjectFailure;
+import mircoders.entity.EntityComment;
 import mircoders.entity.EntityUploadedMedia;
 
 /**
  * <b>implements abstract DB connection to the comment_x_media SQL table
  *
  * @author RK, mir-coders group
- * @version $Id: DatabaseCommentToMedia.java,v 1.3.2.1 2003/09/03 17:49:41 zapata Exp $
+ * @version $Id: DatabaseCommentToMedia.java,v 1.3.2.2 2003/11/24 23:37:18 rk Exp $
  *
  */
 
@@ -76,6 +76,7 @@ public class DatabaseCommentToMedia extends Database implements StorageObject{
       StorageObjectExc {
     if (comment != null) {
       try {
+        // TODO make this a count statement
         if (selectByWhereClause("comment_id=" + comment.getId(), -1).size() ==
             0)
           return false;
@@ -102,6 +103,7 @@ public class DatabaseCommentToMedia extends Database implements StorageObject{
   public EntityList getAudio(EntityComment comment) throws StorageObjectFailure {
     EntityList returnList = null;
     if (comment != null) {
+//    TODO rewrite as relational sql
       // get all to_topic from media_x_topic
       String id = comment.getId();
       //this is not supported by mysql
@@ -131,6 +133,7 @@ public class DatabaseCommentToMedia extends Database implements StorageObject{
   public EntityList getVideo(EntityComment comment) throws StorageObjectFailure {
     EntityList returnList = null;
     if (comment != null) {
+//    TODO rewrite as relational sql
       // get all to_topic from media_x_topic
       String id = comment.getId();
       //this is not supported by mysql
@@ -161,6 +164,7 @@ public class DatabaseCommentToMedia extends Database implements StorageObject{
       StorageObjectFailure {
     EntityList returnList = null;
     if (comment != null) {
+//    TODO rewrite as relational sql
       // get all to_topic from media_x_topic
       String id = comment.getId();
       //this is not supported by mysql
@@ -192,6 +196,7 @@ public class DatabaseCommentToMedia extends Database implements StorageObject{
 
     EntityList returnList = null;
     if (comment != null) {
+//    TODO rewrite as relational sql
       // get all to_topic from media_x_topic
       String id = comment.getId();
       //this is not supported by mysql
@@ -223,6 +228,7 @@ public class DatabaseCommentToMedia extends Database implements StorageObject{
 
     EntityList returnList = null;
     if (comment != null) {
+//    TODO rewrite as relational sql
       // get all to_topic from media_x_topic
       String id = comment.getId();
       //this is not supported by mysql
@@ -446,6 +452,7 @@ public class DatabaseCommentToMedia extends Database implements StorageObject{
       StorageObjectFailure {
     EntityList returnList = null;
     if (media != null) {
+      // TODO rewrite as relational sql
       String id = media.getId();
       String select = "select comment_id from " + theTable + " where media_id=" +
           id;
@@ -491,6 +498,7 @@ public class DatabaseCommentToMedia extends Database implements StorageObject{
   public EntityList getComment() throws StorageObjectFailure {
     EntityList returnList = null;
 
+//  TODO rewrite as relational sql
     String select = "select distinct comment_id from " + theTable;
     // execute select statement
     Connection con = null;
index 5f147b6..854af6a 100755 (executable)
 
 package mircoders.storage;
 
-import java.sql.Connection;\r
-import java.sql.ResultSet;\r
-import java.sql.Statement;\r
-\r
-import mir.entity.EntityList;\r
-import mir.log.LoggerWrapper;\r
-import mir.storage.Database;\r
-import mir.storage.StorageObject;\r
-import mir.storage.StorageObjectExc;\r
-import mir.storage.StorageObjectFailure;\r
-import mircoders.entity.EntityContent;\r
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+
+import mir.entity.EntityList;
+import mir.log.LoggerWrapper;
+import mir.storage.Database;
+import mir.storage.StorageObject;
+import mir.storage.StorageObjectExc;
+import mir.storage.StorageObjectFailure;
+import mircoders.entity.EntityContent;
 import mircoders.entity.EntityUploadedMedia;
 
 /**
  * <b>implements abstract DB connection to the content_x_media SQL table
  *
  * @author RK, mir-coders group
- * @version $Id: DatabaseContentToMedia.java,v 1.19.2.1 2003/09/03 17:49:41 zapata Exp $
+ * @version $Id: DatabaseContentToMedia.java,v 1.19.2.2 2003/11/24 23:37:18 rk Exp $
  *
  */
 
@@ -76,6 +76,7 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
       StorageObjectExc {
     if (content != null) {
       try {
+        // TODO make this a count statement
         if (selectByWhereClause("content_id=" + content.getId(), -1).size() ==
             0)
           return false;
@@ -102,6 +103,7 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
   public EntityList getAudio(EntityContent content) throws StorageObjectFailure {
     EntityList returnList = null;
     if (content != null) {
+//    TODO rewrite as relational sql
       // get all to_topic from media_x_topic
       String id = content.getId();
       //this is not supported by mysql
@@ -131,6 +133,7 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
   public EntityList getVideo(EntityContent content) throws StorageObjectFailure {
     EntityList returnList = null;
     if (content != null) {
+//    TODO rewrite as relational sql
       // get all to_topic from media_x_topic
       String id = content.getId();
       //this is not supported by mysql
@@ -161,6 +164,7 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
       StorageObjectFailure {
     EntityList returnList = null;
     if (content != null) {
+//    TODO rewrite as relational sql
       // get all to_topic from media_x_topic
       String id = content.getId();
       //this is not supported by mysql
@@ -192,6 +196,7 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
 
     EntityList returnList = null;
     if (content != null) {
+//    TODO rewrite as relational sql
       // get all to_topic from media_x_topic
       String id = content.getId();
       //this is not supported by mysql
@@ -223,6 +228,7 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
 
     EntityList returnList = null;
     if (content != null) {
+//    TODO rewrite as relational sql
       // get all to_topic from media_x_topic
       String id = content.getId();
       //this is not supported by mysql
@@ -446,6 +452,7 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
       StorageObjectFailure {
     EntityList returnList = null;
     if (media != null) {
+//    TODO rewrite as relational sql
       String id = media.getId();
       String select = "select content_id from " + theTable + " where media_id=" +
           id;
@@ -496,6 +503,7 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
     Connection con = null;
     Statement stmt = null;
     try {
+//    TODO rewrite as relational sql
       con = getPooledCon();
       // should be a preparedStatement because is faster
       stmt = con.createStatement();