public void setProduced(boolean yesno) throws StorageObjectException
{
- Connection con=null;Statement stmt=null;
String value = (yesno) ? "1":"0";
- String sql = "update content set is_produced='" + value + "' where id='" + getId()+"'";
+ if (value.equals( getValue("is_produced") )) return;
+
+ Connection con=null;Statement stmt=null;
+ String sql = "update content set is_produced='" + value + "' where id='" + getId()+"'";
try {
con = theStorageObject.getPooledCon();
/** @todo should be preparedStatement: faster!! */
throw new TemplateModelException(ex.toString());
}
}
- if (key.equals("to_media")) {
+ if (key.equals("to_media_images")) {
+ try {
+ return getImagesForContent();
+ }
+ catch (Exception ex) {
+ theLog.printWarning("-- getImagesForContent: could not fetch data " + ex.toString());
+ throw new TemplateModelException(ex.toString());
+ }
+ }
+ if (key.equals("to_media_audio")) {
+ try {
+ return getAudioForContent();
+ }
+ catch (Exception ex) {
+ theLog.printWarning("-- getAudioForContent: could not fetch data " + ex.toString());
+ throw new TemplateModelException(ex.toString());
+ }
+ }
+ if (key.equals("to_media_video")) {
+ try {
+ return getVideoForContent();
+ }
+ catch (Exception ex) {
+ theLog.printWarning("-- getVideoForContent: could not fetch data " + ex.toString());
+ throw new TemplateModelException(ex.toString());
+ }
+ }
+ if (key.equals("to_media_other")) {
+ try {
+ return getOtherMediaForContent();
+ }
+ catch (Exception ex) {
+ theLog.printWarning("-- getOtherMediaForContent: could not fetch data " + ex.toString());
+ throw new TemplateModelException(ex.toString());
+ }
+ }
+ else if (key.equals("to_media_icon")) {
try {
- return getUploadedMediaForContent();
+ return getUploadedMediaForNewswire();
}
catch (Exception ex) {
- theLog.printWarning("-- getUploadedMediaForContent: could not fetch data " + ex.toString());
+ theLog.printWarning("-- getUploadedMediaForNewswire: could not fetch data " + ex.toString());
throw new TemplateModelException(ex.toString());
}
}
else if (key.equals("to_topics")) {
try {
- HTMLTemplateProcessor.makeSimpleList(DatabaseContentToTopics.getInstance().getTopics(this));
+ DatabaseContentToTopics.getInstance().getTopics(this);
}
catch (Exception ex) {
theLog.printWarning("-- getTopics: could not fetch data " + ex.toString());
throw new TemplateModelException(ex.toString());
}
}
- else return new SimpleScalar(getValue(key));
+ else {
+ return new SimpleScalar(getValue(key));
+ }
}
return null;
*
* @return freemarker.template.SimpleList
*/
- public SimpleList getComments() throws StorageObjectException {
+ private SimpleList getComments() throws StorageObjectException {
return ((DatabaseContent)theStorageObject).getComments(this);
}
- private SimpleList getUploadedMediaForList() throws StorageObjectException
- { return null; }
+ // @todo this needs to optimized. expensive SQL
+ private SimpleHash getUploadedMediaForNewswire()
+ throws StorageObjectException, TemplateModelException
+ {
+ // fetching/setting the images
+ // return to_media_icons
+ String tinyIcon = null, iconAlt = null;
+ MirMedia mediaHandler = null;
+ EntityUploadedMedia uploadedMedia;
+ Entity mediaType;
+ SimpleHash returnHash = new SimpleHash();
+
+ EntityList upMediaEntityList =
+ DatabaseContentToMedia.getInstance().getUploadedMedia(this);
+ if (upMediaEntityList!=null && upMediaEntityList.getCount()>=1) {
+
+ for (int n=0; n < upMediaEntityList.size();n++) {
+ uploadedMedia = (EntityUploadedMedia)upMediaEntityList.elementAt(n);
+ mediaType = uploadedMedia.getMediaType();
+ try {
+ mediaHandler = MediaHelper.getHandler( mediaType );
+ } catch (MirMediaException ex) {
+ throw new TemplateModelException(ex.toString());
+ }
+ //the "best" media type to show
+ if (mediaHandler.isVideo()) {
+ tinyIcon = MirConfig.getProp("Producer.Icon.TinyVideo");
+ iconAlt = "Video";
+ break;
+ } else if (mediaHandler.isAudio()) {
+ tinyIcon = MirConfig.getProp("Producer.Icon.TinyAudio");
+ iconAlt = "Audio";
+ } else if (tinyIcon == null && !mediaHandler.isImage()) {
+ tinyIcon = mediaHandler.getTinyIcon();
+ iconAlt = mediaHandler.getIconAlt();
+ }
+ }
+ //it only has image(s)
+ if (tinyIcon == null) {
+ tinyIcon = MirConfig.getProp("Producer.Icon.TinyImage");
+ iconAlt = "Image";
+ }
+ // uploadedMedia Entity list is empty.
+ // we only have text
+ } else {
+ tinyIcon = MirConfig.getProp("Producer.Icon.TinyText");
+ iconAlt = "Text";
+ }
+ returnHash.put("tiny_icon", mirconf_imageRoot+"/"+tinyIcon);
+ returnHash.put("icon_alt", iconAlt);
+ return returnHash;
+ }
- private SimpleList getUploadedMediaForContent()
+ //######## @todo all of the following getBlahForContent should have
+ // and optimized version where LIMIT=1 sql for list view.
+ private EntityList getImagesForContent()
throws StorageObjectException, TemplateModelException
{
- SimpleList returnList=null;
- EntityList currentMediaList = DatabaseContentToMedia.getInstance().getUploadedMedia(this);
- if (currentMediaList!=null && currentMediaList.getCount()>=1)
- {
- Entity upMedia,mediaType;
- SimpleHash upMediaSimpleHash;
- Class mediaHandlerClass,mediaStorageClass;
- String mediaStorageName,mediaHandlerName=null;
- MirMedia mediaHandler=null;
- Database mediaStorage=null;
-
- returnList = new SimpleList();
-
- for (int n=0; n < currentMediaList.size();n++) {
- upMedia = currentMediaList.elementAt(n);
- upMediaSimpleHash = HTMLTemplateProcessor.makeSimpleHash(upMedia);
- mediaType = ((EntityMedia)upMedia).getMediaType();
- //must be a non-existant to_media_type entry..
- if (mediaType != null) {
- mediaHandlerName = mediaType.getValue("classname");
- mediaStorageName = mediaType.getValue("tablename");
- try {
- mediaStorageClass = Class.forName("mircoders.storage.Database"+mediaStorageName);
- mediaHandlerClass = Class.forName("mir.media.MediaHandler"+mediaHandlerName);
- mediaHandler = (MirMedia)mediaHandlerClass.newInstance();
- Method m = mediaStorageClass.getMethod("getInstance", null);
- mediaStorage = (Database)m.invoke(null, null);
- }
- catch (Exception ex) {
- throw new TemplateModelException(ex.toString());
- }
-
- //we most likely need further info
- upMedia = mediaStorage.selectById(upMedia.getId());
- try {
- upMediaSimpleHash.put("url", mediaHandler.getURL(upMedia, mediaType));
- }
- catch (Exception ex) {
- throw new TemplateModelException(ex.toString());
- }
- upMediaSimpleHash.put("type",mediaType.getValue("classname"));
- returnList.add(upMediaSimpleHash);
- } //end if media_type != null
- } //end for
- } //end if currentMediaList != null
- return returnList;
+ return DatabaseContentToMedia.getInstance().getImages(this);
+ }
+
+ private EntityList getAudioForContent()
+ throws StorageObjectException, TemplateModelException
+ {
+ return DatabaseContentToMedia.getInstance().getAudio(this) ;
+ }
+
+ private EntityList getVideoForContent()
+ throws StorageObjectException, TemplateModelException
+ {
+ return DatabaseContentToMedia.getInstance().getVideo(this) ;
+ }
+
+ private EntityList getOtherMediaForContent()
+ throws StorageObjectException, TemplateModelException
+ {
+ return DatabaseContentToMedia.getInstance().getOther(this);
}
}