/*
- * Copyright (C) 2001, 2002 The Mir-coders group
+ * Copyright (C) 2001, 2002 The Mir-coders group
*
* This file is part of Mir.
*
* 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 the com.oreilly.servlet library, 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.
+ * 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 mircoders.media;
+import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
-import mir.config.MirPropertiesConfiguration;
import mir.entity.Entity;
import mir.log.LoggerWrapper;
import mir.media.MediaExc;
import mir.media.MediaFailure;
+import mir.media.image.ImageProcessor;
+// FIXME: delete this when finished testing ImageMagickImageProcessor
+//import mir.media.image.JAIImageProcessor;
+import mir.media.image.ImageMagickImageProcessor;
import mir.misc.StringUtil;
-import mircoders.storage.DatabaseUploadedMedia;
/**
public class MediaHandlerImagesExtern extends MediaHandlerGeneric
{
+ private int maxIconSize;
+ private float minDescaleRatio;
+ private int minDescaleReduction;
+
public MediaHandlerImagesExtern() {
+
logger = new LoggerWrapper("Media.Images.Extern");
+
+ maxIconSize = configuration.getInt("Producer.Image.MaxIconSize");
+ minDescaleRatio = configuration.getFloat("Producer.Image.MinDescalePercentage")/100;
+ minDescaleReduction = configuration.getInt("Producer.Image.MinDescaleReduction");
}
public void produce(Entity anImageEntity, Entity mediaTypeEnt) throws MediaExc, MediaFailure {
try {
- String date = anImageEntity.getValue("date");
+ String date = anImageEntity.getFieldValue("date");
String datePath = StringUtil.webdbDate2path(date);
- String ext = "." + mediaTypeEnt.getValue("name");
- String filePath = datePath + anImageEntity.getId() + ext;
- String iconFilePath = MirPropertiesConfiguration.instance().getString("Producer.StorageRoot") + getIconStoragePath() + filePath;
+ String ext = "." + mediaTypeEnt.getFieldValue("name");
+ String fileBasePath = datePath + anImageEntity.getId();
+ String filePath = fileBasePath + ext;
+ String iconPath = getIconStoragePath() + fileBasePath + ".jpg";
+ String iconStoragePath = configuration.getString("Producer.StorageRoot") + iconPath;
String imageFilePath = getStoragePath() + File.separator + filePath;
- int maxIconSize = MirPropertiesConfiguration.instance().getInt("Producer.Image.MaxIconSize");
File imageFile = new File(imageFilePath);
- File iconFile = new File(iconFilePath);
+ File iconFile = new File(iconStoragePath);
if (!imageFile.exists()) {
throw new MediaExc("error in MediaHandlerImagesExtern.produce(): " + filePath + " does not exist!");
}
else {
- ImageProcessor processor = new ImageProcessor(imageFile, "JPEG");
+ // FIXME: delete this when finished testing ImageMagickImageProcessor
+ // ImageProcessor processor = new JAIImageProcessor(imageFile);
+ ImageProcessor processor = new ImageMagickImageProcessor(imageFile);
- processor.descaleImage(maxIconSize, 0.2F);
+ processor.descaleImage(maxIconSize, minDescaleRatio, minDescaleReduction);
File dir = new File(iconFile.getParent());
if (dir!=null && !dir.exists()){
dir.mkdirs();
}
- processor.writeScaledData(iconFile);
-
- logger.info(processor.getWidth()+"x"+processor.getHeight());
+ processor.writeScaledData(iconFile, "JPEG");
- anImageEntity.setValueForProperty("img_height", new Integer(processor.getHeight()).toString());
- anImageEntity.setValueForProperty("img_width", new Integer(processor.getWidth()).toString());
+ anImageEntity.setFieldValue("img_height", new Integer(processor.getHeight()).toString());
+ anImageEntity.setFieldValue("img_width", new Integer(processor.getWidth()).toString());
- anImageEntity.setValueForProperty("icon_height", new Integer(processor.getScaledHeight()).toString());
- anImageEntity.setValueForProperty("icon_width", new Integer(processor.getScaledWidth()).toString());
+ anImageEntity.setFieldValue("icon_height", new Integer(processor.getScaledHeight()).toString());
+ anImageEntity.setFieldValue("icon_width", new Integer(processor.getScaledWidth()).toString());
- anImageEntity.setValueForProperty("icon_path", getIconStoragePath()+filePath);
- anImageEntity.setValueForProperty("publish_path", filePath);
+ processor.cleanup();
+ anImageEntity.setFieldValue("icon_path", iconPath);
+ anImageEntity.setFieldValue("publish_path", filePath);
anImageEntity.update();
+
+
}
}
catch(Throwable t) {
- logger.error("MediaHandlerImagesExtern.produce: " + t.getMessage());
+ logger.error("MediaHandlerImagesExtern.produce: " + t.toString());
t.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE));
throw new MediaFailure(t.getMessage(), t);
}
}
- public InputStream getIcon(Entity anImageEntity) throws MediaExc, MediaFailure {
+ /** {@inheritDoc} */
+ public InputStream getThumbnail(Entity anImageEntity) throws MediaExc, MediaFailure {
try {
- Entity mediaType = DatabaseUploadedMedia.getInstance().getMediaType(
- anImageEntity);
+ File file = new File(configuration.getString("Producer.StorageRoot") + anImageEntity.getFieldValue("icon_path"));
- String date = anImageEntity.getValue("date");
- String datePath = StringUtil.webdbDate2path(date);
- String ext = "." + mediaType.getValue("name");
- String filePath = MirPropertiesConfiguration.instance().getString("Producer.StorageRoot") +
- getIconStoragePath() + datePath + anImageEntity.getId() + ext;
+ if (!file.exists()) {
+ // hackish
+ file = new File(configuration.getHome(), "../img/photo_big.gif");
+ }
- return new FileInputStream(new File(filePath));
+ return new BufferedInputStream(
+ new FileInputStream(file),8192);
}
catch (Throwable t) {
- throw new MediaFailure(t);
+ return null;
}
}
+ public String getIconMimeType(Entity anImageEntity, Entity aMediaType) {
+ return "image/jpeg";
+ }
+
public String getStoragePath()
{
return configuration.getString("Producer.Image.Path");
return "Image";
}
- public boolean isVideo()
- {
- return false;
- }
-
- public boolean isAudio()
- {
- return false;
- }
-
- public boolean isImage ()
- {
- return true;
- }
-
public String getDescr(Entity mediaType)
{
return "image/jpeg";