package mircoders.servlet;
import java.io.*;
+import java.lang.*;
import java.sql.*;
import java.util.*;
import java.net.*;
+import java.lang.reflect.*;
import javax.servlet.*;
import javax.servlet.http.*;
import mir.misc.*;
import mir.entity.*;
import mir.storage.*;
+import mir.media.*;
import mircoders.entity.*;
import mircoders.storage.*;
import mircoders.module.*;
+import mircoders.producer.*;
/*
* ServletModuleBilder -
try {
WebdbMultipartRequest mp = new WebdbMultipartRequest(req);
HashMap parameters = mp.getParameters();
+ String mediaId=null;
MpRequest mpReq = (MpRequest)mp.requestList.get(0);
byte[] imageData=mpReq.getMedia();
String fileName=mpReq.getFilename();
if (imageData!=null && fileName!=null) {
String fileType = "-1";
- if (contentType.equals("image/jpeg")) fileType="0";
- if (contentType.equals("image/gif")) fileType="1";
+
+ //the where clause to find the media_type entry
+ //from the content-type.
+ //we use the media type entry to lookup the
+ //media Handler/Storage classes
+ String wc = " mime_type='"+contentType+"'";
+
+ EntityList mediaTypesList = DatabaseMediaType.getInstance().selectByWhereClause(wc);
+ String mediaTypeId = null;
+ String mediaStorageName = null;
+ String mediaHandlerName = null;
+
+ //if we found an entry matching the
+ //content-type int the table.
+ if (mediaTypesList.size() > 0) {
+ //get the class names from the media_type table.
+ mediaTypeId = mediaTypesList.elementAt(0).getId();
+ mediaStorageName = mediaTypesList.elementAt(0).getValue("tablename");
+ mediaHandlerName = mediaTypesList.elementAt(0).getValue("classname");
+ parameters.put("to_media_type",mediaTypeId);
+
+ //load the classes via reflection
+ String MediaId;
+ try {
+ Class mediaStorageClass = Class.forName("mircoders.storage.Database"+mediaStorageName);
+ Method m = mediaStorageClass.getMethod("getInstance", null);
+ Database mediaStorage = (Database)m.invoke(null, null);
+ Entity mediaEnt = (Entity)mediaStorage.getEntityClass().newInstance();
+ mediaEnt.setStorage(mediaStorage);
+ mediaEnt.setValues(parameters);
+ mediaId = mediaEnt.insert();
+
+ Class mediaHandlerClass = Class.forName("mir.media.MediaHandler"+mediaHandlerName);
+ MirMedia mediaHandler = (MirMedia)mediaHandlerClass.newInstance();
+ //save and store the media data/metadata
+ mediaHandler.set(mpReq.getMedia(), mediaEnt,mediaTypesList.elementAt(0));
+
+ //were done with mpReq at this point, dereference it. as it contains
+ //mucho mem. -mh 01.10.2001
+ mpReq=null;
+
+ if(mediaId!=null){
+ new ProducerMedia().handle(null, null, false, false, mediaId);
+ }
+ } catch (Exception e) {
+ theLog.printError("setting uploaded_media failed: "+e.toString());
+ } //end try-catch
+
+
if (fileType != "-1")
entImage.setImage(imageData, fileType);
else
theLog.printError("Wrong file uploaded!");
}
_edit(id, req, res);
+ }
}
catch (IOException e) { throw new ServletModuleException("upload -- ioexception " + e.toString());}
catch (ModuleException e) { throw new ServletModuleException("upload -- moduleexception " + e.toString());}
+ catch (StorageObjectException e) { throw new ServletModuleException("StorageObjectException" + e.toString());}
}