2 package mircoders.media;
7 import java.lang.reflect.*;
9 import freemarker.template.SimpleList;
14 import mir.storage.StorageObjectException;
15 import mircoders.entity.EntityImages;
18 * This class handles saving, fetching creating representations
19 * for all images. The image content is stored in the DB. The content is
20 * written out to a file at the ProducerImages level.
21 * Remember that Handlers for specific image types, Gif, Jpeg, etc..
23 * It implements the MirMedia interface.
25 * slowly starting to look better, a next step would be to have the
26 * representation stuff (WebdbImage) happen here.
29 * @see mir.media.MirMedia
35 public class MediaHandlerImages implements MirMedia
37 private Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+
40 public byte[] get(Entity ent, Entity mediaTypeEnt)
41 throws MirMediaException
43 byte[] image_data = null;
46 image_data = ((EntityImages)ent).getImage();
47 } catch ( StorageObjectException e) {
48 theLog.printDebugInfo("MediaHandlerImages.get: "+e.toString());
49 throw new MirMediaException(e.toString());
55 public boolean set(byte[] uploadData, Entity ent, Entity mediaTypeEnt)
56 throws MirMediaException {
59 ((EntityImages)ent).setImage(uploadData);
60 } catch ( StorageObjectException e) {
61 theLog.printError("MediaHandlerImages.set: "+e.toString());
62 throw new MirMediaException(e.toString());
70 public void produce(Entity ent, Entity mediaTypeEnt) throws MirMediaException
72 String date = ent.getValue("date");
73 String datePath = StringUtil.webdbDate2path(date);
74 String ext = "."+mediaTypeEnt.getValue("name");
75 String filepath = datePath+ent.getId()+ext;
76 String iconFilePath = MirConfig.getProp("Producer.StorageRoot")
77 +getIconStoragePath() + filepath;
78 String productionFilePath = getStoragePath() + "/" + filepath;
81 if (ent.getValue("icon_data")!= null &&
82 ent.getValue("image_data")!= null) {
85 FileUtil.write(iconFilePath,((EntityImages)ent).getIcon());
86 FileUtil.write(productionFilePath,((EntityImages)ent).getImage());
87 ent.setValueForProperty("icon_path",getIconStoragePath()+filepath);
88 ent.setValueForProperty("publish_path",filepath);
90 } catch ( Exception e) {
91 String msg = "MediaHandlerImages.produce - Error: " + e.toString();
92 theLog.printError(msg);
93 throw new MirMediaException(msg);
96 String msg="MediaHandlerImages.produce - missing image or icon OID for: "+
98 theLog.printError(msg);
99 throw new MirMediaException(msg);
104 public byte[] getIcon(Entity ent) throws MirMediaException
106 byte[] icon_data = null;
109 icon_data = ((EntityImages)ent).getIcon();
110 } catch ( StorageObjectException e) {
111 theLog.printDebugInfo("MediaHandlerImages.getIcon: "+e.toString());
112 throw new MirMediaException(e.toString());
118 public SimpleList getURL(Entity ent, Entity mediaTypeEnt)
120 SimpleList theList = new SimpleList();
125 public String getStoragePath()
127 return MirConfig.getProp("Producer.Image.Path");
130 public String getIconStoragePath()
132 return MirConfig.getProp("Producer.Image.IconPath");
135 public String getPublishHost()
137 return MirConfig.getProp("Producer.Image.Host");
140 public String getTinyIcon ()
142 return MirConfig.getProp("Producer.Icon.TinyImage");
145 public String getBigIcon ()
147 return MirConfig.getProp("Producer.Icon.BigImage");
150 public String getIconAlt ()
155 public boolean isVideo ()
160 public boolean isAudio ()
165 public boolean isImage ()
170 public String getDescr()