0ee930a783bb8741533e368cbcd568e47ffc509b
[mir.git] / source / mir / media / MediaHandlerImages.java
1
2 package mir.media;
3
4 import java.lang.*;
5 import java.io.*;
6 import java.util.*;
7 import java.lang.reflect.*;
8
9 import mir.misc.*;
10 import mir.entity.*;
11
12 /**
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..
17  * should override it.
18  * It implements the MirMedia interface.
19  * <p>
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?
23  * -mh 25.09.2001
24  *
25  * @see mir.media.MirMedia
26  * @author mh
27  * @version 24.09.2001
28  */
29
30
31 public class MediaHandlerImages
32 {
33     protected final String        WEBDB_JPG="0";
34     protected final String        WEBDB_GIF="1";
35
36     protected String imageType="0";
37     private Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+"log/media.log");
38
39         public byte[] get(Entity ent, Entity mediaTypeEnt) throws MirMediaException
40         {
41         byte[] image_data = null;
42
43         try {
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());
55         }
56
57
58         return image_data;
59         }
60
61         protected boolean set(byte[] uploadData, Entity ent, Entity mediaTypeEnt)
62             throws MirMediaException {
63
64         try {
65             Class[] params = {byte[].class, String.class};
66             theLog.printDebugInfo("NAME: "+ent.getClass().getName()+" "+
67             mediaTypeEnt.getClass().getName()+" "+uploadData.length+" "+
68             imageType); 
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());
80         }
81         //deref. -mh
82         uploadData=null;
83
84         return true;
85         }
86
87         public byte[] getIcon(Entity ent) throws MirMediaException
88         {
89         byte[] icon_data = null;
90
91         try {
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());
103         }
104
105         return icon_data;
106     }
107
108     public String getURL(Entity ent, Entity mediaTypeEnt)
109     {
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"));
114     }
115
116     public String getListView(Entity ent, Entity mediaTypeEnt)
117     {
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"));
122     }
123
124     public String getStoragePath()
125     {
126         return MirConfig.getProp("Producer.Image.Path");
127     }
128
129     public String getIconStoragePath()
130     {
131         return MirConfig.getProp("Producer.Image.IconPath");
132     }
133
134     public String getPublishHost()
135     {
136         return MirConfig.getProp("Producer.Image.Host");
137     }
138
139     public String getTinyIcon ()
140     {
141         return MirConfig.getProp("Producer.Icon.TinyImage");
142     } 
143
144     public String getBigIcon ()
145     {
146         return MirConfig.getProp("Producer.Icon.BigImage");
147     } 
148
149     public String getIconAlt ()
150     {
151         return "Image";
152     } 
153
154     public boolean isVideo ()
155     {
156         return false;
157     } 
158
159     public boolean isAudio ()
160     {
161         return false;
162     } 
163
164     public boolean isImage ()
165     {
166         return true;
167     } 
168
169 }