2 * Copyright (C) 2001, 2002 The Mir-coders group
\r
4 * This file is part of Mir.
\r
6 * Mir is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 2 of the License, or
\r
9 * (at your option) any later version.
\r
11 * Mir is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with Mir; if not, write to the Free Software
\r
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 * In addition, as a special exception, The Mir-coders gives permission to link
\r
21 * the code of this program with the com.oreilly.servlet library, any library
\r
22 * licensed under the Apache Software License, The Sun (tm) Java Advanced
\r
23 * Imaging library (JAI), The Sun JIMI library (or with modified versions of
\r
24 * the above that use the same license as the above), and distribute linked
\r
25 * combinations including the two. You must obey the GNU General Public
\r
26 * License in all respects for all of the code used other than the above
\r
27 * mentioned libraries. If you modify this file, you may extend this exception
\r
28 * to your version of the file, but you are not obligated to do so. If you do
\r
29 * not wish to do so, delete this exception statement from your version.
\r
32 package mircoders.media;
\r
38 import java.lang.reflect.*;
\r
40 import freemarker.template.SimpleList;
\r
44 import mir.entity.*;
\r
45 import mir.storage.*;
\r
47 import mircoders.entity.*;
\r
48 import mircoders.storage.*;
\r
52 * Image handler that stores images outside of the database. Will be replaced by the new
\r
53 * media handling system.
\r
58 public class MediaHandlerImagesExtern extends MediaHandlerGeneric
\r
60 public void produce(Entity anImageEntity, Entity mediaTypeEnt) throws MirMediaException
\r
63 String date = anImageEntity.getValue("date");
\r
64 String datePath = StringUtil.webdbDate2path(date);
\r
65 String ext = "." + mediaTypeEnt.getValue("name");
\r
66 String filePath = datePath + anImageEntity.getId() + ext;
\r
67 String iconFilePath = MirConfig.getProp("Producer.StorageRoot") + getIconStoragePath() + filePath;
\r
68 String imageFilePath = getStoragePath() + File.separator + filePath;
\r
70 File imageFile = new File(imageFilePath);
\r
71 File iconFile = new File(iconFilePath);
\r
73 if (!imageFile.exists()) {
\r
74 throw new MirMediaException("error in MediaHandlerImagesExtern.produce(): " + filePath + " does not exist!");
\r
77 ImageProcessor processor = new ImageProcessor(imageFile, "JPEG");
\r
79 processor.descaleImage(50, 0.8F);
\r
80 File dir = new File(iconFile.getParent());
\r
81 if (dir!=null && !dir.exists()){
\r
84 processor.writeScaledData(iconFile);
\r
86 anImageEntity.setValueForProperty("img_height", new Integer(processor.getHeight()).toString());
\r
87 anImageEntity.setValueForProperty("img_width", new Integer(processor.getWidth()).toString());
\r
89 anImageEntity.setValueForProperty("icon_height", new Integer(processor.getScaledHeight()).toString());
\r
90 anImageEntity.setValueForProperty("icon_width", new Integer(processor.getScaledWidth()).toString());
\r
92 anImageEntity.setValueForProperty("icon_path", getIconStoragePath()+filePath);
\r
93 anImageEntity.setValueForProperty("publish_path", filePath);
\r
95 anImageEntity.update();
\r
98 catch(Throwable t) {
\r
99 t.printStackTrace(System.out);
\r
100 throw new MirMediaException(t.getMessage());
\r
105 public InputStream getIcon(Entity anImageEntity) throws MirMediaException
\r
108 Entity mediaType = DatabaseUploadedMedia.getInstance().getMediaType(
\r
111 String date = anImageEntity.getValue("date");
\r
112 String datePath = StringUtil.webdbDate2path(date);
\r
113 String ext = "." + mediaType.getValue("name");
\r
114 String filePath = MirConfig.getProp("Producer.StorageRoot") +
\r
115 getIconStoragePath() + datePath + anImageEntity.getId() + ext;
\r
117 return new FileInputStream(new File(filePath));
\r
119 catch (Throwable t) {
\r
120 throw new MirMediaException(t.getMessage());
\r
124 public String getStoragePath()
\r
126 return MirConfig.getProp("Producer.Image.Path");
\r
129 public String getIconStoragePath()
\r
131 return MirConfig.getProp("Producer.Image.IconPath");
\r
134 public String getPublishHost()
\r
136 return StringUtil.removeSlash(MirConfig.getProp("Producer.Image.Host"));
\r
139 public String getTinyIconName()
\r
141 return MirConfig.getProp("Producer.Icon.TinyImage");
\r
144 public String getBigIconName()
\r
146 return MirConfig.getProp("Producer.Icon.BigImage");
\r
149 public String getIconAltName()
\r
154 public boolean isVideo()
\r
159 public boolean isAudio()
\r
164 public boolean isImage ()
\r
169 public String getDescr(Entity mediaType)
\r
171 return "image/jpeg";
\r