7 import java.lang.reflect.*;
13 * This class handles saving, fetching creating representations
14 * for all images. The image content is stored in the DB. The content is
15 * written out to a file at the ProducerImages level.
16 * Remember that Handlers for specific image types, Gif, Jpeg, etc..
18 * It implements the MirMedia interface.
20 * ok. this is a big hack, it's cause putting the image in the DB
21 * and fetching it from the DB needs low level db connections for
22 * some reason. Does anyone know how to get around this?
25 * @see mir.media.MirMedia
31 public class MediaHandlerImages
33 protected final String WEBDB_JPG="0";
34 protected final String WEBDB_GIF="1";
36 protected String imageType="0";
37 private Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+"log/media.log");
39 public byte[] get(Entity ent, Entity mediaTypeEnt) throws MirMediaException
41 byte[] image_data = null;
44 Method method = ent.getClass().getMethod("getImage",null);
45 image_data = (byte[])method.invoke(ent, null);
46 } catch ( NoSuchMethodException e) {
47 theLog.printDebugInfo("method lookup unsuccesful: "+e.toString());
48 throw new MirMediaException(e.toString());
49 } catch ( IllegalAccessException e) {
50 theLog.printDebugInfo("method illegal: "+e.toString());
51 throw new MirMediaException(e.toString());
52 } catch ( InvocationTargetException e) {
53 theLog.printDebugInfo("get: invocation target illegal: "+e.toString());
54 throw new MirMediaException(e.toString());
61 protected boolean set(byte[] uploadData, Entity ent, Entity mediaTypeEnt)
62 throws MirMediaException {
65 Class[] params = {byte[].class, String.class};
66 theLog.printDebugInfo("NAME: "+ent.getClass().getName()+" "+
67 mediaTypeEnt.getClass().getName()+" "+uploadData.length+" "+
69 Method method = ent.getClass().getMethod("setImage",params);
70 method.invoke(ent, new Object[] {uploadData, imageType});
71 } catch ( NoSuchMethodException e) {
72 theLog.printDebugInfo("method lookup unsuccesful: "+e.toString());
73 throw new MirMediaException(e.toString());
74 } catch ( IllegalAccessException e) {
75 theLog.printDebugInfo("method illegal: "+e.toString());
76 throw new MirMediaException(e.toString());
77 } catch ( InvocationTargetException e) {
78 theLog.printDebugInfo("set: invocation target illegal: "+e.toString());
79 throw new MirMediaException(e.toString());
87 public byte[] getIcon(Entity ent) throws MirMediaException
89 byte[] icon_data = null;
92 Method method = ent.getClass().getMethod("getIcon",null);
93 icon_data = (byte[])method.invoke(ent, null);
94 } catch ( NoSuchMethodException e) {
95 theLog.printDebugInfo("method lookup unsuccesful: "+e.toString());
96 throw new MirMediaException(e.toString());
97 } catch ( IllegalAccessException e) {
98 theLog.printDebugInfo("method illegal: "+e.toString());
99 throw new MirMediaException(e.toString());
100 } catch ( InvocationTargetException e) {
101 theLog.printDebugInfo("getIcon: invocation target illegal: "+e.toString());
102 throw new MirMediaException(e.toString());
108 public String getURL(Entity ent, Entity mediaTypeEnt)
110 String title = ent.getValue("title");
111 return StringUtil.createIMGLinks(ent.getValue("publish_server")+
112 ent.getValue("publish_path"), title, ent.getValue("img_height"),
113 ent.getValue("img_width"));
116 public String getListView(Entity ent, Entity mediaTypeEnt)
118 //String title = ent.getValue("title");
119 return StringUtil.createIMGLinks( MirConfig.getProp("Producer.ProductionHost")+
120 ent.getValue("icon_path"), null, ent.getValue("icon_height"),
121 ent.getValue("icon_width"));
124 public String getStoragePath()
126 return MirConfig.getProp("Producer.Image.Path");
129 public String getIconStoragePath()
131 return MirConfig.getProp("Producer.Image.IconPath");
134 public String getPublishHost()
136 return MirConfig.getProp("Producer.Image.Host");
139 public String getTinyIcon ()
141 return MirConfig.getProp("Producer.Icon.TinyImage");
144 public String getBigIcon ()
146 return MirConfig.getProp("Producer.Icon.BigImage");
149 public String getIconAlt ()
154 public boolean isVideo ()
159 public boolean isAudio ()
164 public boolean isImage ()