2 * Copyright (C) 2001, 2002 The Mir-coders group
4 * This file is part of Mir.
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.
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.
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
20 * In addition, as a special exception, The Mir-coders gives permission to link
21 * the code of this program with the com.oreilly.servlet library, any library
22 * licensed under the Apache Software License, The Sun (tm) Java Advanced
23 * Imaging library (JAI), The Sun JIMI library (or with modified versions of
24 * the above that use the same license as the above), and distribute linked
25 * combinations including the two. You must obey the GNU General Public
26 * License in all respects for all of the code used other than the above
27 * mentioned libraries. If you modify this file, you may extend this exception
28 * to your version of the file, but you are not obligated to do so. If you do
29 * not wish to do so, delete this exception statement from your version.
32 package mircoders.media;
37 import freemarker.template.SimpleList;
46 * This is the Generic MediaHandler. It stores the media data on
47 * the filesystem and keeps basic metadata (size, type...) in the
48 * DB. Usually only representation needs to be overridden.
49 * See the MediaHandlerAudio class to see an example of how one
52 * Most media handlers should override this class.
54 * In theory, it could be used to handle miscellaneous media that
55 * we don't have entered in the media_type table, (like RTF documents,
58 * Of course it implements the MirMedia interface.
60 * @see mir.media.MirMedia
61 * @author mh <heckmann@hbe.ca>
65 public class MediaHandlerGeneric implements MirMedia
67 protected static String imageHost = MirConfig.getProp("Producer.Image.Host");
68 protected static String imageRoot = MirConfig.getProp("Producer.ImageRoot");
69 protected static Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+
71 public void set (InputStream in, Entity ent, Entity mediaTypeEnt )
72 throws MirMediaException {
74 String ext = mediaTypeEnt.getValue("name");
75 String mediaFname = ent.getId()+"."+ext;
76 String date = ent.getValue("date");
77 String datePath = StringUtil.webdbDate2path(date);
79 long size = FileUtil.write(getStoragePath()+"/"+datePath+"/"+
81 ent.setValueForProperty("publish_path",datePath+"/"+mediaFname);
82 ent.setValueForProperty("size", new Long(size).toString());
84 } catch (Exception e) {
85 theLog.printError(e.toString());
86 throw new MirMediaException(e.toString());
91 public void produce (Entity ent, Entity mediaTypeEnt )
92 throws MirMediaException {
94 //check first if the media file exist since produced
95 //location is also the storage location
96 String date = ent.getValue("date");
97 String datePath = StringUtil.webdbDate2path(date);
98 String relPath = datePath+ent.getId()+"."+mediaTypeEnt.getValue("name");
99 String fname = getStoragePath()+relPath;
100 if(! new File(fname).exists())
101 throw new MirMediaException("error in MirMedia.produce(): "+relPath+
106 public InputStream getMedia (Entity ent, Entity mediaTypeEnt)
107 throws MirMediaException {
108 String publishPath = mediaTypeEnt.getValue("publish_path");
109 String fname = getStoragePath()+publishPath;
110 File f = new File(fname);
112 throw new MirMediaException("error in MirMedia.getMedia(): "+fname+
116 in = new FileInputStream(f);
117 } catch (IOException e) {
118 throw new MirMediaException("getMedia(): "+e.toString());
123 public InputStream getIcon (Entity ent) {
127 public String getStoragePath()
129 return MirConfig.getProp("Producer.Media.Path");
132 public String getIconStoragePath()
134 return MirConfig.getProp("Producer.Image.IconPath");
137 public String getPublishHost()
139 return MirConfig.getProp("Producer.Media.Host");
142 public String getTinyIconName()
144 return MirConfig.getProp("Producer.Icon.TinyText");
147 public String getBigIconName()
149 return MirConfig.getProp("Producer.Icon.BigText");
152 public String getIconAltName()
154 return "Generic media";
157 public SimpleList getURL(Entity ent, Entity mediaTypeEnt)
159 SimpleList theList = new SimpleList();
164 public boolean isVideo()
169 public boolean isAudio()
174 public boolean isImage()
179 public String getDescr( Entity mediaType)
181 return mediaType.getValue("mime_type");