1.1 restoration
[mir.git] / source / mir / media / MediaHandler.java
index c6d607e..a77ab2e 100755 (executable)
-/*\r
- * Copyright (C) 2001, 2002 The Mir-coders group\r
- *\r
- * This file is part of Mir.\r
- *\r
- * Mir is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Mir is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with Mir; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
- *\r
- * In addition, as a special exception, The Mir-coders gives permission to link\r
- * the code of this program with  any library licensed under the Apache Software License,\r
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library\r
- * (or with modified versions of the above that use the same license as the above),\r
- * and distribute linked combinations including the two.  You must obey the\r
- * GNU General Public License in all respects for all of the code used other than\r
- * the above mentioned libraries.  If you modify this file, you may extend this\r
- * exception to your version of the file, but you are not obligated to do so.\r
- * If you do not wish to do so, delete this exception statement from your version.\r
- */\r
-package  mir.media;\r
-\r
-import java.io.InputStream;\r
-import java.util.List;\r
-\r
-import mir.entity.Entity;\r
-\r
-/**\r
- * Interface for Media handling in Mir. All media handlers\r
- * must implement this interface. Each specific media type,\r
- * be it Gif, Jpeg, Mp3 audio, Real Audio or quicktime video\r
- * has special needs when it comes to representation on the various\r
- * pages (article, list, summary), must be stored differently and has a\r
- * different URL, etc... This interface allows Mir to support\r
- * an infinite (I hope) number of media types. Once this is done,\r
- * no code at any other level in Mir needs to be changed other than\r
- * adding the content-type <-> media handler name mapping in the\r
- * media_type table. The following is an example of the media_type\r
- * table:\r
- * <p>\r
- * id |  name   |        mime_type         | classname |   tablename   | dcname<br>\r
- *---+---------+--------------------------+-----------+---------------+-------<br>\r
- *  2 | unknown | application/octet-stream | --        | UploadedMedia | <br>\r
- *  3 | jpg     | image/gif                | ImagesGif | Images        | <br>\r
- *  4 | mp3     | audio/mp3                | Audio     | UploadedMedia | <br>\r
- * <p>\r
- * The "id" field is used as a mapping in the table that contains the media type\r
- * to the media_type table. For example, the images table has a to_media_type\r
- * field that contains the id in the media_type table.\r
- * <p>\r
- * The "name" field is used for various display/filenaming purposes. it should\r
- * match a valid file extension name for a media_type (we could have used the\r
- * content-type map for this....).\r
- * <p>\r
- * The "mime_type" field is the most important as it does maps the type to Java\r
- * classes (the storage and media_handler name). We call those classes using\r
- * reflection. This way, once a Handler for a specific media type is implemented\r
- * and entered into the media_type table, no other Mir code needs to be modified.\r
- * <p>\r
- * The "classname" field is the name of the media handler (e.g MediaHandlerAudio)\r
- * we use it to call the MediaHandler methods via reflection.\r
- * <p>\r
- * The "tablename" is the name of the database storage classes (e.g DatabaseImages\r
- * and EntityImages). We use this to fetch/storage the media (meta)data in the db.\r
- * <p?\r
- * The "dcname" field is as of yet unused. Do search for "Dublin Core" on google\r
- * to learn more.\r
- * <p>\r
- * Most media handlers should just extend MediaHandlerGeneric (i.e inherit from\r
- * ) and just override the things that need to be specific. see MediaHandlerAudio\r
- *\r
- * @author <mh@nadir.org>, the Mir-coders group\r
- * @version $Id: MediaHandler.java,v 1.1.2.1 2003/12/14 16:37:06 zapata Exp $\r
- */\r
-\r
-public interface MediaHandler {\r
-  /**\r
-   * Takes the uploaded media data itself, along with the media Entity\r
-   * which contains the Media metadata plus the MediaType entity containing\r
-   * all the info for the specific media type itself. It's job is store the\r
-   * Media data (content) itself, this could be on the local filesystem, in the\r
-   * DB or even on a remote host. It then inserts the MetaData in the DB.\r
-   * @param InputStream, a stream of the uploaded data.\r
-   * @param ent, an Entity holding the media MetaData\r
-   * @param mediaType, an Entity holding the media_table entry\r
-   * @return boolean, success/fail\r
-   * @see mir.entity.Entity\r
-   */\r
-  public void store(InputStream in, Entity ent, Entity mediaTypeEnt ) throws MediaExc, MediaFailure;\r
-\r
-  public void produce(Entity ent, Entity mediaTypeEnt ) throws MediaExc, MediaFailure;\r
-  /**\r
-   * Get's the media data from storage and returns it as an InputStream\r
-   * Not very useful for most media types as they are stored in a file,\r
-   * but very usefull for ones stored in the DB as it is necessary to get\r
-   * it first before making a file out of it (in Producer*).\r
-   * @param ent, an Entity holding the media MetaData\r
-   * @param mediaType, an Entity holding the media_table entry\r
-   * @return java.io.InputStream\r
-   * @see mir.entity.Entity\r
-   */\r
-  public InputStream getMedia (Entity ent, Entity mediaTypeEnt) throws MediaExc, MediaFailure;\r
-\r
-  /**\r
-   * Pretty much like get() above. But get's the specific Icon\r
-   * representation. useful for media stored in the DB.\r
-   * @param ent, an Entity holding the media MetaData\r
-   * @return java.io.InputStream\r
-   * @see mir.entity.Entity\r
-   */\r
-  public InputStream getThumbnail(Entity ent) throws MediaExc, MediaFailure;\r
-\r
-\r
-  /**\r
-   *\r
-   * @param ent\r
-   * @return\r
-   * @throws MediaExc\r
-   * @throws MediaFailure\r
-   */\r
-  public String getThumbnailMimeType(Entity aMediaEntity, Entity aMediaType) throws MediaExc, MediaFailure;\r
-\r
-  /**\r
-   * gets the final content representation for the media\r
-   * in the form of a URL (String) that allows someone to\r
-   * download, look at or listen to the media. (HREF, img src\r
-   * streaming link, etc..)\r
-   * It should use the helper functions in the StringUtil class to\r
-   * build URL's safely, eliminating any *illegal* user input.\r
-   * @param ent, an Entity holding the media MetaData\r
-   * @param mediaTypeEnt, an Entity holding the media_table entry\r
-   * @return String, the url.\r
-   * @see mir.entity.Entity\r
-   * @see mir.misc.StringUtil\r
-   */\r
-  public List getURL (Entity ent, Entity mediaTypeEnt) throws MediaExc, MediaFailure;\r
-\r
-        /**\r
-   * Returns the absolute filesystem path to where the media\r
-   * content should be stored. This path is usually defined\r
-   * in the configuration wich is accessible through the MirConfig\r
-   * class.\r
-   * @return String, the path.\r
-   * @see mir.misc.MirConfig\r
-   */\r
-  public String getStoragePath () throws MediaExc, MediaFailure;\r
-\r
-        /**\r
-   * Returns the *relative* filesystem path to where the media\r
-   * icon content should be stored. It is relative to the path\r
-   * returned by getStoragePath()\r
-   * This path is usually defined\r
-   * in the configuration wich is accessible through the MirConfig\r
-   * class.\r
-   * @return String, the path.\r
-   * @see mir.misc.MirConfig\r
-   */\r
-  public String getIconStoragePath () throws MediaExc, MediaFailure;\r
-\r
-        /**\r
-   * Returns the base URL to that the media is accessible from\r
-   * to the end user. This could be a URL to another host.\r
-   * This is used in the Metadata stored in the DB and later on\r
-   * ,the templates use it.\r
-   * It is usually defined\r
-   * in the configuration witch is accessible through the MirConfig\r
-   * class.\r
-   * @return String, the base URL to the host.\r
-   * @see mir.misc.MirConfig\r
-   */\r
-  public String getPublishHost () throws MediaExc, MediaFailure;\r
-\r
-        /**\r
-   * Returns the file name of the Icon representing the media type.\r
-   * It is used in the summary view.\r
-   * It is usually defined\r
-   * in the configuration wich is accessible through the MirConfig\r
-   * class.\r
-   * @return String, the icon filename.\r
-   * @see mir.misc.MirConfig\r
-   */\r
-  public String getBigIconName ();\r
-\r
-        /**\r
-   * Returns the file name of the small Icon representing\r
-   * the media type.\r
-   * It is used in the right hand newswire list of the startpage.\r
-   * It is usually defined\r
-   * in the configuration wich is accessible through the MirConfig\r
-   * class.\r
-   * @return String, the icon filename.\r
-   * @see mir.misc.MirConfig\r
-   */\r
-  public String getTinyIconName ();\r
-\r
-  /**\r
-   * Returns the IMG SRC "ALT" text to be used\r
-   * for the Icon representations\r
-   * @return String, the ALT text.\r
-   */\r
-  public String getIconAltName ();\r
-\r
-  /**\r
-   * returns a brief text dscription of what this\r
-   * media type is.\r
-   * @return String\r
-   */\r
-  public String getDescr (Entity mediaTypeEnt);\r
-\r
-}\r
-\r
-\r
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mir is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with  any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two.  You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries.  If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+package  mir.media;
+
+import java.io.InputStream;
+import java.io.File;
+import java.util.List;
+
+import mir.entity.Entity;
+import mir.session.UploadedFile;
+
+/**
+ * Interface for Media handling in Mir. All media handlers
+ * must implement this interface. Each specific media type,
+ * be it Gif, Jpeg, Mp3 audio, Real Audio or quicktime video
+ * has special needs when it comes to representation on the various
+ * pages (article, list, summary), must be stored differently and has a
+ * different URL, etc... This interface allows Mir to support
+ * an infinite (I hope) number of media types. Once this is done,
+ * no code at any other level in Mir needs to be changed other than
+ * adding the content-type <-> media handler name mapping in the
+ * media_type table. The following is an example of the media_type
+ * table:
+ * <p>
+ * id |  name   |        mime_type         | classname |   tablename   | dcname<br>
+ *---+---------+--------------------------+-----------+---------------+-------<br>
+ *  2 | unknown | application/octet-stream | --        | UploadedMedia | <br>
+ *  3 | jpg     | image/gif                | ImagesGif | Images        | <br>
+ *  4 | mp3     | audio/mp3                | Audio     | UploadedMedia | <br>
+ * <p>
+ * The "id" field is used as a mapping in the table that contains the media type
+ * to the media_type table. For example, the images table has a to_media_type
+ * field that contains the id in the media_type table.
+ * <p>
+ * The "name" field is used for various display/filenaming purposes. it should
+ * match a valid file extension name for a media_type (we could have used the
+ * content-type map for this....).
+ * <p>
+ * The "mime_type" field is the most important as it does maps the type to Java
+ * classes (the storage and media_handler name). We call those classes using
+ * reflection. This way, once a Handler for a specific media type is implemented
+ * and entered into the media_type table, no other Mir code needs to be modified.
+ * <p>
+ * The "classname" field is the name of the media handler (e.g MediaHandlerAudio)
+ * we use it to call the MediaHandler methods via reflection.
+ * <p>
+ * The "tablename" is the name of the database storage classes (e.g DatabaseImages
+ * and EntityImages). We use this to fetch/storage the media (meta)data in the db.
+ * <p?
+ * The "dcname" field is as of yet unused. Do search for "Dublin Core" on google
+ * to learn more.
+ * <p>
+ * Most media handlers should just extend MediaHandlerGeneric (i.e inherit from
+ * ) and just override the things that need to be specific. see MediaHandlerAudio
+ *
+ * @author <mh@nadir.org>, the Mir-coders group
+ * @version $Id: MediaHandler.java,v 1.1.2.3 2004/11/21 22:07:13 zapata Exp $
+ */
+
+public interface MediaHandler {
+  /**
+   * Store the media content from an {@link UploadedFile}
+   */
+  public void store(UploadedFile anUploadedFile, Entity aMedia, Entity aMediaType) throws MediaExc, MediaFailure;
+
+  /**
+   * Store the media content from an input stream.
+   */
+  public void store(InputStream anInputStream, Entity aMedia, Entity aMediaType) throws MediaExc, MediaFailure;
+
+  /**
+   * Store the media content from a file.
+   */
+  public void store(File aFile, Entity aMedia, Entity aMediaType) throws MediaExc, MediaFailure;
+
+  /**
+   * Perform production related tasks for this media.  
+   */
+  public void produce(Entity aMedia, Entity aMediaType ) throws MediaExc, MediaFailure;
+
+  /**
+   * Get's the media data from storage and returns it as an InputStream
+   * Not very useful for most media types as they are stored in a file,
+   * but very usefull for ones stored in the DB as it is necessary to get
+   * it first before making a file out of it (in Producer*).
+   */
+  public InputStream getMedia (Entity aMedia, Entity aMediaType) throws MediaExc, MediaFailure;
+
+  /**
+   * Pretty much like get() above. But get's the specific Icon
+   * representation. useful for media stored in the DB.
+   */
+  public InputStream getThumbnail(Entity aMedia) throws MediaExc, MediaFailure;
+
+
+  /**
+   * Returns the mime-type of the media's thumbnail
+   */
+  public String getThumbnailMimeType(Entity aMediaEntity, Entity aMediaType) throws MediaExc, MediaFailure;
+
+  /**
+   * Returns the absolute filesystem path to where the media
+   * content should be stored. This path is usually defined
+   * in the configuration wich is accessible through the MirConfig
+   * class.
+   */
+  public String getStoragePath () throws MediaExc, MediaFailure;
+
+  /**
+   * Returns the *relative* filesystem path to where the media
+   * icon content should be stored. It is relative to the path
+   * returned by getStoragePath()
+   * This path is usually defined
+   * in the configuration wich is accessible through the MirConfig
+   * class.
+   */
+  public String getIconStoragePath () throws MediaExc, MediaFailure;
+
+        /**
+   * Returns the base URL to that the media is accessible from
+   * to the end user. This could be a URL to another host.
+   * This is used in the Metadata stored in the DB and later on
+   * ,the templates use it.
+   * It is usually defined
+   * in the configuration witch is accessible through the MirConfig
+   * class.
+   */
+  public String getPublishHost () throws MediaExc, MediaFailure;
+
+        /**
+   * Returns the file name of the Icon representing the media type.
+   * It is used in the summary view.
+   * It is usually defined
+   * in the configuration wich is accessible through the MirConfig
+   * class.
+   */
+  public String getBigIconName ();
+
+        /**
+   * Returns the file name of the small Icon representing
+   * the media type.
+   * It is used in the right hand newswire list of the startpage.
+   * It is usually defined
+   * in the configuration wich is accessible through the MirConfig
+   * class.
+   */
+  public String getTinyIconName ();
+
+  /**
+   * Returns the IMG SRC "ALT" text to be used
+   * for the Icon representations
+   * @return String, the ALT text.
+   */
+  public String getIconAltName ();
+
+  /**
+   * returns a brief text dscription of what this
+   * media type is.
+   * @return String
+   */
+  public String getDescr (Entity aMediaType);
+
+}
+
+