2 package mircoders.media;
7 import java.lang.reflect.*;
12 import mir.storage.StorageObjectException;
13 import mircoders.entity.EntityImages;
16 * This class handles saving, fetching creating representations
17 * for all images. The image content is stored in the DB. The content is
18 * written out to a file at the ProducerImages level.
19 * Remember that Handlers for specific image types, Gif, Jpeg, etc..
21 * It implements the MirMedia interface.
23 * slowly starting to look better, a next step would be to have the
24 * representation stuff (WebdbImage) happen here.
27 * @see mir.media.MirMedia
33 public class MediaHandlerImages implements MirMedia
35 private Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+
38 public byte[] get(Entity ent, Entity mediaTypeEnt)
39 throws MirMediaException
41 byte[] image_data = null;
44 image_data = ((EntityImages)ent).getImage();
45 } catch ( StorageObjectException e) {
46 theLog.printDebugInfo("MediaHandlerImages.get: "+e.toString());
47 throw new MirMediaException(e.toString());
53 public boolean set(byte[] uploadData, Entity ent, Entity mediaTypeEnt)
54 throws MirMediaException {
57 ((EntityImages)ent).setImage(uploadData);
58 } catch ( StorageObjectException e) {
59 theLog.printError("MediaHandlerImages.set: "+e.toString());
60 throw new MirMediaException(e.toString());
68 public void produce(Entity ent, Entity mediaTypeEnt) throws MirMediaException
70 String date = ent.getValue("date");
71 String datePath = StringUtil.webdbDate2path(date);
72 String ext = "."+mediaTypeEnt.getValue("name");
73 String filepath = datePath+ent.getId()+ext;
74 String iconFilePath = MirConfig.getProp("Producer.StorageRoot")
75 +getIconStoragePath() + filepath;
76 String productionFilePath = getStoragePath() + "/" + filepath;
79 if (ent.getValue("icon_data")!= null &&
80 ent.getValue("image_data")!= null) {
83 FileUtil.write(iconFilePath,((EntityImages)ent).getIcon());
84 FileUtil.write(productionFilePath,((EntityImages)ent).getImage());
85 ent.setValueForProperty("icon_path",getIconStoragePath()+filepath);
86 ent.setValueForProperty("publish_path",filepath);
87 //ent.setValueForProperty("publish_server", getPublishHost());
88 //ent.setValueForProperty("icon_is_produced","1");
89 //ent.setValueForProperty("is_produced","1");
91 } catch ( Exception e) {
92 String msg = "MediaHandlerImages.produce - Error: " + e.toString();
93 theLog.printError(msg);
94 throw new MirMediaException(msg);
97 String msg="MediaHandlerImages.produce - missing image or icon OID for: "+
99 theLog.printError(msg);
100 throw new MirMediaException(msg);
105 public byte[] getIcon(Entity ent) throws MirMediaException
107 byte[] icon_data = null;
110 icon_data = ((EntityImages)ent).getIcon();
111 } catch ( StorageObjectException e) {
112 theLog.printDebugInfo("MediaHandlerImages.getIcon: "+e.toString());
113 throw new MirMediaException(e.toString());
119 public String getURL(Entity ent, Entity mediaTypeEnt)
121 String title = ent.getValue("title");
122 return StringUtil.createIMGLinks(ent.getValue("publish_server")+
123 ent.getValue("publish_path"), title, ent.getValue("img_height"),
124 ent.getValue("img_width"));
127 public String getListView(Entity ent, Entity mediaTypeEnt)
129 //String title = ent.getValue("title");
130 return StringUtil.createIMGLinks(
131 MirConfig.getProp("Producer.ProductionHost")+ent.getValue("icon_path"),
132 null, ent.getValue("icon_height"), ent.getValue("icon_width"));
135 public String getStoragePath()
137 return MirConfig.getProp("Producer.Image.Path");
140 public String getIconStoragePath()
142 return MirConfig.getProp("Producer.Image.IconPath");
145 public String getPublishHost()
147 return MirConfig.getProp("Producer.Image.Host");
150 public String getTinyIcon ()
152 return MirConfig.getProp("Producer.Icon.TinyImage");
155 public String getBigIcon ()
157 return MirConfig.getProp("Producer.Icon.BigImage");
160 public String getIconAlt ()
165 public boolean isVideo ()
170 public boolean isAudio ()
175 public boolean isImage ()