a77ab2e220a47d585240d6bbb469b1f38307dbc2
[mir.git] / source / mir / media / MediaHandler.java
1 /*
2  * Copyright (C) 2001, 2002 The Mir-coders group
3  *
4  * This file is part of Mir.
5  *
6  * Mir is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * Mir is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Mir; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  * In addition, as a special exception, The Mir-coders gives permission to link
21  * the code of this program with  any library licensed under the Apache Software License,
22  * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
23  * (or with modified versions of the above that use the same license as the above),
24  * and distribute linked combinations including the two.  You must obey the
25  * GNU General Public License in all respects for all of the code used other than
26  * the above mentioned libraries.  If you modify this file, you may extend this
27  * exception to your version of the file, but you are not obligated to do so.
28  * If you do not wish to do so, delete this exception statement from your version.
29  */
30 package  mir.media;
31
32 import java.io.InputStream;
33 import java.io.File;
34 import java.util.List;
35
36 import mir.entity.Entity;
37 import mir.session.UploadedFile;
38
39 /**
40  * Interface for Media handling in Mir. All media handlers
41  * must implement this interface. Each specific media type,
42  * be it Gif, Jpeg, Mp3 audio, Real Audio or quicktime video
43  * has special needs when it comes to representation on the various
44  * pages (article, list, summary), must be stored differently and has a
45  * different URL, etc... This interface allows Mir to support
46  * an infinite (I hope) number of media types. Once this is done,
47  * no code at any other level in Mir needs to be changed other than
48  * adding the content-type <-> media handler name mapping in the
49  * media_type table. The following is an example of the media_type
50  * table:
51  * <p>
52  * id |  name   |        mime_type         | classname |   tablename   | dcname<br>
53  *---+---------+--------------------------+-----------+---------------+-------<br>
54  *  2 | unknown | application/octet-stream | --        | UploadedMedia | <br>
55  *  3 | jpg     | image/gif                | ImagesGif | Images        | <br>
56  *  4 | mp3     | audio/mp3                | Audio     | UploadedMedia | <br>
57  * <p>
58  * The "id" field is used as a mapping in the table that contains the media type
59  * to the media_type table. For example, the images table has a to_media_type
60  * field that contains the id in the media_type table.
61  * <p>
62  * The "name" field is used for various display/filenaming purposes. it should
63  * match a valid file extension name for a media_type (we could have used the
64  * content-type map for this....).
65  * <p>
66  * The "mime_type" field is the most important as it does maps the type to Java
67  * classes (the storage and media_handler name). We call those classes using
68  * reflection. This way, once a Handler for a specific media type is implemented
69  * and entered into the media_type table, no other Mir code needs to be modified.
70  * <p>
71  * The "classname" field is the name of the media handler (e.g MediaHandlerAudio)
72  * we use it to call the MediaHandler methods via reflection.
73  * <p>
74  * The "tablename" is the name of the database storage classes (e.g DatabaseImages
75  * and EntityImages). We use this to fetch/storage the media (meta)data in the db.
76  * <p?
77  * The "dcname" field is as of yet unused. Do search for "Dublin Core" on google
78  * to learn more.
79  * <p>
80  * Most media handlers should just extend MediaHandlerGeneric (i.e inherit from
81  * ) and just override the things that need to be specific. see MediaHandlerAudio
82  *
83  * @author <mh@nadir.org>, the Mir-coders group
84  * @version $Id: MediaHandler.java,v 1.1.2.3 2004/11/21 22:07:13 zapata Exp $
85  */
86
87 public interface MediaHandler {
88   /**
89    * Store the media content from an {@link UploadedFile}
90    */
91   public void store(UploadedFile anUploadedFile, Entity aMedia, Entity aMediaType) throws MediaExc, MediaFailure;
92
93   /**
94    * Store the media content from an input stream.
95    */
96   public void store(InputStream anInputStream, Entity aMedia, Entity aMediaType) throws MediaExc, MediaFailure;
97
98   /**
99    * Store the media content from a file.
100    */
101   public void store(File aFile, Entity aMedia, Entity aMediaType) throws MediaExc, MediaFailure;
102
103   /**
104    * Perform production related tasks for this media.  
105    */
106   public void produce(Entity aMedia, Entity aMediaType ) throws MediaExc, MediaFailure;
107
108   /**
109    * Get's the media data from storage and returns it as an InputStream
110    * Not very useful for most media types as they are stored in a file,
111    * but very usefull for ones stored in the DB as it is necessary to get
112    * it first before making a file out of it (in Producer*).
113    */
114   public InputStream getMedia (Entity aMedia, Entity aMediaType) throws MediaExc, MediaFailure;
115
116   /**
117    * Pretty much like get() above. But get's the specific Icon
118    * representation. useful for media stored in the DB.
119    */
120   public InputStream getThumbnail(Entity aMedia) throws MediaExc, MediaFailure;
121
122
123   /**
124    * Returns the mime-type of the media's thumbnail
125    */
126   public String getThumbnailMimeType(Entity aMediaEntity, Entity aMediaType) throws MediaExc, MediaFailure;
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    */
134   public String getStoragePath () throws MediaExc, MediaFailure;
135
136   /**
137    * Returns the *relative* filesystem path to where the media
138    * icon content should be stored. It is relative to the path
139    * returned by getStoragePath()
140    * This path is usually defined
141    * in the configuration wich is accessible through the MirConfig
142    * class.
143    */
144   public String getIconStoragePath () throws MediaExc, MediaFailure;
145
146         /**
147    * Returns the base URL to that the media is accessible from
148    * to the end user. This could be a URL to another host.
149    * This is used in the Metadata stored in the DB and later on
150    * ,the templates use it.
151    * It is usually defined
152    * in the configuration witch is accessible through the MirConfig
153    * class.
154    */
155   public String getPublishHost () throws MediaExc, MediaFailure;
156
157         /**
158    * Returns the file name of the Icon representing the media type.
159    * It is used in the summary view.
160    * It is usually defined
161    * in the configuration wich is accessible through the MirConfig
162    * class.
163    */
164   public String getBigIconName ();
165
166         /**
167    * Returns the file name of the small Icon representing
168    * the media type.
169    * It is used in the right hand newswire list of the startpage.
170    * It is usually defined
171    * in the configuration wich is accessible through the MirConfig
172    * class.
173    */
174   public String getTinyIconName ();
175
176   /**
177    * Returns the IMG SRC "ALT" text to be used
178    * for the Icon representations
179    * @return String, the ALT text.
180    */
181   public String getIconAltName ();
182
183   /**
184    * returns a brief text dscription of what this
185    * media type is.
186    * @return String
187    */
188   public String getDescr (Entity aMediaType);
189
190 }
191
192