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.
33 package mircoders.media;
36 import java.io.InputStream;
38 import mir.config.MirPropertiesConfiguration;
39 import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;
40 import mir.entity.Entity;
41 import mir.media.MirMedia;
42 import mir.media.MirMediaException;
43 import mir.misc.FileUtil;
44 import mir.misc.Logfile;
45 import mir.misc.StringUtil;
46 import mir.storage.StorageObjectFailure;
47 import mircoders.entity.EntityImages;
48 import freemarker.template.SimpleList;
51 * This class handles saving, fetching creating representations
52 * for all images. The image content is stored in the DB. The content is
53 * written out to a file at the ProducerImages level.
54 * Remember that Handlers for specific image types, Gif, Jpeg, etc..
56 * It implements the MirMedia interface.
58 * slowly starting to look better, a next step would be to have the
59 * representation stuff (WebdbImage) happen here.
62 * @see mir.media.MirMedia
64 * @version $Id: MediaHandlerImages.java,v 1.16 2003/01/25 17:50:35 idfx Exp $
68 public abstract class MediaHandlerImages implements MirMedia
70 static MirPropertiesConfiguration configuration;
71 static Logfile theLog;
72 static final String PNG = "PNG";
73 static final String JPEG = "JPEG";
77 configuration = MirPropertiesConfiguration.instance();
78 } catch (PropertiesConfigExc e) {
81 theLog = Logfile.getInstance(configuration.getString("Home")+"log/media.log");
84 abstract String getType();
86 public InputStream getMedia(Entity ent, Entity mediaTypeEnt)
87 throws MirMediaException
91 in = ((EntityImages)ent).getImage();
92 } catch ( StorageObjectFailure e) {
93 theLog.printDebugInfo("MediaHandlerImages.getImage: "+e.toString());
94 throw new MirMediaException(e.toString());
100 public void set(InputStream in, Entity ent, Entity mediaTypeEnt)
101 throws MirMediaException {
104 ((EntityImages)ent).setImage(in, getType());
106 catch ( StorageObjectFailure e) {
107 e.printStackTrace(System.out);
108 theLog.printError("MediaHandlerImages.set: "+e.getMessage());
109 throw new MirMediaException(e.getMessage());
113 public void produce(Entity ent, Entity mediaTypeEnt) throws MirMediaException
115 String date = ent.getValue("date");
116 String datePath = StringUtil.webdbDate2path(date);
117 String ext = "."+mediaTypeEnt.getValue("name");
118 String filepath = datePath+ent.getId()+ext;
119 String iconFilePath = configuration.getString("Producer.StorageRoot")
120 +getIconStoragePath() + filepath;
121 String productionFilePath = getStoragePath() + File.separator + filepath;
124 if (ent.getValue("icon_data")!= null &&
125 ent.getValue("image_data")!= null) {
128 InputStream in = ((EntityImages)ent).getIcon();
129 FileUtil.write(iconFilePath, in);
130 in = ((EntityImages)ent).getImage();
131 FileUtil.write(productionFilePath, in);
132 ent.setValueForProperty("icon_path",getIconStoragePath()+filepath);
133 ent.setValueForProperty("publish_path",filepath);
135 } catch ( Exception e) {
136 String msg = "MediaHandlerImages.produce - Error: " + e.toString();
137 theLog.printError(msg);
138 throw new MirMediaException(msg);
141 String msg="MediaHandlerImages.produce - missing image or icon OID for: "+
143 theLog.printError(msg);
144 throw new MirMediaException(msg);
149 public InputStream getIcon(Entity ent) throws MirMediaException
153 in = ((EntityImages)ent).getIcon();
154 } catch ( StorageObjectFailure e) {
155 theLog.printDebugInfo("MediaHandlerImages.getIcon: "+e.toString());
156 throw new MirMediaException(e.toString());
162 public SimpleList getURL(Entity ent, Entity mediaTypeEnt)
164 SimpleList theList = new SimpleList();
169 public String getStoragePath()
171 return configuration.getString("Producer.Image.Path");
174 public String getIconStoragePath()
176 return configuration.getString("Producer.Image.IconPath");
179 public String getPublishHost()
181 return StringUtil.removeSlash(configuration.getString("Producer.Image.Host"));
184 public String getTinyIconName()
186 return configuration.getString("Producer.Icon.TinyImage");
189 public String getBigIconName()
191 return configuration.getString("Producer.Icon.BigImage");
194 public String getIconAltName()
199 public boolean isVideo()
204 public boolean isAudio()
209 public boolean isImage ()
214 public String getDescr(Entity mediaType)