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 abstract class MediaHandlerImages implements MirMedia
37 static Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+
39 static final String PNG = "PNG";
40 static final String JPEG = "JPEG";
42 abstract String getType();
44 public byte[] get(Entity ent, Entity mediaTypeEnt)
45 throws MirMediaException
47 byte[] image_data = null;
50 image_data = ((EntityImages)ent).getImage();
51 } catch ( StorageObjectException e) {
52 theLog.printDebugInfo("MediaHandlerImages.get: "+e.toString());
53 throw new MirMediaException(e.toString());
59 public boolean set(byte[] uploadData, Entity ent, Entity mediaTypeEnt)
60 throws MirMediaException {
63 ((EntityImages)ent).setImage(uploadData, getType());
64 } catch ( StorageObjectException e) {
65 theLog.printError("MediaHandlerImages.set: "+e.toString());
66 throw new MirMediaException(e.toString());
74 public void produce(Entity ent, Entity mediaTypeEnt) throws MirMediaException
76 String date = ent.getValue("date");
77 String datePath = StringUtil.webdbDate2path(date);
78 String ext = "."+mediaTypeEnt.getValue("name");
79 String filepath = datePath+ent.getId()+ext;
80 String iconFilePath = MirConfig.getProp("Producer.StorageRoot")
81 +getIconStoragePath() + filepath;
82 String productionFilePath = getStoragePath() + "/" + filepath;
85 if (ent.getValue("icon_data")!= null &&
86 ent.getValue("image_data")!= null) {
89 FileUtil.write(iconFilePath,((EntityImages)ent).getIcon());
90 FileUtil.write(productionFilePath,((EntityImages)ent).getImage());
91 ent.setValueForProperty("icon_path",getIconStoragePath()+filepath);
92 ent.setValueForProperty("publish_path",filepath);
94 } catch ( Exception e) {
95 String msg = "MediaHandlerImages.produce - Error: " + e.toString();
96 theLog.printError(msg);
97 throw new MirMediaException(msg);
100 String msg="MediaHandlerImages.produce - missing image or icon OID for: "+
102 theLog.printError(msg);
103 throw new MirMediaException(msg);
108 public byte[] getIcon(Entity ent) throws MirMediaException
110 byte[] icon_data = null;
113 icon_data = ((EntityImages)ent).getIcon();
114 } catch ( StorageObjectException e) {
115 theLog.printDebugInfo("MediaHandlerImages.getIcon: "+e.toString());
116 throw new MirMediaException(e.toString());
122 public SimpleList getURL(Entity ent, Entity mediaTypeEnt)
124 SimpleList theList = new SimpleList();
129 public String getStoragePath()
131 return MirConfig.getProp("Producer.Image.Path");
134 public String getIconStoragePath()
136 return MirConfig.getProp("Producer.Image.IconPath");
139 public String getPublishHost()
141 return MirConfig.getProp("Producer.Image.Host");
144 public String getTinyIcon ()
146 return MirConfig.getProp("Producer.Icon.TinyImage");
149 public String getBigIcon ()
151 return MirConfig.getProp("Producer.Icon.BigImage");
154 public String getIconAlt ()
159 public boolean isVideo ()
164 public boolean isAudio ()
169 public boolean isImage ()
174 public String getDescr(Entity mediaType)