package mircoders.entity;
-import java.lang.*;
-import java.io.*;
-import java.util.*;
-import java.sql.*;
-import java.lang.reflect.*;
-
-import freemarker.template.*;
-
-import mir.entity.*;
-import mir.misc.*;
-import mir.media.*;
-import mir.storage.*;
-
-import mircoders.storage.*;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+
+import freemarker.template.SimpleScalar;
+import freemarker.template.TemplateModel;
+import freemarker.template.TemplateModelException;
+
+import mir.log.LoggerWrapper;
+import mir.entity.Entity;
+import mir.entity.EntityList;
+import mir.storage.StorageObject;
+import mir.storage.StorageObjectExc;
+import mir.storage.StorageObjectFailure;
+import mircoders.storage.DatabaseContent;
+import mircoders.storage.DatabaseContentToMedia;
+import mircoders.storage.DatabaseContentToTopics;
/**
* this class implements mapping of one line of the database table content
* to a java object
*
- * @version $Id: EntityContent.java,v 1.13 2002/12/02 12:33:23 zapata Exp $
+ * @version $Id: EntityContent.java,v 1.15 2003/02/23 05:00:13 zapata Exp $
* @author mir-coders group
*
*/
public class EntityContent extends Entity
{
- String mirconf_extLinkName = MirConfig.getProp("Producer.ExtLinkName");
- String mirconf_intLinkName = MirConfig.getProp("Producer.IntLinkName");
- String mirconf_mailLinkName = MirConfig.getProp("Producer.MailLinkName");
- String mirconf_imageRoot = MirConfig.getProp("Producer.ImageRoot");
+ String mirconf_extLinkName = configuration.getString("Producer.ExtLinkName");
+ String mirconf_intLinkName = configuration.getString("Producer.IntLinkName");
+ String mirconf_mailLinkName = configuration.getString("Producer.MailLinkName");
+ String mirconf_imageRoot = configuration.getString("Producer.ImageRoot");
//this should always be transient i.e it can never be stored in the db
//or ObjectStore. (so the ObjectStore should only be caching what comes
public EntityContent()
{
super();
- //content_data is now filed-type "text"
- //streamedInput = new ArrayList();
- //streamedInput.add("content_data");
+
+ logger = new LoggerWrapper("Entity.Content");
}
public EntityContent(StorageObject theStorage) {
* set is_produced flag for the article
*/
- public void setProduced(boolean yesno) throws StorageObjectException
+ public void setProduced(boolean yesno) throws StorageObjectFailure
{
String value = (yesno) ? "1":"0";
if (value.equals( getValue("is_produced") )) return;
stmt = con.createStatement();
theStorageObject.executeUpdate(stmt,sql);
}
- catch (StorageObjectException e) {
- throwStorageObjectException(e, "\n -- set produced failed");
+ catch (StorageObjectFailure e) {
+ throwStorageObjectFailure(e, "\n -- set produced failed");
}
catch (SQLException e) {
- throwStorageObjectException(e, "\n -- set produced failed");
+ throwStorageObjectFailure(e, "\n -- set produced failed");
}
finally {
theStorageObject.freeConnection(con,stmt);
* make openposting to newswire
*/
- public void newswire() throws StorageObjectException
+ public void newswire() throws StorageObjectFailure
{
String sql = "update content set to_article_type='1', is_produced='0' where id='" + getId()+"'";
try {
theStorageObject.executeUpdate(sql);
- } catch (StorageObjectException e) {
- throwStorageObjectException(e, "\n -- newswire failed");
+ } catch (StorageObjectFailure e) {
+ throwStorageObjectFailure(e, "\n -- newswire failed");
} catch (SQLException e) {
- throwStorageObjectException(e, "\n -- newswire failed");
+ throwStorageObjectFailure(e, "\n -- newswire failed");
}
}
/**
* dettach from media
*/
- public void dettach(String cid,String mid) throws StorageObjectException
+ public void dettach(String cid,String mid) throws StorageObjectFailure
{
if (mid!=null){
try{
DatabaseContentToMedia.getInstance().delete(cid,mid);
}
catch (Exception e){
- throwStorageObjectException(e, "\n -- failed to get instance");
+ throwStorageObjectFailure(e, "\n -- failed to get instance");
}
//set Content to unproduced
* attach to media
*/
- public void attach(String mid) throws StorageObjectException
+ public void attach(String mid) throws StorageObjectFailure
{
if (mid!=null) {
//write media-id mid and content-id in table content_x_media
try{
DatabaseContentToMedia.getInstance().addMedia(getId(),mid);
- } catch(StorageObjectException e){
- throwStorageObjectException(e, "attach: could not get the instance");
+ } catch(StorageObjectFailure e){
+ throwStorageObjectFailure(e, "attach: could not get the instance");
}
//set Content to unproduced
setProduced(false);
- } else {
- theLog.printError("EntityContent: attach without mid");
+ }
+ else {
+ logger.error("EntityContent: attach without mid");
}
}
return (TemplateModel)_entCache.get(key);
}
catch (Exception ex) {
- theLog.printWarning("-- getComments: could not fetch data " + ex.toString());
+ logger.warn("EntityContent.getComments: could not fetch data " + ex.toString());
throw new TemplateModelException(ex.toString());
}
return (TemplateModel)_entCache.get(key);
}
catch (Exception ex) {
- theLog.printWarning("-- getImagesForContent: could not fetch data " + ex.toString());
+ logger.warn("EntityContent.getImagesForContent: could not fetch data " + ex.toString());
throw new TemplateModelException(ex.toString());
}
}
return (TemplateModel)_entCache.get(key);
}
catch (Exception ex) {
- theLog.printWarning("-- getAudioForContent: could not fetch data " + ex.toString());
+ logger.warn("EntityContent.getAudioForContent: could not fetch data " + ex.toString());
throw new TemplateModelException(ex.toString());
}
}
return (TemplateModel)_entCache.get(key);
}
catch (Exception ex) {
- theLog.printWarning("-- getVideoForContent: could not fetch data " + ex.toString());
+ logger.warn("EntityContent.getVideoForContent: could not fetch data " + ex.toString());
throw new TemplateModelException(ex.toString());
}
}
return (TemplateModel)_entCache.get(key);
}
catch (Exception ex) {
- theLog.printWarning("-- getOtherMediaForContent: could not fetch data " + ex.toString());
+ logger.warn("EntityContent.getOtherMediaForContent: could not fetch data " + ex.toString());
throw new TemplateModelException(ex.toString());
}
}
return (TemplateModel)_entCache.get(key);
}
catch (Exception ex) {
- theLog.printWarning("-- getTopics: could not fetch data " + ex.toString());
+ logger.warn("EntityContent.getTopics: could not fetch data " + ex.toString());
throw new TemplateModelException(ex.toString());
}
}
*
* @return freemarker.template.SimpleList
*/
- private EntityList getComments() throws StorageObjectException {
+ private EntityList getComments() throws StorageObjectFailure {
return ((DatabaseContent)theStorageObject).getComments(this);
}
- private boolean hasMedia() throws StorageObjectException
+ private boolean hasMedia() throws StorageObjectFailure
{
if (_hasMedia == null) {
- _hasMedia =
- new Boolean(DatabaseContentToMedia.getInstance().hasMedia(this));
+ try {
+ _hasMedia =
+ new Boolean(DatabaseContentToMedia.getInstance().hasMedia(this));
+ } catch (StorageObjectExc e) {
+ throw new StorageObjectFailure(e);
+ }
}
return _hasMedia.booleanValue();
}
//######## @todo all of the following getBlahForContent should have
// and optimized version where LIMIT=1 sql for list view.
private EntityList getImagesForContent()
- throws StorageObjectException, TemplateModelException
+ throws StorageObjectFailure, TemplateModelException
{
if (hasMedia())
return DatabaseContentToMedia.getInstance().getImages(this);
}
private EntityList getAudioForContent()
- throws StorageObjectException, TemplateModelException
+ throws StorageObjectFailure, TemplateModelException
{
if (hasMedia())
return DatabaseContentToMedia.getInstance().getAudio(this) ;
}
private EntityList getVideoForContent()
- throws StorageObjectException, TemplateModelException
+ throws StorageObjectFailure, TemplateModelException
{
if (hasMedia())
return DatabaseContentToMedia.getInstance().getVideo(this) ;
}
private EntityList getOtherMediaForContent()
- throws StorageObjectException, TemplateModelException
+ throws StorageObjectFailure, TemplateModelException
{
if (hasMedia())
return DatabaseContentToMedia.getInstance().getOther(this);