e9535d2eddb7e0bef7c604f6894e6c339836403d
[mir.git] / source / mir / media / MirMedia.java
1 /*
2  * put your module comment here
3  *
4  */
5
6
7 package  mir.media;
8
9 import java.util.*;
10
11 import freemarker.template.SimpleList;
12
13 import mir.entity.*;
14
15 /**
16  * Interface for Media handling in Mir. All media handlers
17  * must implement this interface. Each specific media type,
18  * be it Gif, Jpeg, Mp3 audio, Real Audio or quicktime video
19  * has special needs when it comes to representation on the various
20  * pages (article, list, summary), must be stored differently and has a 
21  * different URL, etc... This interface allows Mir to support 
22  * an infinite (I hope) number of media types. Once this is done,
23  * no code at any other level in Mir needs to be changed other than
24  * adding the content-type <-> media handler name mapping in the
25  * media_type table. The following is an example of the media_type
26  * table:
27  * <p>
28  * id |  name   |        mime_type         | classname |   tablename   | dcname<br>
29  *---+---------+--------------------------+-----------+---------------+-------<br>
30  *  2 | unknown | application/octet-stream | --        | UploadedMedia | <br>
31  *  3 | jpg     | image/gif                | ImagesGif | Images        | <br>
32  *  4 | mp3     | audio/mp3                | Audio     | UploadedMedia | <br>
33  * <p>
34  * The "id" field is used as a mapping in the table that contains the media type
35  * to the media_type table. For example, the images table has a to_media_type
36  * field that contains the id in the media_type table.
37  * <p>
38  * The "name" field is used for various display/filenaming purposes. it should
39  * match a valid file extension name for a media_type (we could have used the
40  * content-type map for this....). 
41  * <p>
42  * The "mime_type" field is the most important as it does maps the type to Java
43  * classes (the storage and media_handler name). We call those classes using
44  * reflection. This way, once a Handler for a specific media type is implemented
45  * and entered into the media_type table, no other Mir code needs to be modified.
46  * <p>
47  * The "classname" field is the name of the media handler (e.g MediaHandlerAudio)
48  * we use it to call the MediaHandler methods via reflection.
49  * <p>
50  * The "tablename" is the name of the database storage classes (e.g DatabaseImages
51  * and EntityImages). We use this to fetch/storage the media (meta)data in the db.
52  * <p?
53  * The "dcname" field is as of yet unused. Do search for "Dublin Core" on google
54  * to learn more.
55  * <p>
56  * Most media handlers should just extend MediaHandlerGeneric (i.e inherit from
57  * ) and just override the things that need to be specific. see MediaHandlerAudio
58  * 
59  * @author mh <heckmann@hbe.ca>
60  * @version 24.09.2001
61  */
62
63 public interface  MirMedia{
64
65   /**
66    * Takes the uploaded media data itself, along with the media Entity
67    * which contains the Media metadata plus the MediaType entity containing
68    * all the info for the specific media type itself. It's job is store the
69    * Media data (content) itself, this could be on the local filesystem, in the
70    * DB or even on a remote host. It then inserts the MetaData in the DB.
71    * @param uploadedData, a byte array containing the uploaded data.
72    * @param ent, an Entity holding the media MetaData
73    * @param mediaType, an Entity holding the media_table entry
74    * @return boolean, success/fail
75    * @see mir.entity.Entity
76    */
77   public abstract boolean set (byte[] uploadedData, Entity ent,
78                                 Entity mediaTypeEnt ) throws MirMediaException;
79
80         public abstract void produce (Entity ent, Entity mediaTypeEnt ) 
81     throws MirMediaException;
82
83   /**
84    * Get's the media data from storage and returns it as a byte array
85    * Not very useful for most media types as they are stored in a file,
86    * but very usefull for ones stored in the DB as it is necessary to get
87    * it first before making a file out of it (in Producer*).
88    * @param ent, an Entity holding the media MetaData
89    * @param mediaType, an Entity holding the media_table entry
90    * @return byte[]
91    * @see mir.entity.Entity
92    */
93   public abstract byte[] get (Entity ent, Entity mediaTypeEnt)
94           throws MirMediaException;
95
96   /**
97    * Pretty much like get() above. But get's the specific Icon
98    * representation. useful for media stored in the DB.
99    * @param ent, an Entity holding the media MetaData
100    * @return byte[]
101    * @see mir.entity.Entity
102    */
103   public abstract byte[] getIcon (Entity ent) throws MirMediaException;
104
105         /**
106    * gets the final content representation for the media
107    * in the form of a URL (String) that allows someone to 
108    * download, look at or listen to the media. (HREF, img src
109    * streaming link, etc..)
110    * It should use the helper functions in the StringUtil class to
111    * build URL's safely, eliminating any *illegal* user input.
112    * @param ent, an Entity holding the media MetaData
113    * @param mediaTypeEnt, an Entity holding the media_table entry
114    * @return String, the url.
115    * @see mir.entity.Entity
116    * @see mir.misc.StringUtil
117    */
118   public abstract SimpleList getURL (Entity ent, Entity mediaTypeEnt)
119     throws MirMediaException;
120
121         /**
122    * Returns the absolute filesystem path to where the media
123    * content should be stored. This path is usually defined
124    * in the configuration wich is accessible through the MirConfig
125    * class.
126    * @return String, the path.
127    * @see mir.misc.MirConfig
128    */
129   public abstract String getStoragePath () throws MirMediaException;
130
131         /**
132    * Returns the *relative* filesystem path to where the media
133    * icon content should be stored. It is relative to the path
134    * returned by getStoragePath()
135    * This path is usually defined
136    * in the configuration wich is accessible through the MirConfig
137    * class.
138    * @return String, the path.
139    * @see mir.misc.MirConfig
140    */
141   public abstract String getIconStoragePath () throws MirMediaException;
142
143         /**
144    * Returns the base URL to that the media is accessible from
145    * to the end user. This could be a URL to another host.
146    * This is used in the Metadata stored in the DB and later on
147    * ,the templates use it.
148    * It is usually defined
149    * in the configuration witch is accessible through the MirConfig
150    * class.
151    * @return String, the base URL to the host.
152    * @see mir.misc.MirConfig
153    */
154   public abstract String getPublishHost () throws MirMediaException;
155
156         /**
157    * Returns the file name of the Icon representing the media type.
158    * It is used in the summary view.
159    * It is usually defined
160    * in the configuration wich is accessible through the MirConfig
161    * class.
162    * @return String, the icon filename.
163    * @see mir.misc.MirConfig
164    */
165   public abstract String getBigIcon ();
166   
167         /**
168    * Returns the file name of the small Icon representing 
169    * the media type.
170    * It is used in the right hand newswire list of the startpage.
171    * It is usually defined
172    * in the configuration wich is accessible through the MirConfig
173    * class.
174    * @return String, the icon filename.
175    * @see mir.misc.MirConfig
176    */
177   public abstract String getTinyIcon ();
178
179         /**
180    * Returns the IMG SRC "ALT" text to be used
181    * for the Icon representations
182    * @return String, the ALT text.
183    */
184   public abstract String getIconAlt ();
185
186         /**
187    * your can all figure it out.
188    * @return boolean.
189    */
190   public abstract boolean isVideo ();
191
192         /**
193    * you can all figure it out.
194    * @return boolean.
195    */
196   public abstract boolean isAudio ();
197
198         /**
199    * you can all figure it out.
200    * @return boolean.
201    */
202   public abstract boolean isImage ();
203
204   /**
205    * returns a brief text dscription of what this
206    * media type is.
207    * @return String
208    */
209   public abstract String getDescr ();
210
211 }
212
213