From: mh Date: Mon, 1 Apr 2002 03:57:52 +0000 (+0000) Subject: bug fix in content type finding logic. this really ought to go in another file X-Git-Tag: prexmlproducerconfig~171 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=118de8edd861cd55f4c4fa6685690c1de0ee7fef;p=mir.git bug fix in content type finding logic. this really ought to go in another file --- diff --git a/source/mircoders/servlet/ServletModuleOpenIndy.java b/source/mircoders/servlet/ServletModuleOpenIndy.java index 7c7219d1..01fe8043 100755 --- a/source/mircoders/servlet/ServletModuleOpenIndy.java +++ b/source/mircoders/servlet/ServletModuleOpenIndy.java @@ -298,7 +298,8 @@ public class ServletModuleOpenIndy extends ServletModule if (contentType.equals("text/plain") || contentType.equals("application/octet-stream")) { - throw new ServletModuleUserException("One or more files of unrecognized types"); + contentModule.deleteById(cid); + _throwBadContentType(fileName, contentType); } String mediaTitle=(String)withValues.get("media_title"+i); @@ -314,12 +315,6 @@ public class ServletModuleOpenIndy extends ServletModule mediaValues.put("is_produced", "0"); mediaValues.put("is_published","0"); - //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+"'"; - // @todo this should probably be moved to DatabaseMediaType -mh String[] cTypeSplit = StringUtil.split(contentType, "/"); String wc = " mime_type LIKE '"+cTypeSplit[0]+"%'"; @@ -332,79 +327,86 @@ public class ServletModuleOpenIndy extends ServletModule Database mediaStorage; ProducerMedia mediaProducer; - //if we found an entry matching the + //if we didn't find 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;j 0 + throw new ServletModuleException("getting media handler failed: " + +e.toString()); + } + + mediaValues.put("to_media_type",mediaTypeId); + + //load the classes via reflection + String MediaId; + Entity mediaEnt = null; + try { + mediaEnt = (Entity)mediaStorage.getEntityClass().newInstance(); + mediaEnt.setStorage(mediaStorage); + mediaEnt.setValues(mediaValues); + mediaId = mediaEnt.insert(); + + //save and store the media data/metadata + mediaHandler.set(mpReq.getMedia(), mediaEnt, + mediaType); + + //were done with mpReq at this point, dereference it. + //as it contains mucho mem. -mh 01.10.2001 + mpReq=null; + //we got this far, associate the media to the article + mediaEnt.setValueForProperty("is_published","1"); + mediaEnt.update(); + //produce it + mediaProducer.handle(null, null, false, false, mediaId); + DatabaseContentToMedia.getInstance().addMedia(cid,mediaId); + } catch (Exception e) { + theLog.printError("setting media failed: "+e.toString()); + contentModule.deleteById(cid); + throw new ServletModuleException("setting media failed: " + +e.toString()); + } + } //end for Iterator... //if we're here all is ok... @@ -440,6 +442,17 @@ public class ServletModuleOpenIndy extends ServletModule deliver(req, res, mergeData, postingFormDoneTemplate); } + private void _throwBadContentType (String fileName, String contentType) + throws ServletModuleUserException { + + theLog.printDebugInfo("Wrong file type uploaded!: " + fileName+" " + +contentType); + throw new ServletModuleUserException("The file you uploaded is of the " + +"following mime-type: "+contentType + +", we do not support this mime-type. " + +"Error One or more files of unrecognized type. Sorry"); + } + } diff --git a/source/mircoders/servlet/ServletModuleUploadedMedia.java b/source/mircoders/servlet/ServletModuleUploadedMedia.java index f9ebde38..c6d74f34 100755 --- a/source/mircoders/servlet/ServletModuleUploadedMedia.java +++ b/source/mircoders/servlet/ServletModuleUploadedMedia.java @@ -91,8 +91,7 @@ public abstract class ServletModuleUploadedMedia if (contentType.equals("text/plain") || contentType.equals("application/octet-stream")) { - throw new ServletModuleUserException( - "One or more files of unrecognized types"); + _throwBadContentType(fileName, contentType); } parameters.put("date", StringUtil.date2webdbDate(new GregorianCalendar())); @@ -110,24 +109,29 @@ public abstract class ServletModuleUploadedMedia // if we didn't find an entry matching the // content-type in the table. if (mediaTypesList.size() == 0) { - theLog.printDebugInfo("Wrong file type uploaded!: " + fileName); - throw new MirMediaUserException("One or more files of unrecognized type"); + _throwBadContentType(fileName, contentType); } Entity mediaType = null; + Entity mediaType2 = null; // find out if we an exact content-type match if so take it. - // otherwise just use the first one. + // otherwise try to match majortype/* // @todo this should probably be moved to DatabaseMediaType -mh - for (int j = 0; j < mediaTypesList.size(); j++) { - theLog.printDebugInfo("mediaTypesList: "+mediaTypesList.size()); - if (contentType.equals( - mediaTypesList.elementAt(j).getValue("mime_type"))) + for(int j=0;j