neue forms
[mir.git] / source / mir / media / MediaHandlerRealVideo.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 /**
17  * Handles real video.  like MediaHandlerAudio, except it manages the ram file, too.  
18  *
19  * @see mir.media.MediaHandlerGeneric
20  * @see mir.media.MirMedia
21  * @author john <john@manifestor.org>
22  * @version 11.10.2001
23  */
24
25
26 public class MediaHandlerRealVideo extends MediaHandlerGeneric implements MirMedia
27 {
28
29     private String imageHost = MirConfig.getProp("Producer.Image.Host");
30     private static String imageRoot = MirConfig.getProp("Producer.ImageRoot");
31     private Logfile theLog = Logfile.getInstance(this.getClass().getName());
32     public boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt ) {
33         String ext = mediaTypeEnt.getValue("name");
34         String dir = MirConfig.getProp("Producer.Media.Path");
35         String rtspDir = MirConfig.getProp("Producer.RealMedia.Path");
36         String mediaHost = MirConfig.getProp("Producer.Media.Host");
37         String rtspMediaHost = MirConfig.getProp("Producer.RealMedia.Host");
38
39         String mediaFname = ent.getId()+"."+ext;
40         String RealMediaPointer = rtspMediaHost+mediaFname;
41         String RealMediaFile = ent.getId()+".ram";
42         String date = ent.getValue("date");
43         String datePath = StringUtil.webdbDate2path(date);
44         Integer size = new Integer(uploadedData.length);
45         if(FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData)) {
46         //if(FileUtil.write(rtspDir+"/"+mediaFname, uploadedData)) {
47             //were done with the data, dereference.
48             uploadedData=null;
49             
50             try {
51 //write an rm file
52 FileUtil.write(dir+"/"+RealMediaFile,RealMediaPointer.getBytes());
53
54                 ent.setValueForProperty("is_produced", "1");
55                 ent.setValueForProperty("icon_is_produced", "1");
56                 ent.setValueForProperty("publish_path",datePath+"/"+mediaFname);
57                 //ent.setValueForProperty("publish_path", RealMediaFile);
58                 ent.setValueForProperty("publish_server", mediaHost);
59                 ent.setValueForProperty("size", size.toString());
60                 ent.update();
61             } catch (StorageObjectException e) {
62                 theLog.printError("StorageObjectException: "+e.toString()); 
63                 return false;
64             }
65         } else {
66             theLog.printError("could not write FILE!"); 
67             return false;
68         }
69
70         return true;
71     }
72
73
74
75
76
77     public String getPublishHost()
78     {
79         return MirConfig.getProp("Producer.Media.Host");
80     }
81
82
83
84     public String getURL(Entity ent, Entity mediaTypeEnt)
85     {
86       int size = Integer.parseInt(ent.getValue("size"), 10)/1024;
87       String title = ent.getValue("title")+
88         " - "+mediaTypeEnt.getValue("name")+" "+
89         size+" KB";
90       return StringUtil.createURLLinks(ent.getValue("publish_server")+"/"+
91         ent.getValue("publish_path"), title, imageRoot, getBigIcon());
92     }
93
94    
95     private static String tinyIcon = MirConfig.getProp("Producer.Icon.TinyVideo");
96     private static String bigIcon = MirConfig.getProp("Producer.Icon.BigVideo");
97
98   public String getTinyIcon()
99   {
100     return tinyIcon;
101   }
102
103   public String getBigIcon()
104   {
105     return bigIcon;
106   }
107
108   public String getIconAlt()
109   {
110     return "Video";
111   }
112
113   public boolean isVideo()
114   {
115     return true;
116   }
117
118 }
119         
120         
121