ProducerList is now converted to the new way to handle media.
[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         //deref. -mh
69         uploadData=null;
70
71         return true;
72         }
73
74         public byte[] getIcon(Entity ent)
75         {
76         byte[] icon_data = null;
77
78         try {
79             Method method = ent.getClass().getMethod("getIcon",null);
80             icon_data = (byte[])method.invoke(ent, null);
81         } catch ( NoSuchMethodException e) {
82             theLog.printDebugInfo("method lookup unsuccesful: "+e.toString()); 
83         } catch ( IllegalAccessException e) {
84             theLog.printDebugInfo("method illegal: "+e.toString()); 
85         } catch ( InvocationTargetException e) {
86             theLog.printDebugInfo("invocation target illegal: "+e.toString()); 
87         }
88
89         return icon_data;
90     }
91
92     public String getURL(Entity ent, Entity mediaTypeEnt)
93     {
94       String title = ent.getValue("title");
95       return StringUtil.createIMGLinks(ent.getValue("publish_server")+
96         ent.getValue("publish_path"), title, ent.getValue("img_height"),
97         ent.getValue("img_width"));
98     }
99
100     public String getListView(Entity ent, Entity mediaTypeEnt)
101     {
102       //String title = ent.getValue("title");
103       return StringUtil.createIMGLinks( MirConfig.getProp("Producer.ProductionHost")+
104         ent.getValue("icon_path"), null, ent.getValue("icon_height"),
105         ent.getValue("icon_width"));
106     }
107
108     public String getStoragePath()
109     {
110         return MirConfig.getProp("Producer.Image.Path");
111     }
112
113     public String getIconStoragePath()
114     {
115         return MirConfig.getProp("Producer.Image.IconPath");
116     }
117
118     public String getPublishHost()
119     {
120         return MirConfig.getProp("Producer.Image.Host");
121     }
122
123     public String getTinyIcon ()
124     {
125         return MirConfig.getProp("Producer.Icon.TinyImage");
126     } 
127
128     public String getBigIcon ()
129     {
130         return MirConfig.getProp("Producer.Icon.BigImage");
131     } 
132
133     public String getIconAlt ()
134     {
135         return "Image";
136     } 
137
138     public boolean isVideo ()
139     {
140         return false;
141     } 
142
143     public boolean isAudio ()
144     {
145         return false;
146     } 
147
148     public boolean isImage ()
149     {
150         return true;
151     } 
152
153 }