another media handling merge.
[mir.git] / source / mir / media / MediaHandlerGeneric.java
1 /*
2  * put your module comment here
3  */
4
5
6 package  mir.media;
7
8 import java.util.*;
9
10 import mir.entity.*;
11 import mir.misc.*;
12 import mir.storage.*;
13
14
15 /**
16  * Interfacedefinition für Datenbank-Adpatoren. Die Adaptoren legen
17  * jeweils das Verhalten und die Befehlsmächtigkeit der Datenbank
18  * fest.
19  *
20  * @author <mh>
21  * @version 24.09.2001
22  */
23
24 public class MediaHandlerGeneric implements MirMedia
25 {
26
27     private Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+"log/media.log");
28     public boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt ) {
29         String ext = mediaTypeEnt.getValue("name");
30         String dir = MirConfig.getProp("Producer.Media.Path");
31         String mediaHost = MirConfig.getProp("Producer.Media.Host");
32         String mediaFname = ent.getId()+"."+ext;
33         String date = ent.getValue("date");
34         String datePath = StringUtil.webdbDate2path(date);
35         //hack: make it a config option to use "dated" dirs
36         //we can't cause of stallman -mh
37         //if(FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData)) {
38         if(FileUtil.write(dir+"/"+mediaFname, uploadedData)) {
39             try {
40                 ent.setValueForProperty("is_produced", "1");
41                 ent.setValueForProperty("icon_is_produced", "1");
42                 //hack: make it a config option to use "dated" dirs
43                 //we can't cause of stallman -mh
44                 //ent.setValueForProperty("publish_path",datePath+"/"+mediaFname);
45                 ent.setValueForProperty("publish_path", mediaFname);
46                 ent.setValueForProperty("publish_server", mediaHost);
47                 ent.update();
48             } catch (StorageObjectException e) {
49                 theLog.printError("StorageObjectException: "+e.toString()); 
50                 return false;
51             }
52         } else {
53             theLog.printError("could not write FILE!"); 
54             return false;
55         }
56
57         return true;
58     }
59
60     //a class that will probably never get used..
61     private byte[] getFile (String fileName) {
62         long size = FileUtil.getSize(fileName);
63         if (size < 0) return null;
64
65         byte[] container = new byte[(int)size];
66             
67         if(!FileUtil.read(fileName, container))
68             return null;
69
70         return container;
71     }
72
73     public byte[] get (Entity ent, Entity mediaTypeEnt) {
74         return null;
75     }
76
77     public byte[] getIcon (Entity ent) {
78         String name = "/path/to/some/generic/icon";
79         return getFile(name);
80     }
81
82     public String getStoragePath()
83     {
84         return MirConfig.getProp("Producer.Media.Path");
85     }
86
87     public String getIconStoragePath()
88     {
89         return MirConfig.getProp("Producer.Image.IconPath");
90     }
91
92     public String getPublishHost()
93     {
94         return MirConfig.getProp("Producer.Media.Host");
95     }
96 }
97         
98         
99