bolivian setup seems to work now...
[mir.git] / source / mircoders / entity / adapter / CommentAdapterDefinition.java
1 package mircoders.entity.adapter;
2
3 import mir.entity.*;
4 import mir.entity.adapter.*;
5 import mircoders.storage.*;
6
7 public class CommentAdapterDefinition extends EntityAdapterDefinition {
8   private static CommentAdapterDefinition instance;
9
10   public static CommentAdapterDefinition getInstance() {
11     synchronized (CommentAdapterDefinition.class) {
12       if (instance == null) {
13         instance = new CommentAdapterDefinition();
14       }
15       return instance;
16     }
17   }
18
19   public CommentAdapterDefinition() {
20     super();
21
22     addDBDateField("creationdate", "webdb_create");
23     addDBDateField("changedate", "webdb_lastchange");
24   }
25 }
26
27
28 //  String mirconf_extLinkName  = MirConfig.getProp("Producer.ExtLinkName");
29 //  String mirconf_intLinkName  = MirConfig.getProp("Producer.IntLinkName");
30 //  String mirconf_mailLinkName = MirConfig.getProp("Producer.MailLinkName");
31 //  String mirconf_imageRoot    = MirConfig.getProp("Producer.ImageRoot");
32
33
34 //      if (field.equals("date_formatted"))
35 //      {
36 //                if (hasValueForField("date"))
37 //              returnField = StringUtil.webdbDate2readableDate(getValue("date"));
38 //              }
39 //      else if (field.equals("description_parsed"))
40 //        returnField = getDescriptionParsed();
41 //      else if (field.equals("description_sentence"))
42 //        returnField = getDescriptionSentence();
43 //      else if (field.equals("content_data_parsed"))
44 //        returnField = getContentDataParsed();
45
46
47 //      if (key.equals("to_comments")) {
48 //        try {
49 //          _entCache.put(key, getComments());
50 //          return (TemplateModel)_entCache.get(key);
51 //        } catch (Exception ex) {
52 //          theLog.printWarning("-- getComments: could not fetch data " + ex.toString());
53 //          throw new TemplateModelException(ex.toString());
54 //        }
55 //      }
56 //      if (key.equals("to_media_images")) {
57 //        try {
58 //          _entCache.put(key, getImagesForContent());
59 //          return (TemplateModel)_entCache.get(key);
60 //        }
61 //        catch (Exception ex) {
62 //          theLog.printWarning("-- getImagesForContent: could not fetch data " + ex.toString());
63 //          throw new TemplateModelException(ex.toString());
64 //        }
65 //      }
66 //      if (key.equals("to_media_audio")) {
67 //        try {
68 ////          _entCache.put(key, getAudioForContent());
69 //          return (TemplateModel)_entCache.get(key);
70 //        }
71 //        catch (Exception ex) {
72 //          theLog.printWarning("-- getAudioForContent: could not fetch data " + ex.toString());
73 //          throw new TemplateModelException(ex.toString());
74 //        }
75 //      }
76 //      if (key.equals("to_media_video")) {
77 //        try {
78 //          _entCache.put(key, getVideoForContent());
79 /*          return (TemplateModel)_entCache.get(key);
80         }
81         catch (Exception ex) {
82           theLog.printWarning("-- getVideoForContent: could not fetch data " + ex.toString());
83           throw new TemplateModelException(ex.toString());
84         }
85       }
86       if (key.equals("to_media_other")) {
87         try {
88           _entCache.put(key, getOtherMediaForContent());
89           return (TemplateModel)_entCache.get(key);
90         }
91         catch (Exception ex) {
92           theLog.printWarning("-- getOtherMediaForContent: could not fetch data " + ex.toString());
93           throw new TemplateModelException(ex.toString());
94         }
95       }
96       else if (key.equals("to_media_icon")) {
97         try {
98           _entCache.put(key, getUploadedMediaForNewswire());
99           return (TemplateModel)_entCache.get(key);
100         }
101         catch (Exception ex) {
102           theLog.printWarning("-- getUploadedMediaForNewswire: could not fetch data " + ex.toString());
103           throw new TemplateModelException(ex.toString());
104         }
105       }
106       else if (key.equals("to_topics")) {
107         try {
108           _entCache.put(key,
109                         DatabaseContentToTopics.getInstance().getTopics(this));
110           return (TemplateModel)_entCache.get(key);
111         }
112         catch (Exception ex) {
113           theLog.printWarning("-- getTopics: could not fetch data " + ex.toString());
114           throw new TemplateModelException(ex.toString());
115         }
116       }
117 */
118
119
120
121
122 /*
123   private String getContentDataParsed() {
124     String returnField = getValue("content_data");
125     if (returnField!=null & returnField.length()>0 ) {
126       returnField=StringUtil.deleteForbiddenTags(returnField);
127       //create http-links and email-links
128       if (getValue("is_html").equals("0")) {
129         returnField = StringUtil.createHTML(returnField,mirconf_imageRoot,
130                                             mirconf_mailLinkName,mirconf_extLinkName,
131                                             mirconf_intLinkName);
132       }
133       returnField = StringUtil.decodeHTMLinTags(returnField);
134     }
135     return returnField;
136   }
137
138   private String getDescriptionSentence() {
139     String returnField = getValue("description");
140     if (returnField != null && returnField.length()>0) {
141        returnField = StringUtil.removeHTMLTags(returnField);
142        int endOfFirstSentence=StringUtil.findEndOfSentence(returnField,0);
143        if (endOfFirstSentence > 0){
144          returnField = returnField.substring(0,endOfFirstSentence);
145        }
146     }
147     return returnField;
148   }
149
150   private String getDescriptionParsed() {
151     String returnField = getValue("description");
152     if (returnField != null && returnField.length()>0) {
153       returnField = StringUtil.deleteForbiddenTags(returnField);
154       if (getValue("is_html").equals("0")) {
155         returnField = StringUtil.createHTML(returnField,mirconf_imageRoot,
156                                             mirconf_mailLinkName,mirconf_extLinkName,
157                                             mirconf_intLinkName);
158       }
159       returnField = StringUtil.decodeHTMLinTags(returnField);
160     }
161     return returnField;
162   }
163
164
165         private EntityList getComments() throws StorageObjectException {
166                 return ((DatabaseContent)theStorageObject).getComments(this);
167         }
168
169   // @todo this needs to optimized. expensive SQL
170   private SimpleHash getUploadedMediaForNewswire()
171     throws StorageObjectException, TemplateModelException
172   {
173     // fetching/setting the images
174     // return to_media_icons
175     String        tinyIcon = null, iconAlt = null;
176     MirMedia      mediaHandler = null;
177     EntityUploadedMedia uploadedMedia;
178     Entity        mediaType;
179     SimpleHash    returnHash = new SimpleHash();
180
181     EntityList upMediaEntityList =
182                     DatabaseContentToMedia.getInstance().getUploadedMedia(this);
183     if (upMediaEntityList!=null && upMediaEntityList.getCount()>=1) {
184
185       for (int n=0; n < upMediaEntityList.size();n++) {
186         uploadedMedia = (EntityUploadedMedia)upMediaEntityList.elementAt(n);
187         mediaType = uploadedMedia.getMediaType();
188         try {
189           mediaHandler = MediaHelper.getHandler( mediaType );
190         } catch (MirMediaException ex) {
191           throw new TemplateModelException(ex.toString());
192         }
193         //the "best" media type to show
194         if (mediaHandler.isVideo()) {
195           tinyIcon = MirConfig.getProp("Producer.Icon.TinyVideo");
196           iconAlt = "Video";
197           break;
198         } else if (mediaHandler.isAudio()) {
199           tinyIcon = MirConfig.getProp("Producer.Icon.TinyAudio");
200           iconAlt = "Audio";
201         } else if (tinyIcon == null && !mediaHandler.isImage()) {
202           tinyIcon = mediaHandler.getTinyIcon();
203           iconAlt = mediaHandler.getIconAlt();
204         }
205
206       }
207       //it only has image(s)
208       if (tinyIcon == null) {
209         tinyIcon = MirConfig.getProp("Producer.Icon.TinyImage");
210         iconAlt = "Image";
211       }
212     // uploadedMedia Entity list is empty.
213     // we only have text
214     } else {
215       tinyIcon = MirConfig.getProp("Producer.Icon.TinyText");
216       iconAlt = "Text";
217     }
218     returnHash.put("tiny_icon", mirconf_imageRoot+"/"+tinyIcon);
219     returnHash.put("icon_alt", iconAlt);
220     return returnHash;
221   }
222
223   private boolean hasMedia() throws StorageObjectException
224   {
225     if (_hasMedia == null) {
226       _hasMedia =
227         new Boolean(DatabaseContentToMedia.getInstance().hasMedia(this));
228     }
229     return _hasMedia.booleanValue();
230   }
231
232   //######## @todo all of the following getBlahForContent should have
233   // and optimized version where LIMIT=1 sql for list view.
234   private EntityList getImagesForContent()
235     throws StorageObjectException, TemplateModelException
236   {
237     if (hasMedia())
238       return DatabaseContentToMedia.getInstance().getImages(this);
239     else
240       return null;
241   }
242
243   private EntityList getAudioForContent()
244     throws StorageObjectException, TemplateModelException
245   {
246     if (hasMedia())
247       return DatabaseContentToMedia.getInstance().getAudio(this) ;
248     else
249       return null;
250   }
251
252   private EntityList getVideoForContent()
253     throws StorageObjectException, TemplateModelException
254   {
255     if (hasMedia())
256       return DatabaseContentToMedia.getInstance().getVideo(this) ;
257     else
258       return null;
259   }
260
261   private EntityList getOtherMediaForContent()
262     throws StorageObjectException, TemplateModelException
263   {
264     if (hasMedia())
265       return DatabaseContentToMedia.getInstance().getOther(this);
266     else
267       return null;
268   }
269
270 }
271 */
272
273
274
275
276
277
278
279
280
281
282
283
284 //      if (field.equals("date_formatted"))
285 //      {
286 //                if (hasValueForField("webdb_create"))
287 //                returnField = StringUtil.dateToReadableDate(getValue("webdb_create"));
288
289
290 //      else if (field.equals("description_parsed")) {
291 //        /** @todo the config stuff should be moved to StringUtil */
292 //        String extLinkName = MirConfig.getProp("Producer.ExtLinkName");
293 //        String intLinkName = MirConfig.getProp("Producer.IntLinkName");
294 //        String mailLinkName = MirConfig.getProp("Producer.MailLinkName");
295 //        String imageRoot = MirConfig.getProp("Producer.ImageRoot");
296 //        returnField = StringUtil.createHTML(getValue("description"),imageRoot,mailLinkName,extLinkName,intLinkName);