* ) and just override the things that need to be specific. see MediaHandlerAudio
*
* @author <mh@nadir.org>, the Mir-coders group
- * @version $Id: MediaHandler.java,v 1.1.2.8 2005/12/24 11:43:36 zapata Exp $
+ * @version $Id: MediaHandler.java,v 1.1.2.9 2006/01/28 18:33:15 zapata Exp $
*/
public interface MediaHandler {
public void produce(Entity aMedia, Entity aMediaType ) throws MediaExc, MediaFailure;
/**
- * Get's the media data from database and returns it as an InputStream
- * Not very useful for most media types as they are stored in a file,
- * but very usefull for ones stored in the DB as it is necessary to get
- * it first before making a file out of it (in Producer*).
+ * Returns the associated media as an input stream
*/
public InputStream getMedia (Entity aMedia, Entity aMediaType) throws MediaExc, MediaFailure;
/**
- * Pretty much like get() above. But get's the specific Icon
- * representation. useful for media stored in the DB.
+ * Returns a thumbnail of the associated media as an input stream
*/
public InputStream getThumbnail(Entity aMedia) throws MediaExc, MediaFailure;
*/
package mir.media.image;
+import mir.config.MirPropertiesConfiguration;
import mir.log.LoggerWrapper;
import mir.media.MediaExc;
-import mir.media.MediaFailure;
-import mir.util.StreamCopier;
import mir.util.ShellRoutines;
-import mir.config.MirPropertiesConfiguration;
+import mir.util.StreamCopier;
-import java.io.*;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.util.StringTokenizer;
* Image processing by calling the ImageMagick command line progrmas
* "convert" and "identify". The main task of this class is to scale
* images. The path to ImageMagick commandline programs can be
- * specified in the coonfiguration file.
+ * specified in the configuration file.
*
* @author <grok@no-log.org>, the Mir-coders group
*/
private ImageFile sourceImage;
private ImageFile scaledImage;
- /**
- * ImageFile is a thin wrapper around a file that contains an
- * image. It uses ImageMagick to retreive information about the
- * image. It can also scale images using ImageMagick. Intended for
- * use in the ImageMagickImageProcessor class.
- */
- static class ImageFile {
- /**
- * path to the file represented by this class
- */
- File file;
- /**
- * whether the file must be deleted on cleanup
- */
- boolean fileIsTemp = false;
- /**
- * image information is stored here to avoid multiple costly calls to
- * "identify"
- */
- int width;
- int height;
- /**
- * Image type as returned by identify %m : "PNG", "GIF", ...
- */
- String type;
- /**
- * number of scenes in image >1 (typically animated gif)
- */
- boolean isAnimation;
-
- /**
- * Empty constructor automatically creates a temporary file
- * that will later hold an image
- */
- ImageFile() throws IOException {
- file = File.createTempFile("mirimage", "");
- fileIsTemp = true;
- }
-
- /**
- * if the file doesn't already have an image in it
- * we don't want to read its information
- */
- ImageFile(File file, boolean doReadInfo) throws IOException {
- this.file = file;
- if (doReadInfo) {
- readInfo();
- }
- }
-
- ImageFile(File file) throws IOException {
- this(file, true);
- }
-
- /**
- * delete temporary files
- */
- public void cleanup() {
- logger.debug("ImageFile.cleanup()");
- if (fileIsTemp) {
- logger.debug("deleting:" + file);
- file.delete();
- file = null;
- fileIsTemp = false;
- }
- }
-
- void debugOutput() {
- logger.debug(" filename:" + file +
- " Info:" +
- " width:" + width +
- " height:" + height +
- " type:" + type +
- " isAnimation:" + isAnimation);
- }
-
- private void checkFile() throws IOException {
- if (file == null || !file.exists()) {
- String message = "ImageFile.checkFile file \"" + file +
- "\" does not exist";
- logger.error(message);
- throw new IOException(message);
- }
- }
-
- /**
- * Uses the imagemagick "identify" command to retreive image information
- */
- public void readInfo() throws IOException {
- checkFile();
- String infoString = ShellRoutines.execIntoString
- (getImageMagickPath() +
- "identify " + "-format \"%w %h %m %n \" " +
- file.getAbsolutePath()); // extra space, for multiframe (animations)
- StringTokenizer st = new StringTokenizer(infoString);
- width = Integer.parseInt(st.nextToken());
- height = Integer.parseInt(st.nextToken());
- type = st.nextToken();
- isAnimation = Integer.parseInt(st.nextToken()) > 1;
- }
-
- public ImageFile scale(float aScalingFactor) throws IOException {
- logger.debug("ImageFile.scale");
- checkFile();
- ImageFile result = new ImageFile();
- String command = getImageMagickPath() + "convert " +
- file.getAbsolutePath() + " " +
- "-scale " +
- Float.toString(aScalingFactor * 100) + "% " +
- result.file.getAbsolutePath();
- logger.debug("ImageFile.scale:command:" + command);
- ShellRoutines.simpleExec(command);
- result.readInfo();
- return result;
- }
- }
-
public ImageMagickImageProcessor(InputStream inputImageStream)
throws IOException {
logger.debug("ImageMagickImageProcessor(stream)");
if (1 - scale > aMinDescale) {
scaleImage(scale);
+
+ return;
}
- } else {
- logger.debug("descaleImage: image size is ok, not scaling image");
- try {
- scaledImage = new ImageFile(sourceImage.file);
- }
- catch (IOException e) {
- throw new MediaExc(e.toString());
- }
}
+
+ // the image didn't need to be scaled: scaledImage = original image
+ try {
+ scaledImage = new ImageFile(sourceImage.file);
+ }
+ catch (IOException e) {
+ throw new MediaExc(e.toString());
+ }
+
}
/**
* Scales image by a factor using the convert ImageMagick command
*/
- public void scaleImage(float aScalingFactor)
- throws MediaExc {
+ public void scaleImage(float aScalingFactor) throws MediaExc {
logger.debug("scaleImage:" + aScalingFactor);
try {
// first cleanup previous temp scaledimage file if necesary
return scaledImage.height;
}
- public void writeScaledData(OutputStream aStream, String anImageType)
- throws MediaExc {
+ public void writeScaledData(OutputStream aStream, String anImageType) throws MediaExc, IOException {
// we can't asume that requested "anImageType" is the same as the
// scaled image type, so we have to convert
+ // if image is an animation and target type doesn't support
+ // animations, then just use first frame
+ String frame = "";
+ scaledImage.debugOutput();
+
+ if (scaledImage.isAnimation && !anImageType.equals("GIF")) {
+ frame = "[0]";
+ }
+ // ImageMagick "convert" into temp file
+ File temp = File.createTempFile("mirimage", "");
+ String command = getImageMagickPath() + "convert " +
+ scaledImage.file.getAbsolutePath() + frame + " " +
+ anImageType + ":" + temp.getAbsolutePath();
+ logger.debug("writeScaledData command:" + command);
+ ShellRoutines.simpleExec(command);
+ // copy temp file into stream
+ StreamCopier.copy(new FileInputStream(temp), aStream);
+ temp.delete();
+ }
+
+ public void writeScaledData(File aFile, String anImageType) throws MediaExc, IOException, FileNotFoundException {
+ OutputStream stream = new BufferedOutputStream(new FileOutputStream(aFile), 8192);
+
try {
- // if image is an animation and target type doesn't support
- // animations, then just use first frame
- String frame = "";
- scaledImage.debugOutput();
- if (scaledImage.isAnimation && !anImageType.equals("GIF")) {
- frame = "[0]";
- }
- // ImageMagick "convert" into temp file
- File temp = File.createTempFile("mirimage", "");
- String command = getImageMagickPath() + "convert " +
- scaledImage.file.getAbsolutePath() + frame + " " +
- anImageType + ":" + temp.getAbsolutePath();
- logger.debug("writeScaledData command:" + command);
- ShellRoutines.simpleExec(command);
- // copy temp file into stream
- StreamCopier.copy(new FileInputStream(temp), aStream);
- temp.delete();
+ writeScaledData(stream, anImageType);
}
- catch (Exception e) {
- throw new MediaExc(e.toString());
+ finally {
+ try {
+ stream.close();
+ }
+ catch (Throwable t) {
+ }
}
}
- public byte[] getScaledData(String anImageType) throws MediaExc {
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- writeScaledData(outputStream, anImageType);
- return outputStream.toByteArray();
- }
+ /**
+ * ImageFile is a thin wrapper around a file that contains an
+ * image. It uses ImageMagick to retreive information about the
+ * image. It can also scale images using ImageMagick. Intended for
+ * use in the ImageMagickImageProcessor class.
+ */
+ static class ImageFile {
+ /**
+ * path to the file represented by this class
+ */
+ File file;
+ /**
+ * whether the file must be deleted on cleanup
+ */
+ boolean fileIsTemp = false;
+ /**
+ * image information is stored here to avoid multiple costly calls to
+ * "identify"
+ */
+ int width;
+ int height;
+ /**
+ * Image type as returned by identify %m : "PNG", "GIF", ...
+ */
+ String type;
+ /**
+ * number of scenes in image >1 (typically animated gif)
+ */
+ boolean isAnimation;
- public void writeScaledData(File aFile, String anImageType) throws MediaExc {
- try {
- OutputStream stream = new BufferedOutputStream(new FileOutputStream(aFile), 8192);
+ /**
+ * Empty constructor automatically creates a temporary file
+ * that will later hold an image
+ */
+ ImageFile() throws IOException {
+ file = File.createTempFile("mirimage", "");
+ fileIsTemp = true;
+ }
- try {
- writeScaledData(stream, anImageType);
+ /**
+ * if the file doesn't already have an image in it
+ * we don't want to read its information
+ */
+ ImageFile(File file, boolean doReadInfo) throws IOException {
+ this.file = file;
+ if (doReadInfo) {
+ readInfo();
}
- finally {
- try {
- stream.close();
- }
- catch (Throwable t) {
- }
+ }
+
+ ImageFile(File file) throws IOException {
+ this(file, true);
+ }
+
+ /**
+ * delete temporary files
+ */
+ public void cleanup() {
+ logger.debug("ImageFile.cleanup()");
+ if (fileIsTemp) {
+ logger.debug("deleting:" + file);
+ file.delete();
+ file = null;
+ fileIsTemp = false;
+ }
+ }
+
+ void debugOutput() {
+ logger.debug(" filename:" + file +
+ " Info:" +
+ " width:" + width +
+ " height:" + height +
+ " type:" + type +
+ " isAnimation:" + isAnimation);
+ }
+
+ private void checkFile() throws IOException {
+ if (file == null || !file.exists()) {
+ String message = "ImageFile.checkFile file \"" + file +
+ "\" does not exist";
+ logger.error(message);
+ throw new IOException(message);
}
}
- catch (FileNotFoundException f) {
- throw new MediaFailure(f);
+
+ /**
+ * Uses the imagemagick "identify" command to retreive image information
+ */
+ public void readInfo() throws IOException {
+ checkFile();
+ String infoString = ShellRoutines.execIntoString
+ (getImageMagickPath() +
+ "identify " + "-format \"%w %h %m %n \" " +
+ file.getAbsolutePath()); // extra space, for multiframe (animations)
+ StringTokenizer st = new StringTokenizer(infoString);
+ width = Integer.parseInt(st.nextToken());
+ height = Integer.parseInt(st.nextToken());
+ type = st.nextToken();
+ isAnimation = Integer.parseInt(st.nextToken()) > 1;
+ }
+
+ public ImageFile scale(float aScalingFactor) throws IOException {
+ logger.debug("ImageFile.scale");
+
+ checkFile();
+ ImageFile result = new ImageFile();
+ String command = getImageMagickPath() + "convert " +
+ file.getAbsolutePath() + " " +
+ "-scale " +
+ Float.toString(aScalingFactor * 100) + "% " +
+ result.file.getAbsolutePath();
+ logger.debug("ImageFile.scale:command:" + command);
+ ShellRoutines.simpleExec(command);
+ result.readInfo();
+
+ return result;
}
}
}
import java.io.File;
import java.io.OutputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
public interface ImageProcessor {
- public void descaleImage(int aMaxSize) throws MediaExc;
+ void descaleImage(int aMaxSize) throws MediaExc;
- public void descaleImage(int aMaxSize, float aMinDescale) throws MediaExc;
+ void descaleImage(int aMaxSize, float aMinDescale) throws MediaExc;
- public void descaleImage(int aMaxSize, int aMinResize) throws MediaExc;
+ void descaleImage(int aMaxSize, int aMinResize) throws MediaExc;
- public void descaleImage(int aMaxSize, float aMinDescale, int aMinResize) throws MediaExc;
+ void descaleImage(int aMaxSize, float aMinDescale, int aMinResize) throws MediaExc;
/**
* Resizes an image to fit inside <code>aMaxWidth</code> and <code>aMaxHeight</code>, provided
* this requires at least <code>aMinResize</code> pixels will be removed from either the width or
* the height
*/
- public void descaleImage(int aMaxWidth, int aMaxHeight, float aMinDescale, int aMinResize) throws MediaExc;
+ void descaleImage(int aMaxWidth, int aMaxHeight, float aMinDescale, int aMinResize) throws MediaExc;
- public void scaleImage(float aScalingFactor) throws MediaExc;
+ void scaleImage(float aScalingFactor) throws MediaExc;
- public int getWidth();
- public int getHeight();
- public int getScaledWidth();
- public int getScaledHeight();
- public void writeScaledData(OutputStream aStream, String anImageType)
- throws MediaExc;
- public byte[] getScaledData(String anImageType) throws MediaExc;
- public void writeScaledData(File aFile, String anImageType) throws MediaExc;
+ int getWidth();
+ int getHeight();
+ int getScaledWidth();
+ int getScaledHeight();
+ void writeScaledData(OutputStream aStream, String anImageType) throws MediaExc, IOException;
+ void writeScaledData(File aFile, String anImageType) throws MediaExc, IOException, FileNotFoundException;
/**
* call this when you're over using this object (removes temp files)
*/
- public void cleanup();
+ void cleanup();
}
*/
package mir.producer.reader;
+import mir.producer.CompositeProducerNode;
+import mir.producer.ProducerFactory;
+import mir.producer.ProducerNode;
+import mir.producer.SimpleProducerVerb;
+import mir.util.ExceptionRoutines;
+import mir.util.xml.XMLParserEngine;
+import mir.util.xml.XMLParserExc;
+import mir.util.xml.XMLParserFailure;
+
import java.io.File;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
-import mir.producer.CompositeProducerNode;
-import mir.producer.ProducerFactory;
-import mir.producer.ProducerNode;
-import mir.producer.SimpleProducerVerb;
-import mir.util.ExceptionRoutines;
-import mir.util.xml.XMLParserEngine;
-import mir.util.xml.XMLParserExc;
-import mir.util.xml.XMLParserFailure;
-
public class ProducerConfigReader {
private ProducerNodeBuilderLibrary builderLibrary;
private ProducerNodeBuilderLibrary scriptedNodeBuilderLibrary;
/**
* Convenience validation method to test wether a field is numeric
-
- * @param aRequest
- * @param aFieldName
- * @param anErrorMessageResource
- * @param aValidationResults
- * @return
*/
-
- public static boolean testFieldIsNumeric(Request aRequest, String aFieldName, String anErrorMessageResource, List aValidationResults) {
+ public static boolean testFieldIsNumeric(Request aRequest, String aFieldName,
+ String anErrorMessageResource, List aValidationResults) {
Object value = aRequest.getParameter(aFieldName);
if (value!=null) {
try {
*/
package mir.util;
+import mir.log.LoggerWrapper;
+
import java.io.File;
import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.Reader;
/**
* Execute system commands. Warning: the current implementation is
* Executes a full command (including arguments) in a subshell.
* Standard input and output go to /dev/null
*/
- public static void simpleExec(String command)
- throws IOException {
+ public static void simpleExec(String command) throws IOException {
int exitStatus;
try {
// WARNING: unix specific
- exitStatus = Runtime.getRuntime().exec(new String[]{
- "/bin/sh", "-c",
- command + " " + ">/dev/null 2>/dev/null"
- }).waitFor();
+// exitStatus =
+ Process process = Runtime.getRuntime().exec(
+ new String[]{
+ "/bin/sh", "-c", command
+ });
+ Reader errorStreamReader = new InputStreamReader(process.getErrorStream());
+ ReaderLogger logger = new ReaderLogger(errorStreamReader, new LoggerWrapper("Utility"));
+ new Thread(logger).start();
+
+ Reader outputStreamReader = new InputStreamReader(process.getInputStream());
+ logger = new ReaderLogger(outputStreamReader, new LoggerWrapper("Utility"));
+ new Thread(logger).start();
+
+ exitStatus = process.waitFor();
}
catch (InterruptedException e) {
- throw new IOException(e.toString());
+ throw new IOException("Interrupted");
}
+
if (exitStatus != 0) {
throw new IOException("command exit satus:" + exitStatus);
}
}
+ private static class ReaderLogger implements Runnable {
+ private Reader reader;
+ private PrintWriter writer;
+
+ ReaderLogger(Reader aReader, LoggerWrapper aLogger) {
+ reader = aReader;
+ writer = aLogger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE);
+ }
+
+ public void run() {
+ try {
+ int size;
+ char[] buffer = new char[1024];
+ while ((size = reader.read(buffer)) >= 0) {
+ writer.write(buffer,0,size);
+ }
+ }
+ catch (IOException e) {
+ }
+ writer.close();
+ try {
+ reader.close();
+ }
+ catch (Exception e) {
+ }
+ }
+ }
+
}
package mircoders.entity;
-import mir.log.LoggerWrapper;
import mir.media.image.ImageMagickImageProcessor;
import mir.media.image.ImageProcessor;
+import mir.media.MediaExc;
import mir.storage.DatabaseFailure;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
+import java.io.IOException;
import java.sql.SQLException;
public class EntityImages extends EntityUploadedMedia
/**
* Processes and saves image data
*/
- public void setImage(InputStream anInputStream, String type) throws DatabaseFailure {
+ public void setImage(InputStream anInputStream, String type) throws IOException, MediaExc, SQLException {
if (anInputStream != null) {
- try {
ImageProcessor processor = new ImageMagickImageProcessor(anInputStream);
processor.descaleImage(maxImageSize, minDescaleRatio, minDescaleReduction);
setFieldValue("icon_width", Integer.toString(processor.getScaledWidth()));
processor.cleanup();
update();
- }
- catch (Exception e) {
- throw new DatabaseFailure(e);
- }
}
}
*/
package mircoders.localizer.basic;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
import mir.entity.Entity;
import mir.session.Request;
import mir.session.Response;
import mircoders.storage.DatabaseCommentToMedia;
import mircoders.storage.DatabaseContent;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
/**
* Session handler for comment postings
*
import mircoders.localizer.MirLocalizerExc;
import mircoders.localizer.MirLocalizerFailure;
import mircoders.media.MediaHelper;
+import mircoders.module.ModuleCommentStatus;
import mircoders.module.ModuleContent;
import mircoders.module.ModuleLanguage;
-import mircoders.module.ModuleCommentStatus;
import mircoders.storage.*;
import multex.Failure;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.awt.*;
public class MirBasicDataModelLocalizer implements MirDataModelLocalizer {
protected LoggerWrapper logger = new LoggerWrapper("Localizer.DataModel");
import mircoders.entity.EntityImages;
import java.io.*;
+import java.sql.SQLException;
/**
* This class handles saving, fetching creating representations
*
* @see mir.media.MediaHandler
* @author mh
- * @version $Id: MediaHandlerImages.java,v 1.23.2.9 2005/08/21 17:09:23 zapata Exp $
+ * @version $Id: MediaHandlerImages.java,v 1.23.2.10 2006/01/28 18:33:16 zapata Exp $
*/
try {
((EntityImages) ent).setImage(in, getType());
}
- catch (Throwable e) {
+ catch (IOException e) {
+ logger.error("MediaHandlerImages.store", e);
+
+ throw new MediaFailure("A problem has occurred processing the media file", e);
+ }
+ catch (SQLException e) {
logger.error("MediaHandlerImages.store", e);
throw new MediaFailure("A problem has occurred processing the media file", e);
package mircoders.media;
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-
import mir.entity.Entity;
import mir.log.LoggerWrapper;
import mir.media.MediaExc;
import mir.media.MediaFailure;
-import mir.media.image.ImageProcessor;
import mir.media.image.ImageMagickImageProcessor;
+import mir.media.image.ImageProcessor;
import mir.misc.StringUtil;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
/**
* Image handler that stores images outside of the database.
*
* @version 1.0
*/
-public class MediaHandlerImagesExtern extends MediaHandlerGeneric
-{
+public class MediaHandlerImagesExtern extends MediaHandlerGeneric {
private int maxIconSize;
private float minDescaleRatio;
private int minDescaleReduction;
minDescaleReduction = configuration.getInt("Producer.Image.MinDescaleReduction");
}
- public void produce(Entity anImageEntity, Entity mediaTypeEnt) throws MediaExc, MediaFailure {
- try {
+ public void produce(Entity anImageEntity, Entity aMediaTypeEntity) throws MediaExc, MediaFailure {
String date = anImageEntity.getFieldValue("date");
String datePath = StringUtil.webdbDate2path(date);
- String ext = "." + mediaTypeEnt.getFieldValue("name");
+ String ext = "." + aMediaTypeEntity.getFieldValue("name");
String fileBasePath = datePath + anImageEntity.getId();
String filePath = fileBasePath + ext;
String iconPath = getBaseIconStoragePath() + fileBasePath + ".jpg";
throw new MediaExc("error in MediaHandlerImagesExtern.execute(): " + filePath + " does not exist!");
}
else {
- ImageProcessor processor = new ImageMagickImageProcessor(imageFile);
+ ImageProcessor processor;
+ try {
+ processor = new ImageMagickImageProcessor(imageFile);
+ }
+ catch (IOException e) {
+ throw new MediaFailure(e);
+ }
processor.descaleImage(maxIconSize, minDescaleRatio, minDescaleReduction);
File dir = new File(iconFile.getParent());
- if (dir!=null && !dir.exists()){
- dir.mkdirs();
+ if (dir!=null && !dir.exists()){
+ dir.mkdirs();
+ }
+ try {
+ processor.writeScaledData(iconFile, "JPEG");
+ }
+ catch (IOException e) {
+ throw new MediaFailure(e);
}
- processor.writeScaledData(iconFile, "JPEG");
- anImageEntity.setFieldValue("img_height", new Integer(processor.getHeight()).toString());
- anImageEntity.setFieldValue("img_width", new Integer(processor.getWidth()).toString());
+ anImageEntity.setFieldValue("img_height",
+ Integer.toString(processor.getHeight()));
+ anImageEntity.setFieldValue("img_width",
+ Integer.toString(processor.getWidth()));
- anImageEntity.setFieldValue("icon_height", new Integer(processor.getScaledHeight()).toString());
- anImageEntity.setFieldValue("icon_width", new Integer(processor.getScaledWidth()).toString());
+ anImageEntity.setFieldValue("icon_height",
+ Integer.toString(processor.getScaledHeight()));
+ anImageEntity.setFieldValue("icon_width",
+ Integer.toString(processor.getScaledWidth()));
processor.cleanup();
anImageEntity.setFieldValue("icon_path", iconPath);
anImageEntity.setFieldValue("publish_path", filePath);
anImageEntity.update();
-
-
}
- }
- catch(Throwable t) {
- logger.error("MediaHandlerImagesExtern.execute: " + t.getMessage(), t);
- throw new MediaFailure(t.getMessage(), t);
- }
}
*/
package mircoders.media;
-import java.util.GregorianCalendar;
-import java.util.HashMap;
-import java.util.Map;
-
import mir.entity.Entity;
import mir.log.LoggerWrapper;
import mir.media.MediaFailure;
import mir.media.MediaHandler;
+import mir.media.MediaExc;
import mir.misc.StringUtil;
import mir.session.UploadedFile;
import mir.storage.Database;
+import mir.storage.DatabaseExc;
import mir.util.FileRoutines;
import mircoders.module.ModuleMediaType;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.Map;
+
public class MediaUploadProcessor {
private static LoggerWrapper logger = new LoggerWrapper("Media.UploadProcessor");
private static ModuleMediaType mediaTypeModule = new ModuleMediaType();
* Processes an uploaded media file.
* Will create the media entity and so on.
*/
- public static Entity processMediaUpload(UploadedFile aFile, Map aValues) throws UnsupportedMediaTypeExc, MediaFailure {
+ public static Entity processMediaUpload(UploadedFile aFile, Map aValues)
+ throws UnsupportedMediaTypeExc, MediaExc, DatabaseExc {
MediaHandler mediaHandler;
Entity mediaType = null;
Database mediaStorage;
values.put("to_media_type", mediaType.getId());
+ mediaEntity = mediaStorage.createNewEntity();
+ mediaEntity.setFieldValues(values);
+ mediaEntity.insert();
+ mediaHandler.store(aFile, mediaEntity, mediaType);
try {
- mediaEntity = mediaStorage.createNewEntity();
- mediaEntity.setFieldValues(values);
- mediaEntity.insert();
- mediaHandler.store(aFile, mediaEntity, mediaType);
}
catch (Throwable e) {
throw new MediaFailure(e);