neue forms
[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(this.getClass().getName());
38
39         public byte[] get(Entity ent, Entity mediaTypeEnt)
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         } catch ( IllegalAccessException e) {
49             theLog.printDebugInfo("method illegal: "+e.toString()); 
50         } catch ( InvocationTargetException e) {
51             theLog.printDebugInfo("get: invocation target illegal: "+e.toString()); 
52         }
53
54
55         return image_data;
56         }
57
58         protected boolean set(byte[] uploadData, Entity ent, Entity mediaTypeEnt)
59         {
60         try {
61             Class[] params = {byte[].class, String.class};
62             theLog.printDebugInfo("NAME: "+ent.getClass().getName()+" "+
63             mediaTypeEnt.getClass().getName()+" "+uploadData.length+" "+
64             imageType); 
65             Method method = ent.getClass().getMethod("setImage",params);
66             method.invoke(ent, new Object[] {uploadData, imageType});
67         } catch ( NoSuchMethodException e) {
68             theLog.printDebugInfo("method lookup unsuccesful: "+e.toString()); 
69             return false;
70         } catch ( IllegalAccessException e) {
71             theLog.printDebugInfo("method illegal: "+e.toString()); 
72             return false;
73         } catch ( InvocationTargetException e) {
74             theLog.printDebugInfo("set: invocation target illegal: "+e.toString()); 
75             return false;
76         }
77         //deref. -mh
78         uploadData=null;
79
80         return true;
81         }
82
83         public byte[] getIcon(Entity ent)
84         {
85         byte[] icon_data = null;
86
87         try {
88             Method method = ent.getClass().getMethod("getIcon",null);
89             icon_data = (byte[])method.invoke(ent, null);
90         } catch ( NoSuchMethodException e) {
91             theLog.printDebugInfo("method lookup unsuccesful: "+e.toString()); 
92         } catch ( IllegalAccessException e) {
93             theLog.printDebugInfo("method illegal: "+e.toString()); 
94         } catch ( InvocationTargetException e) {
95             theLog.printDebugInfo("getIcon: invocation target illegal: "+e.toString()); 
96         }
97
98         return icon_data;
99     }
100
101     public String getURL(Entity ent, Entity mediaTypeEnt)
102     {
103       String title = ent.getValue("title");
104       return StringUtil.createIMGLinks(ent.getValue("publish_server")+
105         ent.getValue("publish_path"), title, ent.getValue("img_height"),
106         ent.getValue("img_width"));
107     }
108
109     public String getListView(Entity ent, Entity mediaTypeEnt)
110     {
111       //String title = ent.getValue("title");
112       return StringUtil.createIMGLinks( MirConfig.getProp("Producer.ProductionHost")+
113         ent.getValue("icon_path"), null, ent.getValue("icon_height"),
114         ent.getValue("icon_width"));
115     }
116
117     public String getStoragePath()
118     {
119         return MirConfig.getProp("Producer.Image.Path");
120     }
121
122     public String getIconStoragePath()
123     {
124         return MirConfig.getProp("Producer.Image.IconPath");
125     }
126
127     public String getPublishHost()
128     {
129         return MirConfig.getProp("Producer.Image.Host");
130     }
131
132     public String getTinyIcon ()
133     {
134         return MirConfig.getProp("Producer.Icon.TinyImage");
135     } 
136
137     public String getBigIcon ()
138     {
139         return MirConfig.getProp("Producer.Icon.BigImage");
140     } 
141
142     public String getIconAlt ()
143     {
144         return "Image";
145     } 
146
147     public boolean isVideo ()
148     {
149         return false;
150     } 
151
152     public boolean isAudio ()
153     {
154         return false;
155     } 
156
157     public boolean isImage ()
158     {
159         return true;
160     } 
161
162 }