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