fixed / clean ups
[mir.git] / source / mircoders / entity / EntityContent.java
index 3fa7b38..f9c5fdf 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
-\r
-package mircoders.entity;\r
-\r
-import java.sql.Connection;\r
-import java.sql.SQLException;\r
-import java.sql.Statement;\r
-import java.util.Map;\r
-\r
-import mir.entity.Entity;\r
-import mir.log.LoggerWrapper;\r
-import mir.storage.StorageObject;\r
-import mir.storage.StorageObjectFailure;\r
-import mir.util.StringRoutines;\r
-import mircoders.storage.DatabaseContentToMedia;\r
-\r
-/**\r
- * this class implements mapping of one line of the database table content\r
- * to a java object\r
- *\r
- * @version $Id: EntityContent.java,v 1.19.2.3 2003/09/19 23:34:20 zapata Exp $\r
- * @author mir-coders group\r
- *\r
- */\r
-\r
-\r
-public class EntityContent extends Entity\r
-{\r
-  // constructors\r
-\r
-  public EntityContent()\r
-  {\r
-    super();\r
-\r
-    logger = new LoggerWrapper("Entity.Content");\r
-  }\r
-\r
-  public EntityContent(StorageObject theStorage) {\r
-    this();\r
-\r
-    setStorage(theStorage);\r
-  }\r
-\r
-  //\r
-  // methods\r
-\r
-  /**\r
-   * set is_produced flag for the article\r
-   */\r
-\r
-  public void setProduced(boolean yesno) throws StorageObjectFailure\r
-  {\r
-    String value = (yesno) ? "1":"0";\r
-    if (value.equals( getValue("is_produced") )) return;\r
-\r
-    Connection con=null;Statement stmt=null;\r
-    String sql = "update content set is_produced='" + value + "' where id='" + getId()+"'";\r
-    try {\r
-      con = theStorageObject.getPooledCon();\r
-      /** @todo should be preparedStatement: faster!! */\r
-      stmt = con.createStatement();\r
-      theStorageObject.executeUpdate(stmt,sql);\r
-    }\r
-    catch (StorageObjectFailure e) {\r
-      throwStorageObjectFailure(e, "\n -- set produced failed");\r
-    }\r
-    catch (SQLException e) {\r
-      throwStorageObjectFailure(e, "\n -- set produced failed");\r
-    }\r
-    finally {\r
-      theStorageObject.freeConnection(con,stmt);\r
-    }\r
-  }\r
-\r
-  /**\r
-   * Deattaches media from an article\r
-   *\r
-   * @param anArticleId\r
-   * @param aMediaId\r
-   * @throws StorageObjectFailure\r
-   */\r
-  public void dettach(String anArticleId, String aMediaId) throws StorageObjectFailure\r
-  {\r
-    if (aMediaId!=null){\r
-      try{\r
-        DatabaseContentToMedia.getInstance().delete(anArticleId, aMediaId);\r
-      }\r
-      catch (Exception e){\r
-        throwStorageObjectFailure(e, "\n -- failed to get instance");\r
-      }\r
-\r
-      setProduced(false);\r
-    }\r
-  }\r
-\r
-  /**\r
-   * Attaches media to an article\r
-   *\r
-   * @param mid\r
-   * @throws StorageObjectFailure\r
-   */\r
-\r
-  public void attach(String aMediaId) throws StorageObjectFailure\r
-  {\r
-    if (aMediaId!=null) {\r
-      try{\r
-        DatabaseContentToMedia.getInstance().addMedia(getId(),aMediaId);\r
-      }\r
-      catch(StorageObjectFailure e){\r
-        throwStorageObjectFailure(e, "attach: could not get the instance");\r
-      }\r
-      setProduced(false);\r
-    }\r
-    else {\r
-      logger.error("EntityContent: attach without mid");\r
-    }\r
-  }\r
-\r
-  /**\r
-   * overridden method setValues to patch creator_main_url\r
-   */\r
-  public void setValues(Map theStringValues) {\r
-    if (theStringValues != null) {\r
-      if (theStringValues.containsKey("creator_main_url")){\r
-        if (((String)theStringValues.get("creator_main_url")).equalsIgnoreCase("http://")){\r
-          theStringValues.remove("creator_main_url");\r
-        }\r
-        else if (!((String)theStringValues.get("creator_main_url")).startsWith("http://")){\r
-          theStringValues.put("creator_main_url","http://"+((String)theStringValues.get("creator_main_url")));\r
-        }\r
-      }\r
-    }\r
-    super.setValues(theStringValues);\r
-  }\r
-\r
-  public void appendToComments(String aLine) {\r
-    StringBuffer comment = new StringBuffer();\r
-    try {\r
-      comment.append(StringRoutines.interpretAsString(getValue("comment")));\r
-    }\r
-    catch (Throwable t) {\r
-    }\r
-    if (comment.length() > 0 && comment.charAt(comment.length() - 1) != '\n') {\r
-      comment.append('\n');\r
-    }\r
-\r
-    comment.append(aLine);\r
-    setValueForProperty("comment", comment.toString());\r
-  }\r
-\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.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Map;
+
+import mir.entity.AbstractEntity;
+import mir.log.LoggerWrapper;
+import mir.storage.StorageObject;
+import mir.storage.StorageObjectFailure;
+import mircoders.storage.DatabaseContentToMedia;
+
+/**
+ * this class implements mapping of one line of the database table content
+ * to a java object
+ *
+ * @version $Id: EntityContent.java,v 1.19.2.5 2004/01/18 17:30:58 zapata Exp $
+ * @author mir-coders group
+ *
+ */
+
+
+public class EntityContent extends AbstractEntity {
+  // constructors
+
+  public EntityContent()
+  {
+    super();
+
+    logger = new LoggerWrapper("Entity.Content");
+  }
+
+  public EntityContent(StorageObject theStorage) {
+    this();
+
+    setStorage(theStorage);
+  }
+
+  /**
+   * set is_produced flag for the article
+   */
+  public void setProduced(boolean yesno) throws StorageObjectFailure
+  {
+    String value = (yesno) ? "1":"0";
+    if (value.equals( getFieldValue("is_produced") )) return;
+
+    Connection con=null;Statement stmt=null;
+    String sql = "update content set is_produced='" + value + "' where id='" + getId()+"'";
+    try {
+      con = storageObject.getPooledCon();
+      /** todo should be preparedStatement: faster!! */
+      stmt = con.createStatement();
+      storageObject.executeUpdate(stmt,sql);
+    }
+    catch (StorageObjectFailure e) {
+      throw e;
+    }
+    catch (SQLException e) {
+      throw new StorageObjectFailure(e);
+    }
+    finally {
+      storageObject.freeConnection(con,stmt);
+    }
+  }
+
+  /**
+   * Deattaches media from an article
+   *
+   * @param anArticleId
+   * @param aMediaId
+   * @throws StorageObjectFailure
+   */
+  public void dettach(String anArticleId, String aMediaId) throws StorageObjectFailure
+  {
+    if (aMediaId!=null){
+      DatabaseContentToMedia.getInstance().delete(anArticleId, aMediaId);
+
+      setProduced(false);
+    }
+  }
+
+  /**
+   * Attaches media to the article
+   */
+
+  public void attach(String aMediaId) throws StorageObjectFailure
+  {
+    if (aMediaId!=null) {
+      DatabaseContentToMedia.getInstance().addMedia(getId(),aMediaId);
+      setProduced(false);
+    }
+    else {
+      logger.error("EntityContent: attach without mid");
+    }
+  }
+
+  /**
+   * overridden method setValues to patch creator_main_url
+   */
+  public void setValues(Map theStringValues) {
+    if (theStringValues != null) {
+      if (theStringValues.containsKey("creator_main_url")){
+        if (((String)theStringValues.get("creator_main_url")).equalsIgnoreCase("http://")){
+          theStringValues.remove("creator_main_url");
+        }
+        else if (!((String)theStringValues.get("creator_main_url")).startsWith("http://")){
+          theStringValues.put("creator_main_url","http://"+((String)theStringValues.get("creator_main_url")));
+        }
+      }
+    }
+    super.setValues(theStringValues);
+  }
+}