2 * put your module comment here
11 import freemarker.template.SimpleList;
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
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>
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.
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....).
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.
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.
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.
53 * The "dcname" field is as of yet unused. Do search for "Dublin Core" on google
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
59 * @author mh <heckmann@hbe.ca>
63 public interface MirMedia{
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
77 public abstract boolean set (byte[] uploadedData, Entity ent,
78 Entity mediaTypeEnt ) throws MirMediaException;
80 public abstract void produce (Entity ent, Entity mediaTypeEnt )
81 throws MirMediaException;
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
91 * @see mir.entity.Entity
93 public abstract byte[] get (Entity ent, Entity mediaTypeEnt)
94 throws MirMediaException;
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
101 * @see mir.entity.Entity
103 public abstract byte[] getIcon (Entity ent) throws MirMediaException;
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
118 public abstract SimpleList getURL (Entity ent, Entity mediaTypeEnt)
119 throws MirMediaException;
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
126 * @return String, the path.
127 * @see mir.misc.MirConfig
129 public abstract String getStoragePath () throws MirMediaException;
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
138 * @return String, the path.
139 * @see mir.misc.MirConfig
141 public abstract String getIconStoragePath () throws MirMediaException;
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
151 * @return String, the base URL to the host.
152 * @see mir.misc.MirConfig
154 public abstract String getPublishHost () throws MirMediaException;
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
162 * @return String, the icon filename.
163 * @see mir.misc.MirConfig
165 public abstract String getBigIcon ();
168 * Returns the file name of the small Icon representing
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
174 * @return String, the icon filename.
175 * @see mir.misc.MirConfig
177 public abstract String getTinyIcon ();
180 * Returns the IMG SRC "ALT" text to be used
181 * for the Icon representations
182 * @return String, the ALT text.
184 public abstract String getIconAlt ();
187 * your can all figure it out.
190 public abstract boolean isVideo ();
193 * you can all figure it out.
196 public abstract boolean isAudio ();
199 * you can all figure it out.
202 public abstract boolean isImage ();
205 * returns a brief text dscription of what this
209 public abstract String getDescr ();