Config updated
[mir.git] / source / mircoders / entity / EntityContent.java
index 693afd8..39b0428 100755 (executable)
@@ -22,7 +22,7 @@ import mircoders.storage.*;
  */
 
 
-public class EntityContent extends AbstractEntity implements Entity
+public class EntityContent extends Entity
 {
 
        private static int      instances;
@@ -55,7 +55,7 @@ public class EntityContent extends AbstractEntity implements Entity
        * set is_produced flag for the article
        */
 
-       public void setProduced(boolean yesno)
+       public void setProduced(boolean yesno) throws StorageObjectException
        {
                Connection con=null;Statement stmt=null;
                String value = (yesno) ? "1":"0";
@@ -66,9 +66,9 @@ public class EntityContent extends AbstractEntity implements Entity
                        stmt = con.createStatement();
                        theStorageObject.executeUpdate(stmt,sql);
                } catch (StorageObjectException e) {
-                       theLog.printDebugInfo(e.toString() + "\n -- set produced failed");
+            throwStorageObjectException(e, "\n -- set produced failed");
                } catch (SQLException e) {
-                       theLog.printDebugInfo(e.toString() + "\n -- set produced failed");
+            throwStorageObjectException(e, "\n -- set produced failed");
                } finally {
                        theStorageObject.freeConnection(con,stmt);
                }
@@ -79,15 +79,15 @@ public class EntityContent extends AbstractEntity implements Entity
        * make openposting to newswire
        */
 
-       public void newswire()
+       public void newswire() throws StorageObjectException
        {
                String sql = "update content set to_article_type='1', is_produced='0' where id='" + getId()+"'";
                try {
                                theStorageObject.executeUpdate(sql);
                } catch (StorageObjectException e) {
-                       theLog.printError(e.toString() + "newswire failed");
+            throwStorageObjectException(e, "\n -- newswire failed");
                } catch (SQLException e) {
-                       theLog.printError(e.toString() + "newswire failed");
+            throwStorageObjectException(e, "\n -- newswire failed");
                }
        }
 
@@ -95,14 +95,13 @@ public class EntityContent extends AbstractEntity implements Entity
  /**
        * dettach from media
        */
-
-       public void dettach(String cid,String mid)
+       public void dettach(String cid,String mid) throws StorageObjectException
        {
                if (mid!=null){
                        try{
                                DatabaseContentToMedia.getInstance().delete(cid,mid);
                        } catch (Exception e){
-                               theLog.printError("failed to get instance");
+                throwStorageObjectException(e, "\n -- failed to get instance");
                        }
                        //set Content to unproduced
                        setProduced(false);
@@ -113,14 +112,14 @@ public class EntityContent extends AbstractEntity implements Entity
        * attach to media
        */
 
-       public void attach(String mid)
+       public void attach(String mid) throws StorageObjectException
        {
                if (mid!=null) {
                        //write media-id mid and content-id in table content_x_media
                        try{
                                DatabaseContentToMedia.getInstance().addMedia(getId(),mid);
                        } catch(StorageObjectException e){
-                               theLog.printError("attach: could not get the instance");
+                               throwStorageObjectException(e, "attach: could not get the instance");
                        }
                        //set Content to unproduced
                        setProduced(false);
@@ -130,21 +129,20 @@ public class EntityContent extends AbstractEntity implements Entity
        }
 
        /**
-        * overridden method getValues to include formatted date into every
+        * overridden method getValue to include formatted date into every
         * entityContent
         */
 
-       public HashMap getValues() {
-               HashMap returnHash = super.getValues();
-               String date=null;
-
-               if ((date=(String)returnHash.get("date"))!=null)
-                       returnHash.put("date_formatted", StringUtil.webdbDate2readableDate(date));
-               if ((date=(String)returnHash.get("webdb_create"))!=null)
-                       returnHash.put("webdb_create_formatted", StringUtil.dateToReadableDate(date));
-               if ((date=(String)returnHash.get("webdb_lastchange"))!=null)
-                       returnHash.put("webdb_lastchange_formatted", StringUtil.dateToReadableDate(date));
-               return returnHash;
+       public String getValue(String field)
+  {
+    if (field!=null && field.equals("date_formatted"))
+    {
+               if (hasValueForField("date"))
+       return StringUtil.webdbDate2readableDate(getValue("date"));
+      else return null;
+               }
+    else
+      return super.getValue(field);
        }
 
        /**
@@ -198,7 +196,7 @@ public class EntityContent extends AbstractEntity implements Entity
         *
         * @return freemarker.template.SimpleList
         */
-       public SimpleList getComments() {
+       public SimpleList getComments() throws StorageObjectException {
                return ((DatabaseContent)theStorageObject).getComments(this);
        }