more media handling stuff.
[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.
15  *
16  * ok. this is a big hack, it's cause putting the image in the DB
17  * and fetching it from the DB needs low level db connections for
18  * some reason. -mh 25.09.2001
19  *
20  * @author mh
21  * @version 24.09.2001
22  */
23
24
25 public class MediaHandlerImages
26 {
27     protected final String        WEBDB_JPG="0";
28     protected final String        WEBDB_GIF="1";
29
30     protected String imageType="0";
31     private Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+"log/media.log");
32
33         public byte[] get(Entity ent, Entity mediaTypeEnt)
34         {
35         byte[] image_data = null;
36
37         try {
38             Method method = ent.getClass().getMethod("getImage",null);
39             image_data = (byte[])method.invoke(ent, null);
40         } catch ( NoSuchMethodException e) {
41             theLog.printDebugInfo("method lookup unsuccesful: "+e.toString()); 
42         } catch ( IllegalAccessException e) {
43             theLog.printDebugInfo("method illegal: "+e.toString()); 
44         } catch ( InvocationTargetException e) {
45             theLog.printDebugInfo("invocation target illegal: "+e.toString()); 
46         }
47
48
49         return image_data;
50         }
51
52         protected boolean set(byte[] uploadData, Entity ent, Entity mediaTypeEnt)
53         {
54         try {
55             Class[] params = {byte[].class, String.class};
56             Method method = ent.getClass().getMethod("setImage",params);
57             method.invoke(ent, new Object[] {uploadData, imageType});
58         } catch ( NoSuchMethodException e) {
59             theLog.printDebugInfo("method lookup unsuccesful: "+e.toString()); 
60             return false;
61         } catch ( IllegalAccessException e) {
62             theLog.printDebugInfo("method illegal: "+e.toString()); 
63             return false;
64         } catch ( InvocationTargetException e) {
65             theLog.printDebugInfo("invocation target illegal: "+e.toString()); 
66             return false;
67         }
68         return true;
69         }
70
71         public byte[] getIcon(Entity ent)
72         {
73         byte[] icon_data = null;
74
75         try {
76             Method method = ent.getClass().getMethod("getIcon",null);
77             icon_data = (byte[])method.invoke(ent, null);
78         } catch ( NoSuchMethodException e) {
79             theLog.printDebugInfo("method lookup unsuccesful: "+e.toString()); 
80         } catch ( IllegalAccessException e) {
81             theLog.printDebugInfo("method illegal: "+e.toString()); 
82         } catch ( InvocationTargetException e) {
83             theLog.printDebugInfo("invocation target illegal: "+e.toString()); 
84         }
85
86         return icon_data;
87     }
88
89     public String getStoragePath()
90     {
91         return MirConfig.getProp("Producer.Image.Path");
92     }
93
94     public String getIconStoragePath()
95     {
96         return MirConfig.getProp("Producer.Image.IconPath");
97     }
98
99     public String getPublishHost()
100     {
101         return MirConfig.getProp("Producer.Image.Host");
102     }
103
104     public String getTinyIcon ()
105     {
106         return MirConfig.getProp("Producer.Icon.TinyImage");
107     } 
108
109     public String getIconAlt ()
110     {
111         return "Image";
112     } 
113
114     public boolean isVideo ()
115     {
116         return false;
117     } 
118
119     public boolean isAudio ()
120     {
121         return false;
122     } 
123
124     public boolean isImage ()
125     {
126         return true;
127     } 
128
129 }