first cut of merge of STABLE-pre1_0 into HEAD. I won't even guarantee that it
[mir.git] / source / mircoders / servlet / ServletModuleImages.java
index e8702f5..89df034 100755 (executable)
@@ -49,7 +49,7 @@ public class ServletModuleImages extends mir.servlet.ServletModule
 
 
   private ServletModuleImages() {
-    theLog = Logfile.getInstance(this.getClass().getName());
+    theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("ServletModule.Bilder.Logfile"));
     templateListString = MirConfig.getProp("ServletModule.Bilder.ListTemplate");
     templateObjektString = MirConfig.getProp("ServletModule.Bilder.ObjektTemplate");
     templateConfirmString = MirConfig.getProp("ServletModule.Bilder.ConfirmTemplate");
@@ -90,19 +90,17 @@ public class ServletModuleImages extends mir.servlet.ServletModule
       EntityImages entImage = (EntityImages)mainModule.getById(id);
 
       if (imageData!=null && fileName!=null) {
-        String fileType = "-1";
-        
-       //the where clause to find the media_type entry
+           //the where clause to find the media_type entry
         //from the content-type.
-        //we use the media type entry to lookup the 
+        //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 mediaTypeId = null;
         String mediaStorageName = null;
         String mediaHandlerName = null;
+
         //if we found an entry matching the
         //content-type int the table.
         if (mediaTypesList.size() > 0) {
@@ -111,7 +109,7 @@ public class ServletModuleImages extends mir.servlet.ServletModule
           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 {
@@ -131,19 +129,16 @@ public class ServletModuleImages extends mir.servlet.ServletModule
                 //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());
+             } 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!");
+        entImage.setImage(imageData);
       }
       _edit(id, req, res);
       }
@@ -160,10 +155,10 @@ public class ServletModuleImages extends mir.servlet.ServletModule
     try {
       WebdbMultipartRequest mp = new WebdbMultipartRequest(req);
       HashMap parameters = mp.getParameters();
-      MpRequest mpReq = (MpRequest)mp.requestList.get(0);
-      byte[] imageData=mpReq.getMedia();
-      String fileName=mpReq.getFilename();
-      String contentType=mpReq.getContentType();
+      //MpRequest mpReq = (MpRequest)mp.requestList.get(0);
+      //byte[] imageData=mpReq.getMedia();
+      //String fileName=mpReq.getFilename();
+      //String contentType=mpReq.getContentType();
 
       EntityUsers   user = _getUser(req);
       parameters.put("to_publisher", user.getId());
@@ -172,17 +167,7 @@ public class ServletModuleImages extends mir.servlet.ServletModule
         parameters.put("is_published","0");
 
       String id = mainModule.set(parameters);
-      EntityImages entImage = (EntityImages)mainModule.getById(id);
-
-      if (imageData!=null && fileName!=null) {
-        String fileType = "-1";
-        if (contentType.equals("image/jpeg")) fileType="0";
-        if (contentType.equals("image/gif")) fileType="1";
-        if (fileType != "-1")
-          entImage.setImage(imageData, fileType);
-        else
-          theLog.printError("Wrong file uploaded!");
-      }
+      theLog.printError("Image ID"+id);
       _edit(id, req, res);
     }
     catch (IOException e) { throw new ServletModuleException("upload -- ioexception " + e.toString());}
@@ -366,18 +351,12 @@ public class ServletModuleImages extends mir.servlet.ServletModule
         String fileName=mpReq.getFilename();
         String contentType=mpReq.getContentType();
 
-        String fileType = "-1";
-        if (contentType.equals("image/jpeg")) fileType="0";
-        if (contentType.equals("image/gif")) fileType="1";
-        if (fileType != "-1") {
-          EntityImages entImage = (EntityImages)mainModule.getById(idParam);
-          entImage.setImage(imageData, fileType);
-        }
-        else
-          theLog.printError("Wrong file uploaded!");
+        EntityImages entImage = (EntityImages)mainModule.getById(idParam);
+        entImage.setImage(imageData);
       }
       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("upload -- storageobjectexception " + e.toString());}
     }
     else // keine id
       throw new ServletModuleException("Keine id angegeben");