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;
public MediaHandlerImagesExtern() {
logger = new LoggerWrapper("Media.Images.Extern");
- try {
- MirPropertiesConfiguration configuration = MirPropertiesConfiguration.instance();
- }
- catch (Throwable t) {
- logger.fatal("MediaHandlerImagesExtern: can't get configuration");
-
- throw new RuntimeException(t.toString());
- }
maxIconSize = configuration.getInt("Producer.Image.MaxIconSize");
minDescaleRatio = configuration.getFloat("Producer.Image.MinDescalePercentage")/100;
throw new MediaExc("error in MediaHandlerImagesExtern.produce(): " + filePath + " does not exist!");
}
else {
- ImageProcessor processor = new ImageProcessor(imageFile);
+ // FIXME: delete this when finished testing ImageMagickImageProcessor
+ // ImageProcessor processor = new JAIImageProcessor(imageFile);
+ ImageProcessor processor = new ImageMagickImageProcessor(imageFile);
processor.descaleImage(maxIconSize, minDescaleRatio, minDescaleReduction);
File dir = new File(iconFile.getParent());
anImageEntity.setFieldValue("icon_height", new Integer(processor.getScaledHeight()).toString());
anImageEntity.setFieldValue("icon_width", new Integer(processor.getScaledWidth()).toString());
+ processor.cleanup();
anImageEntity.setFieldValue("icon_path", iconPath);
anImageEntity.setFieldValue("publish_path", filePath);
}
}
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 {
- String filePath =
- configuration.getString("Producer.StorageRoot") + anImageEntity.getFieldValue("icon_path");
+ File file = new File(configuration.getString("Producer.StorageRoot") + anImageEntity.getFieldValue("icon_path"));
- logger.info(filePath);
+ if (!file.exists()) {
+ // hackish
+ file = new File(configuration.getHome(), "../img/photo_big.gif");
+ }
return new BufferedInputStream(
- new FileInputStream(new File(filePath)),8192);
+ new FileInputStream(file),8192);
}
catch (Throwable t) {
return null;