support for wildcard like base content-type mappings in media_type table.
authormh <mh>
Tue, 26 Feb 2002 12:23:10 +0000 (12:23 +0000)
committermh <mh>
Tue, 26 Feb 2002 12:23:10 +0000 (12:23 +0000)
so things like image/* will work

source/mircoders/servlet/ServletModuleOpenIndy.java

index 66031a3..ba005bc 100755 (executable)
@@ -317,7 +317,11 @@ public class ServletModuleOpenIndy extends ServletModule
         //from the content-type.
         //we use the media type entry to lookup the
         //media Handler/Storage classes
-        String wc = " mime_type='"+contentType+"'";
+        //String wc = " mime_type = '"+contentType+"'";
+
+        // @todo this should probably be moved to DatabaseMediaType -mh
+        String[] cTypeSplit = StringUtil.split(contentType, "/");
+        String wc = " mime_type LIKE '"+cTypeSplit[0]+"%'";
 
         DatabaseMediaType mediaTypeStor = DatabaseMediaType.getInstance();
         EntityList mediaTypesList = mediaTypeStor.selectByWhereClause(wc);
@@ -329,16 +333,32 @@ public class ServletModuleOpenIndy extends ServletModule
         //if we found an entry matching the
         //content-type int the table.
         if (mediaTypesList.size() > 0) {
+          Entity mediaType = null;
+          
+          // find out if we an exact content-type match if so take it.
+          // otherwise just use the first one.
+          // @todo this should probably be moved to DatabaseMediaType -mh
+          for(int j=0;i<mediaTypesList.size();j++) {
+            if(contentType.equals(
+                            mediaTypesList.elementAt(j).getValue("mime_type")))
+              mediaType = mediaTypesList.elementAt(j);
+          }
+
+          if( mediaType == null )
+            mediaType = mediaTypesList.elementAt(0);
+                
           //get the class names from the media_type table.
-          mediaTypeId = mediaTypesList.elementAt(0).getId();
+          mediaTypeId = mediaType.getId();
           try {
             // ############### @todo: merge these and the getURL call into one
             // getURL helper call that just takes the Entity as a parameter
             // along with media_type
-            mediaHandler = MediaHelper.getHandler(mediaTypesList.elementAt(0));
-            mediaStorage = MediaHelper.getStorage(mediaTypesList.elementAt(0),
+            mediaHandler = MediaHelper.getHandler(mediaType);
+            mediaStorage = MediaHelper.getStorage(mediaType,
                                                 "mircoders.storage.Database");
           } catch (MirMediaException e) {
+            theLog.printError("getting media handler failed: "+e.toString());
+            contentModule.deleteById(cid);
             throw new ServletModuleException("getting media handler failed: "
                                             +e.toString());
           }
@@ -356,7 +376,7 @@ public class ServletModuleOpenIndy extends ServletModule
 
             //save and store the media data/metadata
             mediaHandler.set(mpReq.getMedia(), mediaEnt,
-                            mediaTypesList.elementAt(0));
+                            mediaType);
 
             //were done with mpReq at this point, dereference it.
             //as it contains mucho mem. -mh 01.10.2001