--- /dev/null
+package mircoders.entity;
+
+import java.lang.*;
+import java.io.*;
+import java.util.*;
+import java.sql.*;
+
+import freemarker.template.*;
+
+import webdb.entity.*;
+import webdb.misc.*;
+import webdb.storage.*;
+
+import mir.storage.*;
+
+/**
+ * this class implements mapping of one line of the database table content
+ * to a java object
+ *
+ * @author RK
+ * @version 2001
+ */
+
+
+public class EntityContent extends AbstractEntity implements Entity
+{
+
+ private static int instances;
+
+ // constructors
+
+ public EntityContent()
+ {
+ super();
+ instances++;
+ //content_data is now filed-type "text"
+ //streamedInput = new ArrayList();
+ //streamedInput.add("content_data");
+ }
+
+ public EntityContent(StorageObject theStorage) {
+ this();
+ setStorage(theStorage);
+ }
+
+ public void finalize() {
+ instances--;
+ super.finalize();
+ }
+
+ //
+ // methods
+
+ /**
+ * set is_produced flag for the article
+ */
+
+ public void setProduced(boolean yesno)
+ {
+ Connection con=null;Statement stmt=null;
+ String value = (yesno) ? "1":"0";
+ String sql = "update content set is_produced='" + value + "' where id='" + getId()+"'";
+ try {
+ con = theStorageObject.getPooledCon();
+ /** @todo should be preparedStatement: faster!! */
+ stmt = con.createStatement();
+ theStorageObject.executeUpdate(stmt,sql);
+ } catch (StorageObjectException e) {
+ theLog.printDebugInfo(e.toString() + "\n -- set produced failed");
+ } catch (SQLException e) {
+ theLog.printDebugInfo(e.toString() + "\n -- set produced failed");
+ } finally {
+ theStorageObject.freeConnection(con,stmt);
+ }
+ }
+
+
+ /**
+ * make openposting to newswire
+ */
+
+ public void newswire()
+ {
+ 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");
+ } catch (SQLException e) {
+ theLog.printError(e.toString() + "newswire failed");
+ }
+ }
+
+
+ /**
+ * dettach from media
+ */
+
+ public void dettach()
+ {
+ String sql = "update content set to_media=null, is_produced='0' where id='" + getId()+"'";
+ try {
+ theStorageObject.executeUpdate(sql);
+ } catch (StorageObjectException e) {
+ theLog.printError(e.toString() + "dettach failed");
+ } catch (SQLException e) {
+ theLog.printError(e.toString() + "dettach failed");
+ }
+ }
+
+ /**
+ * attach to media
+ */
+
+ public void attach(String mid)
+ {
+ if (mid!=null) {
+ String sql = "update content set to_media='" + mid + "', is_produced='0' where id='" + getId()+"'";
+ try {
+ theStorageObject.executeUpdate(sql);
+ } catch (StorageObjectException e) {
+ theLog.printError(e.toString() + "attach failed");
+ } catch (SQLException e) {
+ theLog.printError(e.toString() + "attach failed");
+ }
+ }
+ else
+ theLog.printError("EntityContent: attach without mid");
+ }
+
+ /**
+ * overridden method getValues 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;
+ }
+
+ /**
+ * overridden method setValues to patch creator_main_url
+ */
+ public void setValues(HashMap 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);
+ }
+
+ /**
+ * return the content_data as string
+ * is obsolete, because content_data is now sql-type text
+
+ public String getContentData()
+ {
+ Connection con=null;Statement stmt=null;
+ byte[] content_data=null;
+
+ try {
+ con = theStorageObject.getPooledCon();
+ con.setAutoCommit(false);
+ stmt = con.createStatement();
+ ResultSet rs = theStorageObject.executeSql(stmt,"select content_data from content where id="+getId());
+ if(rs!=null) {
+ if (rs.next()) {
+ content_data = rs.getBytes(1);
+ }
+ rs.close();
+ }
+ }
+ catch (Exception e) {theLog.printError("EntityContent :: getContent failed! "+e.toString());}
+ finally {
+ try {con.setAutoCommit(true); } catch (Exception e) {;}
+ theStorageObject.freeConnection(con,stmt); }
+
+ return StringUtil.encodeHtml(StringUtil.unquote( new String(content_data) ));
+ }
+*/
+
+ /**
+ * fetches all the comments belonging to an article
+ *
+ * @return freemarker.template.SimpleList
+ */
+ public SimpleList getComments() {
+ return ((DatabaseContent)theStorageObject).getComments(this);
+ }
+
+
+}