moved media handler implementations to mircoders/media for added flexibility.
[mir.git] / source / mircoders / media / MediaHandlerImages.java
1
2 package mircoders.media;
3
4 import java.lang.*;
5 import java.io.*;
6 import java.util.*;
7 import java.lang.reflect.*;
8
9 import mir.media.*;
10 import mir.misc.*;
11 import mir.entity.*;
12 import mir.storage.StorageObjectException;
13 import mircoders.entity.EntityImages;
14
15 /**
16  * This class handles saving, fetching creating representations
17  * for all images. The image content is stored in the DB. The content is
18  * written out to a file at the ProducerImages level.
19  * Remember that Handlers for specific image types, Gif, Jpeg, etc..
20  * should override it.
21  * It implements the MirMedia interface.
22  * <p>
23  * slowly starting to look better, a next step would be to have the
24  * representation stuff (WebdbImage) happen here.
25  * -mh 01.03.2002
26  *
27  * @see mir.media.MirMedia
28  * @author mh
29  * @version 24.09.2001
30  */
31
32
33 public class MediaHandlerImages implements MirMedia
34 {
35     private Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+
36                                                 "log/media.log");
37
38         public byte[] get(Entity ent, Entity mediaTypeEnt)
39         throws MirMediaException
40         {
41         byte[] image_data = null;
42
43         try {
44             image_data = ((EntityImages)ent).getImage();
45         } catch ( StorageObjectException e) {
46             theLog.printDebugInfo("MediaHandlerImages.get: "+e.toString()); 
47             throw new MirMediaException(e.toString());
48         }
49
50
51         return image_data;
52         }
53
54         public boolean set(byte[] uploadData, Entity ent, Entity mediaTypeEnt)
55             throws MirMediaException {
56
57         try {
58             ((EntityImages)ent).setImage(uploadData);
59         } catch ( StorageObjectException e) {
60             theLog.printDebugInfo("MediaHandlerImages.set: "+e.toString()); 
61             throw new MirMediaException(e.toString());
62         }
63         //deref. -mh
64         uploadData=null;
65
66         return true;
67         }
68
69         public byte[] getIcon(Entity ent) throws MirMediaException
70         {
71         byte[] icon_data = null;
72
73         try {
74             icon_data = ((EntityImages)ent).getIcon();
75         } catch ( StorageObjectException e) {
76             theLog.printDebugInfo("MediaHandlerImages.getIcon: "+e.toString()); 
77             throw new MirMediaException(e.toString());
78         }
79
80         return icon_data;
81     }
82
83     public String getURL(Entity ent, Entity mediaTypeEnt)
84     {
85       String title = ent.getValue("title");
86       return StringUtil.createIMGLinks(ent.getValue("publish_server")+
87         ent.getValue("publish_path"), title, ent.getValue("img_height"),
88         ent.getValue("img_width"));
89     }
90
91     public String getListView(Entity ent, Entity mediaTypeEnt)
92     {
93       //String title = ent.getValue("title");
94       return StringUtil.createIMGLinks( MirConfig.getProp("Producer.ProductionHost")+
95         ent.getValue("icon_path"), null, ent.getValue("icon_height"),
96         ent.getValue("icon_width"));
97     }
98
99     public String getStoragePath()
100     {
101         return MirConfig.getProp("Producer.Image.Path");
102     }
103
104     public String getIconStoragePath()
105     {
106         return MirConfig.getProp("Producer.Image.IconPath");
107     }
108
109     public String getPublishHost()
110     {
111         return MirConfig.getProp("Producer.Image.Host");
112     }
113
114     public String getTinyIcon ()
115     {
116         return MirConfig.getProp("Producer.Icon.TinyImage");
117     } 
118
119     public String getBigIcon ()
120     {
121         return MirConfig.getProp("Producer.Icon.BigImage");
122     } 
123
124     public String getIconAlt ()
125     {
126         return "Image";
127     } 
128
129     public boolean isVideo ()
130     {
131         return false;
132     } 
133
134     public boolean isAudio ()
135     {
136         return false;
137     } 
138
139     public boolean isImage ()
140     {
141         return true;
142     } 
143
144 }