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.misc.StringUtil;
-import mircoders.storage.DatabaseUploadedMedia;
-import mircoders.module.*;
/**
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;
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 ext = "." + mediaTypeEnt.getFieldValue("name");
String fileBasePath = datePath + anImageEntity.getId();
String filePath = fileBasePath + ext;
String iconPath = getIconStoragePath() + fileBasePath + ".jpg";
}
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", iconPath);
- anImageEntity.setValueForProperty("publish_path", filePath);
+ 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 {
- String filePath =
- configuration.getString("Producer.StorageRoot") + anImageEntity.getValue("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 FileInputStream(new File(filePath));
+ return new BufferedInputStream(
+ new FileInputStream(file),8192);
}
catch (Throwable t) {
return null;
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";