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
30 public EntityContent()
33 //content_data is now filed-type "text"
34 //streamedInput = new ArrayList();
35 //streamedInput.add("content_data");
38 public EntityContent(StorageObject theStorage) {
40 setStorage(theStorage);
47 * set is_produced flag for the article
50 public void setProduced(boolean yesno) throws StorageObjectException
52 Connection con=null;Statement stmt=null;
53 String value = (yesno) ? "1":"0";
54 String sql = "update content set is_produced='" + value + "' where id='" + getId()+"'";
56 con = theStorageObject.getPooledCon();
57 /** @todo should be preparedStatement: faster!! */
58 stmt = con.createStatement();
59 theStorageObject.executeUpdate(stmt,sql);
60 } catch (StorageObjectException e) {
61 throwStorageObjectException(e, "\n -- set produced failed");
62 } catch (SQLException e) {
63 throwStorageObjectException(e, "\n -- set produced failed");
65 theStorageObject.freeConnection(con,stmt);
71 * make openposting to newswire
74 public void newswire() throws StorageObjectException
76 String sql = "update content set to_article_type='1', is_produced='0' where id='" + getId()+"'";
78 theStorageObject.executeUpdate(sql);
79 } catch (StorageObjectException e) {
80 throwStorageObjectException(e, "\n -- newswire failed");
81 } catch (SQLException e) {
82 throwStorageObjectException(e, "\n -- newswire failed");
90 public void dettach(String cid,String mid) throws StorageObjectException
94 DatabaseContentToMedia.getInstance().delete(cid,mid);
95 } catch (Exception e){
96 throwStorageObjectException(e, "\n -- failed to get instance");
98 //set Content to unproduced
107 public void attach(String mid) throws StorageObjectException
110 //write media-id mid and content-id in table content_x_media
112 DatabaseContentToMedia.getInstance().addMedia(getId(),mid);
113 } catch(StorageObjectException e){
114 throwStorageObjectException(e, "attach: could not get the instance");
116 //set Content to unproduced
119 theLog.printError("EntityContent: attach without mid");
124 * overridden method getValue to include formatted date into every
128 public String getValue(String field)
130 if (field!=null && field.equals("date_formatted"))
132 if (hasValueForField("date"))
133 return StringUtil.webdbDate2readableDate(getValue("date"));
137 return super.getValue(field);
141 * overridden method setValues to patch creator_main_url
143 public void setValues(HashMap theStringValues) {
144 if (theStringValues != null) {
145 if (theStringValues.containsKey("creator_main_url")){
146 if (((String)theStringValues.get("creator_main_url")).equalsIgnoreCase("http://")){
147 theStringValues.remove("creator_main_url");
148 } else if (!((String)theStringValues.get("creator_main_url")).startsWith("http://")){
149 theStringValues.put("creator_main_url","http://"+((String)theStringValues.get("creator_main_url")));
153 super.setValues(theStringValues);
157 * return the content_data as string
158 * is obsolete, because content_data is now sql-type text
160 public String getContentData()
162 Connection con=null;Statement stmt=null;
163 byte[] content_data=null;
166 con = theStorageObject.getPooledCon();
167 con.setAutoCommit(false);
168 stmt = con.createStatement();
169 ResultSet rs = theStorageObject.executeSql(stmt,"select content_data from content where id="+getId());
172 content_data = rs.getBytes(1);
177 catch (Exception e) {theLog.printError("EntityContent :: getContent failed! "+e.toString());}
179 try {con.setAutoCommit(true); } catch (Exception e) {;}
180 theStorageObject.freeConnection(con,stmt); }
182 return StringUtil.encodeHtml(StringUtil.unquote( new String(content_data) ));
187 * fetches all the comments belonging to an article
189 * @return freemarker.template.SimpleList
191 public SimpleList getComments() throws StorageObjectException {
192 return ((DatabaseContent)theStorageObject).getComments(this);