1 package mircoders.entity;
8 import freemarker.template.*;
14 import mircoders.storage.*;
17 * this class implements mapping of one line of the database table content
25 public class EntityContent extends AbstractEntity implements Entity
28 private static int instances;
32 public EntityContent()
36 //content_data is now filed-type "text"
37 //streamedInput = new ArrayList();
38 //streamedInput.add("content_data");
41 public EntityContent(StorageObject theStorage) {
43 setStorage(theStorage);
46 public void finalize() {
55 * set is_produced flag for the article
58 public void setProduced(boolean yesno)
60 Connection con=null;Statement stmt=null;
61 String value = (yesno) ? "1":"0";
62 String sql = "update content set is_produced='" + value + "' where id='" + getId()+"'";
64 con = theStorageObject.getPooledCon();
65 /** @todo should be preparedStatement: faster!! */
66 stmt = con.createStatement();
67 theStorageObject.executeUpdate(stmt,sql);
68 } catch (StorageObjectException e) {
69 theLog.printDebugInfo(e.toString() + "\n -- set produced failed");
70 } catch (SQLException e) {
71 theLog.printDebugInfo(e.toString() + "\n -- set produced failed");
73 theStorageObject.freeConnection(con,stmt);
79 * make openposting to newswire
82 public void newswire()
84 String sql = "update content set to_article_type='1', is_produced='0' where id='" + getId()+"'";
86 theStorageObject.executeUpdate(sql);
87 } catch (StorageObjectException e) {
88 theLog.printError(e.toString() + "newswire failed");
89 } catch (SQLException e) {
90 theLog.printError(e.toString() + "newswire failed");
101 String sql = "update content set to_media=null, is_produced='0' where id='" + getId()+"'";
103 theStorageObject.executeUpdate(sql);
104 } catch (StorageObjectException e) {
105 theLog.printError(e.toString() + "dettach failed");
106 } catch (SQLException e) {
107 theLog.printError(e.toString() + "dettach failed");
115 public void attach(String mid)
118 String sql = "update content set to_media='" + mid + "', is_produced='0' where id='" + getId()+"'";
120 theStorageObject.executeUpdate(sql);
121 } catch (StorageObjectException e) {
122 theLog.printError(e.toString() + "attach failed");
123 } catch (SQLException e) {
124 theLog.printError(e.toString() + "attach failed");
128 theLog.printError("EntityContent: attach without mid");
132 * overridden method getValues to include formatted date into every
136 public HashMap getValues() {
137 HashMap returnHash = super.getValues();
140 if ((date=(String)returnHash.get("date"))!=null)
141 returnHash.put("date_formatted", StringUtil.webdbDate2readableDate(date));
142 if ((date=(String)returnHash.get("webdb_create"))!=null)
143 returnHash.put("webdb_create_formatted", StringUtil.dateToReadableDate(date));
144 if ((date=(String)returnHash.get("webdb_lastchange"))!=null)
145 returnHash.put("webdb_lastchange_formatted", StringUtil.dateToReadableDate(date));
150 * overridden method setValues to patch creator_main_url
152 public void setValues(HashMap theStringValues) {
153 if (theStringValues != null) {
154 if (theStringValues.containsKey("creator_main_url")){
155 if (((String)theStringValues.get("creator_main_url")).equalsIgnoreCase("http://")){
156 theStringValues.remove("creator_main_url");
157 } else if (!((String)theStringValues.get("creator_main_url")).startsWith("http://")){
158 theStringValues.put("creator_main_url","http://"+((String)theStringValues.get("creator_main_url")));
162 super.setValues(theStringValues);
166 * return the content_data as string
167 * is obsolete, because content_data is now sql-type text
169 public String getContentData()
171 Connection con=null;Statement stmt=null;
172 byte[] content_data=null;
175 con = theStorageObject.getPooledCon();
176 con.setAutoCommit(false);
177 stmt = con.createStatement();
178 ResultSet rs = theStorageObject.executeSql(stmt,"select content_data from content where id="+getId());
181 content_data = rs.getBytes(1);
186 catch (Exception e) {theLog.printError("EntityContent :: getContent failed! "+e.toString());}
188 try {con.setAutoCommit(true); } catch (Exception e) {;}
189 theStorageObject.freeConnection(con,stmt); }
191 return StringUtil.encodeHtml(StringUtil.unquote( new String(content_data) ));
196 * fetches all the comments belonging to an article
198 * @return freemarker.template.SimpleList
200 public SimpleList getComments() {
201 return ((DatabaseContent)theStorageObject).getComments(this);