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 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 throwStorageObjectException(e, "\n -- set produced failed");
70 } catch (SQLException e) {
71 throwStorageObjectException(e, "\n -- set produced failed");
73 theStorageObject.freeConnection(con,stmt);
79 * make openposting to newswire
82 public void newswire() throws StorageObjectException
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 throwStorageObjectException(e, "\n -- newswire failed");
89 } catch (SQLException e) {
90 throwStorageObjectException(e, "\n -- newswire failed");
98 public void dettach(String cid,String mid) throws StorageObjectException
102 DatabaseContentToMedia.getInstance().delete(cid,mid);
103 } catch (Exception e){
104 throwStorageObjectException(e, "\n -- failed to get instance");
106 //set Content to unproduced
115 public void attach(String mid) throws StorageObjectException
118 //write media-id mid and content-id in table content_x_media
120 DatabaseContentToMedia.getInstance().addMedia(getId(),mid);
121 } catch(StorageObjectException e){
122 throwStorageObjectException(e, "attach: could not get the instance");
124 //set Content to unproduced
127 theLog.printError("EntityContent: attach without mid");
132 * overridden method getValue to include formatted date into every
136 public String getValue(String field)
138 if (field!=null && field.equals("date_formatted"))
140 if (hasValueForField("date"))
141 return StringUtil.webdbDate2readableDate(getValue("date"));
145 return super.getValue(field);
149 * overridden method setValues to patch creator_main_url
151 public void setValues(HashMap theStringValues) {
152 if (theStringValues != null) {
153 if (theStringValues.containsKey("creator_main_url")){
154 if (((String)theStringValues.get("creator_main_url")).equalsIgnoreCase("http://")){
155 theStringValues.remove("creator_main_url");
156 } else if (!((String)theStringValues.get("creator_main_url")).startsWith("http://")){
157 theStringValues.put("creator_main_url","http://"+((String)theStringValues.get("creator_main_url")));
161 super.setValues(theStringValues);
165 * return the content_data as string
166 * is obsolete, because content_data is now sql-type text
168 public String getContentData()
170 Connection con=null;Statement stmt=null;
171 byte[] content_data=null;
174 con = theStorageObject.getPooledCon();
175 con.setAutoCommit(false);
176 stmt = con.createStatement();
177 ResultSet rs = theStorageObject.executeSql(stmt,"select content_data from content where id="+getId());
180 content_data = rs.getBytes(1);
185 catch (Exception e) {theLog.printError("EntityContent :: getContent failed! "+e.toString());}
187 try {con.setAutoCommit(true); } catch (Exception e) {;}
188 theStorageObject.freeConnection(con,stmt); }
190 return StringUtil.encodeHtml(StringUtil.unquote( new String(content_data) ));
195 * fetches all the comments belonging to an article
197 * @return freemarker.template.SimpleList
199 public SimpleList getComments() throws StorageObjectException {
200 return ((DatabaseContent)theStorageObject).getComments(this);