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) throws StorageObjectException
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");
99 public void dettach(String cid,String mid) throws StorageObjectException
103 DatabaseContentToMedia.getInstance().delete(cid,mid);
104 } catch (Exception e){
105 theLog.printError("failed to get instance");
107 //set Content to unproduced
116 public void attach(String mid) throws StorageObjectException
119 //write media-id mid and content-id in table content_x_media
121 DatabaseContentToMedia.getInstance().addMedia(getId(),mid);
122 } catch(StorageObjectException e){
123 theLog.printError("attach: could not get the instance");
125 //set Content to unproduced
128 theLog.printError("EntityContent: attach without mid");
133 * overridden method getValues to include formatted date into every
137 public HashMap getValues() {
138 HashMap returnHash = super.getValues();
141 if ((date=(String)returnHash.get("date"))!=null)
142 returnHash.put("date_formatted", StringUtil.webdbDate2readableDate(date));
143 if ((date=(String)returnHash.get("webdb_create"))!=null)
144 returnHash.put("webdb_create_formatted", StringUtil.dateToReadableDate(date));
145 if ((date=(String)returnHash.get("webdb_lastchange"))!=null)
146 returnHash.put("webdb_lastchange_formatted", StringUtil.dateToReadableDate(date));
151 * overridden method setValues to patch creator_main_url
153 public void setValues(HashMap theStringValues) {
154 if (theStringValues != null) {
155 if (theStringValues.containsKey("creator_main_url")){
156 if (((String)theStringValues.get("creator_main_url")).equalsIgnoreCase("http://")){
157 theStringValues.remove("creator_main_url");
158 } else if (!((String)theStringValues.get("creator_main_url")).startsWith("http://")){
159 theStringValues.put("creator_main_url","http://"+((String)theStringValues.get("creator_main_url")));
163 super.setValues(theStringValues);
167 * return the content_data as string
168 * is obsolete, because content_data is now sql-type text
170 public String getContentData()
172 Connection con=null;Statement stmt=null;
173 byte[] content_data=null;
176 con = theStorageObject.getPooledCon();
177 con.setAutoCommit(false);
178 stmt = con.createStatement();
179 ResultSet rs = theStorageObject.executeSql(stmt,"select content_data from content where id="+getId());
182 content_data = rs.getBytes(1);
187 catch (Exception e) {theLog.printError("EntityContent :: getContent failed! "+e.toString());}
189 try {con.setAutoCommit(true); } catch (Exception e) {;}
190 theStorageObject.freeConnection(con,stmt); }
192 return StringUtil.encodeHtml(StringUtil.unquote( new String(content_data) ));
197 * fetches all the comments belonging to an article
199 * @return freemarker.template.SimpleList
201 public SimpleList getComments() {
202 return ((DatabaseContent)theStorageObject).getComments(this);