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 String returnField = null;
133 if (field.equals("date_formatted"))
135 if (hasValueForField("date"))
136 returnField = StringUtil.webdbDate2readableDate(getValue("date"));
138 else if (field.equals("description_parsed"))
139 returnField = getDescriptionParsed();
140 else if (field.equals("content_data_parsed"))
141 returnField = getContentDataParsed();
143 return super.getValue(field);
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 private String getContentDataParsed() {
168 String returnField = getValue("content_data");
169 if (returnField!=null & returnField.length()>0 ) {
170 returnField=StringUtil.deleteForbiddenTags(returnField);
171 //create http-links and email-links
172 if (getValue("is_html").equals("0")) {
173 /** @todo the config stuff should be moved to StringUtil */
174 String extLinkName = MirConfig.getProp("Producer.ExtLinkName");
175 String intLinkName = MirConfig.getProp("Producer.IntLinkName");
176 String mailLinkName = MirConfig.getProp("Producer.MailLinkName");
177 String imageRoot = MirConfig.getProp("Producer.ImageRoot");
178 returnField = StringUtil.createHTML(returnField,imageRoot,mailLinkName,extLinkName,intLinkName);
180 returnField = StringUtil.decodeHTMLinTags(returnField);
186 private String getDescriptionParsed() {
187 String returnField = getValue("description");
188 if (returnField != null && returnField.length()>0) {
189 returnField = StringUtil.deleteForbiddenTags(returnField);
190 if (getValue("is_html").equals("0")) {
191 /** @todo the config stuff should be moved to StringUtil */
192 String extLinkName = MirConfig.getProp("Producer.ExtLinkName");
193 String intLinkName = MirConfig.getProp("Producer.IntLinkName");
194 String mailLinkName = MirConfig.getProp("Producer.MailLinkName");
195 String imageRoot = MirConfig.getProp("Producer.ImageRoot");
196 returnField = StringUtil.createHTML(returnField,imageRoot,mailLinkName,extLinkName,intLinkName);
198 returnField = StringUtil.decodeHTMLinTags(returnField);
204 * fetches all the comments belonging to an article
206 * @return freemarker.template.SimpleList
208 public SimpleList getComments() throws StorageObjectException {
209 return ((DatabaseContent)theStorageObject).getComments(this);